TL;DR
- Run the cheapest check first. That is how to review AI-generated code you cannot read in full: count what changed, break the tests on purpose, run one real path, search for five known mistakes, then bring a second reviewer. Each step hands you evidence instead of an impression.
- A green test run proves less than it looks. We ran a test that computes its expected value with the code it tests. It kept passing after we broke the discount rate. A test with a literal expected value failed at once.
- Don't ask the agent if it is sure. Ask for the commands it ran, the output, and what it did not run.
- Match depth to risk. Docs, copy and additive changes behind a flag can ride on automated checks. Money, auth, migrations and anything that deletes data get a full read from you.
How do you review AI-generated code when you can't read all of it?
Put your checks in order of what they cost, and make each one produce something you can look at: a count, a failing test, command output. Reading line by line comes last, and only for the parts that earn it. The five steps below need only git, a test runner and your own eyes, so they apply to any agent that hands you a diff.
This is a different job from reviewing a teammate. Sonar's 2026 survey of more than 1,100 developers found that 96% do not fully trust AI-generated code to be functionally correct, but only 48% say they always check it before committing. The Claude Code team at Anthropic swaps "did a human read it?" for a better question: what could go wrong with this change, and which check, automated or human, is the right one to catch it.

The five checks in order: count the change, break the tests, run one real path, hunt five mistakes, add a second reviewer. Each is cheaper than the one after it, and a failure at step 1 or 2 saves you the rest.
What goes wrong differently with AI-generated code?
Human mistakes leave signals: an odd name, a hedging comment, uneven style. Agent output has none of those whether or not it is right. As one review guide puts it, when the code is wrong, the polish hides it. Three findings explain why a skim is not enough:
- People trust it more than they should. In a Stanford user study, participants with an AI assistant wrote significantly less secure code than those without one, and were more likely to believe their code was secure. The study was first submitted in November 2022 and used OpenAI's codex-davinci-002, so read it as a warning about confidence, not a score for today's tools. Participants who trusted the AI less and engaged more with their prompts wrote code with fewer vulnerabilities.
- There is more to check. CodeRabbit analyzed 470 open-source pull requests and found that AI-authored changes produced 10.83 issues per PR, compared to 6.45 for human-only PRs, about 1.7 times as many. CodeRabbit sells an AI code review tool, and it labeled PRs as AI-authored by signals of co-authorship and assumed the rest were human, so take that figure as a direction.
- Some of it does not exist. A study of 16 code-generating models and 576,000 samples found that on average at least 5.2% of the packages suggested by commercial models, and 21.7% for open-source models, were hallucinated. That includes 205,474 unique invented names.
Step 1: How big is the change, and is it the one you asked for?
Before you open any code, write the request in one sentence: "add input validation to the signup form". Then look at the shape of the change, not its content.
git diff --stat
git diff --name-onlyWe built a scratch repository, asked for exactly that signup change, and edited the files the way an agent that wandered would. This is what the stat showed:
app/auth.py | 56 +++++++++++++++++++++++-----------------------------
app/mod2.py | 5 -----
app/signup.py | 1 +
package.json | 2 +-
tests/test_signup.py | 3 +++
5 files changed, 30 insertions(+), 37 deletions(-)Two of the five files belong to the signup change: the form and its test. Auth, an unrelated module and package.json changed too, and the change removed more lines than it added. You learned all of that without reading a line. Thoughtbot's advice for this moment: look for seemingly unrelated changes, because AI will often change other parts of the app to get something working, and those things may have been done that way for a reason.
Read the stat with four questions:
- Does the file list match the request? An extra file gets a "why?" or a revert into its own change.
- Were tests touched, and which way? More lines of test is normal. Fewer is a flag.
- Did a dependency file change? A new line in
package.jsonor a lockfile goes straight to step 4. - Is it small enough to review? SmartBear's study of a Cisco team found that developers should review no more than 200 to 400 lines of code at a time, and that beyond 400 the ability to find defects diminishes. Google's reviewer guide says 100 lines is usually reasonable and 1,000 lines is usually too large, and that a 200-line change that might be fine in one file is usually too large when it is spread across 50.
If the answer to the fourth question is no, send it back to be split. One guide's rule: if the diff is too large to review, the task was too large. Ask for it again in pieces.
Then decide how deep to read. Anthropic's Claude Code team routes by risk. Docs, copy, internal-only features and additive changes behind a flag need no human approval once automated review and security checks are green. Ordinary product changes need one person, and the highest-risk code needs two.
Its rule that suits any team: the change sets the tier, not the author. Tenki's guide agrees on the top end: billing, auth, permissions, migrations and anything that deletes data deserve a full review whoever wrote the code.

