← Blog

How to review AI-written code without reading every line twice

Ted ·

Short answer: review the plan before the code, run the tests yourself, then check the diff for the mistakes agents make most: changes outside the task, weakened or deleted tests, swallowed errors, new dependencies, and code that looks right but calls things that don't exist. Ask the agent to explain anything you don't follow, and use a second, fresh agent session as a first-pass reviewer, not as the final one.

A review funnel for agent-written code: check the plan, run the tests, scan the diff for the five common agent mistakes, then do a human read of what's left

Why AI code needs a different review

Human code fails in human ways: typos, forgotten edge cases, shortcuts under deadline. Agent code fails differently. It's usually tidy and confident, which makes the problems easy to miss. And there's more of it, because writing code is now cheap and reading it isn't.

1. Review the plan first

The cheapest review happens before any code exists. For anything bigger than a small fix, have the agent list the files it will change and what it will do in each. Thirty seconds of reading catches "it misunderstood the task", which is the most expensive mistake to find in a finished diff.

2. Run the tests yourself

Agents often say "all tests pass". Sometimes they ran a subset, sometimes the run they're remembering was before the last edit. Run the suite yourself, or have CI do it, before you read a line.

3. Check for the five common agent mistakes

Scan the diff for these specifically:

  1. Scope creep. Files changed that have nothing to do with the task. "While I was there I also refactored…" Ask for those to go in a separate PR.
  2. Tests bent to pass. An assertion loosened, a test marked skipped, a test deleted, or a mock that makes the test meaningless. This is the big one: check every change to a test file.
  3. Swallowed errors. A new try/catch that logs and continues, or a fallback value that hides a failure. Code that never crashes isn't the same as code that works.
  4. New dependencies. A package added for something the codebase already does. Check package.json, requirements.txt or whatever your project uses.
  5. Plausible inventions. A function, flag or API option that sounds right but doesn't exist in the version you use. Types and tests catch most of these; for the rest, look it up.

4. Make the agent explain itself

For anything you don't immediately understand, ask in the same session: "why did you change the retry logic in queue.ts?" The answer either clears it up or reveals the agent wasn't sure either. Both are useful. If the explanation is good, ask it to put a one-line comment in the code.

5. Use a second agent as the first reviewer

A fresh session that didn't write the code is a decent first-pass reviewer:

Review the diff on this branch against main. List bugs, tests that
were weakened, and anything outside the task. Don't fix anything.

It's good at catching the mechanical stuff so you can spend your attention on whether the change is right. It doesn't replace you: two agents can agree confidently on the same wrong idea.

6. Keep agent PRs small

All of this is easy on a 150-line diff and miserable on a 2,000-line one. One task per session, one session per PR. If an agent produced something huge, ask it to split the work into a stack of smaller PRs.

Reviewing as a team

On a team, the harder problem is that the reasoning behind a diff lives in a session on someone else's laptop. A reviewer sees what changed but not why.

Coagy (our product, so weigh accordingly) puts each teammate's sessions in a shared workspace: when the session's owner shares it, reviewers can see the conversation behind the diff, comment, and ask the session a question directly. Anything a teammate's message would make the agent edit or run still asks the owner first.

Quick answers

How do you review code written by AI?

Review the agent's plan first, run the tests yourself, then check the diff for changes outside the task, weakened or deleted tests, swallowed errors, new dependencies and calls to functions or options that don't exist. Ask the agent to explain anything unclear.

Can I use AI to review AI-generated code?

Yes, as a first pass. A fresh agent session that didn't write the code catches many mechanical problems. A person should still make the final call, because two agents can agree on the same wrong idea.

What mistakes do AI coding agents make most often?

Changing code outside the task, loosening or deleting tests so they pass, hiding errors behind try/catch or fallbacks, adding unnecessary dependencies, and using functions or options that don't exist.

How big should an AI-generated pull request be?

Small enough to review in one sitting, usually a few hundred lines at most. Give each agent session one task and open one pull request per task.

Try Coagy

Your team's Claude Code, Codex, Gemini CLI and Cursor sessions in one workspace. Free for up to 4 developers.

Start free