Opinion
Reviewing AI-written code: what to look for
The ways agent-written diffs fail, a practical review checklist, and how to set up the work so review stays manageable.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Coding agents now produce a large share of the diffs many developers review. The code usually compiles, is neatly formatted and comes with a confident summary. That polish is exactly why it needs a different kind of attention. A human’s messy pull request shows you where they struggled. An agent’s tidy one does not.
The short answer to how to review AI-generated code: check that the diff is the change you asked for and the smallest reasonable one, prove each new test fails without the fix, run the code yourself instead of trusting the agent’s report, then look at error paths, fit with the codebase and anything security-relevant.
This article is about reviewing code an agent wrote, whether you prompted it yourself or a teammate did. Most of it also applies to using an AI reviewer, which we come to at the end.
How agent-written code goes wrong
From our own use and from what teams report, the failures cluster in a few places.
It solves a slightly different problem. The agent misread the task, or filled a gap in the specification with a reasonable guess. The code is correct for the problem it solved.
It changes more than it should. A request to fix one function arrives with a refactor of its neighbours, renamed variables and a new helper. Each change looks harmless; together they make the diff hard to review and risky to merge.
Tests that test nothing. Generated tests often assert that a function returns what it returns, mock the very thing under test, or check only that no exception was thrown. They pass, coverage goes up, and they would not catch a regression.
Plausible APIs that do not exist, or not in your version. Less common with current models and with agents that can run the code, but still seen with less popular libraries and recent breaking changes.
Error handling that hides problems. Broad try/except or catch blocks that log and continue, default values that paper over missing data, retries without limits.
Duplicated logic. The agent did not find the existing utility and wrote a new one. Now there are two ways to format a date.
Security details. String-built SQL, unescaped output, secrets in logs, permissive CORS, a dependency added for one function. Agents follow patterns in your codebase, including its bad ones.
Confident summaries. “All tests pass” and “no breaking changes” are claims. They are often true, and need checking because they are sometimes not.
A review checklist
Use this in roughly this order. The early questions are cheap and catch the expensive problems.
- Is this the change I asked for? Read the task, then the summary, then skim the file list. Unexpected files are the first thing to question.
- Is it the smallest reasonable change? If not, ask the agent to split it or revert the unrelated parts before you review further.
- Do the tests prove the behaviour? For each new test, ask whether it would fail if the fix were reverted. Try it for at least one: revert the source change, run the test, see it fail.
- Did I run it? Run the tests and the feature yourself. Do not rely on the agent’s report of its own run.
- What happens on bad input? Empty values, very large values, concurrent calls, the network failing. Look at what the error paths actually do.
- Does it fit the codebase? Existing helpers, naming, layering rules, the patterns your
AGENTS.mddescribes. - Anything security-relevant? Input handling, auth checks, queries, file paths, new dependencies, logging of sensitive data.
- Would I be happy to maintain this? If the code is clever, ask for it to be simpler.
Set up the work so review stays possible
The best review technique is a smaller diff. Most problems with reviewing agent code are really problems with how the task was scoped.
- Plan first. Ask for a plan, review it, then let the agent implement. Catching a wrong approach in a ten-line plan is far cheaper than in a 600-line diff.
- One change per task. Fix the bug in one task; do the refactor in another.
- State what not to touch. “Do not change the public API” or “only edit files under
src/billing”. - Define done as a check. “Done when
npm test billingpasses and the new test fails on the old code.” - Keep instruction files current. An
AGENTS.mdthat names your helpers and conventions prevents a lot of duplicated logic.
Using an AI reviewer
AI review tools and agent review commands (Claude Code’s /review, Codex’s /review and dedicated tools like CodeRabbit) are useful as a first pass. They are good at spotting inconsistencies, missing error handling, likely bugs in unfamiliar code and things that contradict the stated intent. They are tireless on large diffs.
They also produce noise: style comments you did not ask for, findings that are technically true and practically irrelevant, and occasionally confident wrong claims. Two practices help:
- Give the reviewer your checklist. A review prompt or skill that lists what matters in your codebase produces more relevant findings than a generic “review this”.
- Treat findings as questions, not verdicts. The human reviewer still decides, and still owns what gets merged.
Reviewing agent code with another agent can catch real issues. It does not replace a person who understands why the change is being made.
A note on responsibility
Whoever merges the code owns it. “The agent wrote it” is not a reason to review less; if anything, the speed at which agents produce plausible code is a reason to keep review deliberate. Teams that do well with coding agents tend to be strict about small diffs and real tests, and relaxed about who or what typed the code.
For a hands-on version of this, see the code review with Claude Code workflow, and the code-review skill in our directory.
Next steps
- Focus on the security questions with security review a pull request.
- Understand where unreviewed generation breaks down in What is vibe coding, and when it bites.
- Limit what an agent can break before review with permissions and sandboxing for coding agents.
- Choose the agent that suits your review style in Claude Code vs Codex vs Cursor.
- Build the wider habits with the AI-assisted software engineering learning path.
Covers
Related
- Code review with Claude Code on every pull request
Write your checklist once, dry-run it locally, then review every pull request in GitHub Actions and post the findings.
- Your first session with Claude Code
Install it, run it in a real repository, approve its first changes, commit a reviewed edit and learn the commands you will use daily.
- What is vibe coding, and when it bites
Vibe coding means building software by prompting an AI and accepting its code without reading it. Where that works, where it fails, and a test before you try.
- Code review (Sentry)
Sentry's pull-request review checklist: correctness, design, test coverage and long-term impact, with Python, TypeScript and security patterns to flag.
- Run coding agents headless in CI
Run claude -p and codex exec in GitHub Actions with pinned versions, narrow permissions, scoped secrets and separate jobs for writing back to the pull request.