Yes to money, auth, permissions, migrations or deletes: read it in full. Over about 400 lines or off-request: send it back. Tests fail when broken and a real path ran: light review plus a second reviewer. Otherwise fix the tests first. It is our synthesis of the checks in this post, not a standard.
Step 2: Do the tests fail when the code is broken?
Read the tests before the code. They are the agent's own account of what the change should do, and they are the cheapest place to find out that nothing was proved. Google's reviewer guide asks the right question: will the tests actually fail when the code is broken? It adds that tests do not test themselves, so a human has to make sure they are valid.
Here is a small example we ran. We wrote it in a scratch repository, the way an agent might write a discount function and a test for it:
# pricing.py
RATES = {"SPRING": 0.15, "VIP": 0.30}
def get_discount_rate(code):
return RATES.get(code, 0.0)
def apply_discount(price, code):
return price - price * get_discount_rate(code)# test_pricing.py: the expected value is computed with the code under test
def test_spring_discount():
total = apply_discount(100, "SPRING")
assert total == 100 - 100 * get_discount_rate("SPRING")It passes. Now break the code on purpose, which takes one line:
sed -i 's/0.15/0.50/' pricing.pyWe then ran the test above and a second one that uses a literal from the spec, assert apply_discount(100, "SPRING") == 85. The first still passed. The second failed with assert 50.0 == 85.

The left test passes by construction after the SPRING rate went from 0.15 to 0.50: both sides of its comparison use the same broken rate. The right test fails because 85 came from the spec.
That is the whole check. Change a constant, flip a >= to >, return early, then run the tests. If nothing fails, the tests do not cover that line. Mutation testing tools automate this: Stryker inserts bugs into your code and runs your tests, and if the tests still pass, the mutant survived. You do not need the tool to learn what a surviving mutant tells you.
Three more things to look for in the test file:
- Expected values computed by the code. A literal from the spec, or a worked example, is independent. A formula copied from the implementation is not.
- Mocks that supply the answer. Thoughtbot warns that AI will do whatever it needs to do to get a test passing, including stubbing or mocking the implementation it's supposed to be testing.
- Tests that were deleted, skipped or edited. GitHub's guide says to watch for tests that are deleted or skipped, instead of fixed. METR, which runs frontier models on autonomous software-development tasks, reported in a 2025 post that recent frontier models attempted, often successfully, to get a higher score by modifying the tests or scoring code. It named o3 and saw similar behavior in Claude 3.7 Sonnet and o1. Anthropic reports that its Claude 4 models are 65% less likely than Sonnet 3.7 to use shortcuts or loopholes on agentic tasks that are particularly susceptible to them. That is an improvement, and still a reason to run
git diff --stat -- tests/every time.
Our own build skills ask for the same discipline. They require no production code without a failing test that was run and seen to fail for the expected reason. A commit that adds a test carries a Red: line quoting that failure, and the expected value comes from a literal, a worked example or the spec, never recomputed the way the code does.
Step 3: How do you run it and watch one real path?
"All tests pass" is a claim. Claude Code's best-practices page is blunt about it: ask for the command it ran and its output, or the screenshot, because "All tests pass" on its own tells you very little. For a session you did not watch, that output is the only evidence you have.
Then run something yourself. Pick the one path the change exists for and run it the way a user would, with an input from your request. Next, run one hostile input: empty, zero, missing or huge. Tenki's list of unhappy paths is a good prompt for your own: missing or zero values, empty results, timeouts, retries, partial failure and concurrent calls.
Running a path with a known answer catches bugs that read fine. Real Python shows a sliding-window average that runs, returns a list, and nothing complains, yet it skips the last window. The tell is that it returns two averages where three are expected, and checking the output length against what you expect is what catches it.
Two habits make this step faster:
- Check one claim from the agent's summary against the diff. One guide's advice is to verify one factual claim from the explanation, because a confident rationale is not evidence.
- Use the browser for web changes. If the change is something a user sees, watch it render. Our guide to letting Claude Code test your web app in a real browser covers four ways to set that up, and what our own seven runs showed. One of the browser-testing components in our Explore catalog is a skill called
webapp-testing, which tests local web apps with Playwright scripts, checks frontend behaviour, captures screenshots and reads browser logs.
Step 4: What are the five things AI code gets wrong most often?
You now know the change is scoped, the tests can fail and one path works. Spend the rest of your reading on five mistakes that review guides list again and again. Each has a check shorter than reading.
| Mistake | What it looks like | The check |
|---|---|---|
| Invented packages and methods | An import or call that fits the library's style but does not exist | Look up every new package and every unfamiliar method or option |
| Version drift | A removed or deprecated API, or an option your version ignores | Compare against the version in your lockfile, and read deprecation warnings |
| Silent error handling | A broad except or catch that returns an empty default | Search the added lines for except, catch and default returns |
| Secrets | A key in the source, a new config file, a token in a log line | Run a secret scanner, then read every new string constant |
| Deleted guards | A validation or permission check removed while "simplifying" | Read the removed lines before the added ones |
Invented packages. Check that a name resolves in the registry before you install it. npm view shows data about a package from the registry, and PyPI serves metadata for a project at /pypi/<project>/json. We ran both against names that do not exist:
$ npm view expresss-validate-pro version
npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/expresss-validate-pro - Not found
$ curl -s -o /dev/null -w "%{http_code}" https://pypi.org/pypi/skillmanifest-zz-nonexistent-pkg/json
404A 404 settles it. A 200 does not, because anyone can register a name. Security researcher Bar Lanyado watched models repeatedly suggest huggingface-cli and uploaded an empty package under that name. He reported that it received more than 15,000 authentic downloads in three months, and that by February Alibaba's GraphTranslator README pointed to it instead of the real Hugging Face CLI.
So a name that resolves still needs a look at who maintains it, when it was first published and where its repository is. GitHub's guide says the same: check that suggested dependencies exist and are actively maintained. If the agent installed a skill or plugin instead of a library, the checks differ. Our guide on whether Claude skills are safe covers what to read first.
Version drift. Models favor what was common in their training data. Tenki's examples: code written for node-fetch passes a timeout option, but native fetch ignores it, so the 5-second limit never applies, and React 19 removed ReactDOM.render, so code written for older React fails on a current one. Real Python suggests Ruff's UP and DTZ rules to flag dated patterns like datetime.utcnow() or typing.List that models regurgitate from their training data.
Silent error handling. This one is easy to find with a search. Real Python's example is a broad except that falls back to an empty dictionary and keeps going, so you never learn whether the file was missing or malformed. Tenki adds a one-character version: options.maxRetries || 3 turns a deliberate 0 into 3, because 0 is falsy.
Secrets. Run a scanner, but know its blind spot. Real Python notes that Ruff and Bandit flag hardcoded secrets by the variable's name, so a real key stored under an ordinary name can slip right past them. That is why you also read every new string constant. If a secret was ever committed, rotate it, because it can be accessed from your Git history.
Deleted guards. This is scope creep in its most expensive form, and a diff stat hides it. One review guide's rule: review deletions first, because they get the least attention and cause the most regressions. We simulated a change that "simplified" an API function and ran three searches:
$ git diff --stat
api.py | 11 +++++------
test_api.py | 3 +++
2 files changed, 8 insertions(+), 6 deletions(-)
$ git diff -U0 | grep "^-" | grep -v "^---"
- with open(path) as f:
- return parse(f.read())
- if amount <= 0:
- raise ValueError("amount must be positive")
- if not user.is_verified:
- raise PermissionError("user not verified")
$ git diff -U0 | grep -nE "^\+.*(except|catch|skip|xfail)"
11:+ except Exception:
25:+@pytest.mark.skip(reason="flaky")The stat looks harmless: two files, 14 changed lines. The second search shows two guards gone, an amount check and a verification check. (The first two removed lines were only re-indented into a try.) The third shows the swallowed error and a test skipped as "flaky". Three short searches put the problem on screen.
Step 5: Should you ask the agent to defend its work?
Yes, with a better question than "are you sure?" A study of self-correction found that LLMs struggle to self-correct their responses without external feedback, and at times their performance even degrades. So ask for artifacts you can check, not for confidence:
For this change, give me:
1. The request in one sentence, and each file you changed with the reason.
2. The exact commands you ran and the last lines of their output.
3. What you did not run or could not check.
4. Any test you changed, skipped or deleted, and why.
5. Any package or setting you added, and where you confirmed it exists.This follows Anthropic's advice to ask for evidence, and the report format our own build skills use: what is done, the evidence with command result lines, and a "Not verified" line. Those skills also say never to write "works perfectly" or "fully tested".
Then bring a second reviewer on purpose, and make it a different one.
Claude Code's best-practices page notes that /code-review reviews the diff in a fresh subagent that never saw your conversation and isn't swayed by the reasoning that produced the code. A fresh context helps. A different model also sidesteps a known bias: research on LLM evaluators found a self-preference bias, where an LLM scores its own outputs higher than others' while human annotators consider them of equal quality. One review guide adds that green tests written by the authoring model prove little. It recommends one independent oracle: a check the authoring model did not write, such as a contract diff, a pre-existing test, or a human-written case.
Two rules make the second reviewer useful:
- Tell it what to ignore. Anthropic's docs warn that a reviewer asked to find problems will always find something. Fix every finding and you end up with extra abstraction layers and tests for cases that cannot happen. Ask for correctness bugs, with a file and line for each, and skip style.
- Keep a person on the merge. On the Claude Code team, an agent's approval never counts as a person's.
For architectural changes, our build skills prefer a fresh-context reviewer agent. Ours has only Read, Grep, Glob and Bash tools and an instruction not to edit files, and it must return findings by severity, each with a file, a line, a concrete failure scenario and a fix. If you use Claude Code, our guide to setting up AI code review like a team would covers the /code-review command, a reviewer subagent and the GitHub Action.
A one-page checklist to copy
Paste this into your pull request template or your agent's instructions.
## Before reading
- [ ] The request, in one sentence: ...
- [ ] `git diff --stat`: do the files match the request? Under ~400 lines?
- [ ] Tests touched? `git diff --stat -- tests/` (deleted or skipped = flag)
- [ ] Dependency or lockfile changed? Look up each new package.
## Tests
- [ ] Read the tests first. Are expected values literals from the spec?
- [ ] Break one line on purpose. Did a test fail?
## Run
- [ ] The agent's commands and output are in the PR, not just "all tests pass".
- [ ] I ran one real path, then one hostile input (empty, zero, missing).
## Hunt
- [ ] Removed lines: any guard or check gone? (`git diff -U0 | grep "^-"`)
- [ ] New `except` or `catch` that returns a default?
- [ ] New string constants that look like keys; new config files?
- [ ] Deprecated or removed APIs; warnings in the test output?
## Decide
- [ ] Touches money, auth, permissions, migrations or deletes? Full read.
- [ ] A fresh reviewer (new session or another model) found nothing open.
- [ ] A person approves the merge.Try one step today. Take the last change an agent made for you, break one line it covers, and run its tests. If they stay green, you have found a test that proves nothing, and you know where your review should start.
FAQ
Can AI review its own code?
It can find real problems, but not reliably on its own. Research on self-correction found that models struggle to correct their responses without external feedback, and evaluator models favor their own outputs. Use a fresh session or a different model as one reviewer, and keep tests, a run and a person in the loop.
Do you have to read every line of AI-generated code?
No. Count the change, break the tests, run a real path and search for the five mistakes first. Read in full only what touches money, auth, permissions, migrations or deletes. Reviewers lose focus with volume: Real Python notes that most people start to lose focus after about four hundred lines of code or an hour of work.
How long should a review of AI-generated code take?
Pace matters more than a number of minutes. SmartBear's research found a significant drop in defect density at rates faster than 500 lines of code per hour, and advises stopping after about 60 minutes. If the diff is bigger than your hour allows, split it.
How do you spot a hallucinated package?
Look the name up before you install it, with npm view <name> or the PyPI JSON route. A 404 means it does not exist. If it resolves, check who maintains it, when it was first published and whether its repository matches what the agent claimed. A researcher reported that an empty package under an AI-suggested name collected more than 15,000 downloads in three months.
Which tests should you distrust most?
Tests whose expected value is computed by the code under test, tests that mock the thing they test, and tests that changed in the same diff as the code. The one-line check works on all three: break the code and see whether anything fails.
Lessons 1 to 3 of our field guide are free, no account: start lesson 1.
Sources
- www.sonarsource.com/company/press-releases/sonar-data-reveals-critical-verification-gap-in-ai-coding
- claude.dev/blog/solving-code-review-at-anthropic
- www.tenki.cloud/blog/reviewing-ai-generated-code-checklist
- arxiv.org/abs/2211.03622
- www.coderabbit.ai/blog/state-of-AI-vs-human-code-generation-report
- arxiv.org/abs/2406.10279
- thoughtbot.com/blog/how-to-review-ai-generated-prs
- smartbear.com/learn/code-review/best-practices-for-peer-code-review
- google.github.io/eng-practices/review/developer/small-cls.html
- realpython.com/review-ai-generated-code
- google.github.io/eng-practices/review/reviewer/looking-for.html
- stryker-mutator.io/docs
- docs.github.com/en/copilot/tutorials/review-ai-generated-code
- metr.org/blog/2025-06-05-recent-reward-hacking
- www.anthropic.com/news/claude-4
- code.claude.com/docs/en/best-practices
- continuumcode.ai/guides/reviewing-ai-generated-code
- docs.npmjs.com/cli/v10/commands/npm-view
- docs.pypi.org/api/json
- www.theregister.com/2024/03/28/ai_bots_hallucinate_software_packages
- arxiv.org/abs/2310.01798
- arxiv.org/abs/2404.13076
- dev.to/alisa_hester_1/how-to-review-ai-generated-code-without-rubber-stamping-it-4a8c
- skillmanifest.co



