AI-native engineering · L1Reviewing code written by humans and AI

Reviewing code written by humans and AI

Review for correctness, design and shared understanding, and check harder when an AI wrote the code.

L1 Must-knowAI-native engineering20 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 21 Oct 2026 · How we check content
AI tools change fast: we review this lesson every quarter (next by 19 Jan 2027).
Senior at work · lesson 20 of 26
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

This story is made up, but each part of it has happened to real teams.

Ravi asked his coding agent to add signature checks to the payment webhook. Ten minutes later he had a 600-line pull request. The code looked clean. There were twelve new tests, and all of them passed.

His teammate Lina was busy. She skimmed the main file, saw green checks, and wrote "LGTM" ("looks good to me"). She did not open package.json. One new line there added a package called webhook-signature-verify.

The agent had invented that name. No such package existed when the model learned to code. But someone had since published a package with that exact name. It had an install script. When CI installed it, the script read the environment variables and sent the payment API key to a server outside the company.

The twelve tests did not catch it. Each one mocked the new package: it replaced the package with a fake version. So the real code never ran. One catch block also swallowed every error and returned true. So a webhook with a broken signature would have been accepted too.

The team rotated the key, removed the package and added a dependency check to CI. The code had passed review. The review had not really happened.

Section 2 of 8

The idea in simple words

Code review means someone other than the author reads the code before it is merged. Google's guide says it uses review "to maintain the quality of our code and products". 1

Review has three jobs:

  1. Correctness. Does the code do what it should? Does it break on edge cases, such as empty or very large inputs?
  2. Design. Does the change fit the system? Will the next person understand it? Google calls design the most important thing to cover. 3
  3. Shared understanding. After review, at least two people know how this code works. That helps the team on a bad night months later.

Review is not for spacing, import order or quote style. A linter and a formatter can check those every time, for free. (This is our advice. Google's guide also says reviewers should not block a change only because of their personal style. 3)

The goal is not perfect code. Google's main rule is to approve a change once it clearly improves the overall health of the code. Its guide says there is "no such thing as 'perfect' code—there is only better code". 2

The key idea. Review is where a team decides "we understand this, and we will own it". With AI, the code arrives faster, so that decision needs more care, not less.

Section 3 of 8

How it works

A good review has layers. Each one catches different problems. Step through them with Next and Back, or the ← and → keys.

Five layers of review, and what each one catches1 · Author self-reviewread the diff · run tests · write the whycatches: debug code, extra files 2 · Automated checksbuild · tests · linter · dependency scancatches: style, unknown packages 3 · Human review, risk firstdata · money · security · migrationscatches: wrong design, weak tests 4 · AI second passfresh context · comments onlycatches: missed edge cases ✓ 5 · A human approves and mergesthe decision stays with people SeniorPath
  1. The author reads their own diff first, as a reviewer would. They run the tests and write a description that says what changed and why. This removes the easy mistakes before anyone else spends time.
  2. Machines run the checks that have a clear pass or fail. They build the code, run the tests, run the linter and check every new package. Style arguments end here, so people do not spend review time on them.
  3. A person reads the risky parts first: data, money, security, concurrency and migrations. They read the tests and ask: would these fail if the code were wrong? This is where wrong designs and weak tests get caught.
  4. An AI reviewer reads the diff in a fresh context and leaves comments. It may find an edge case the person missed. It does not approve or block anything.
  5. A person who understands the change approves it and merges it. If something breaks later, a person owns the decision, not a tool.
Step 1 of 5

As the author

Your job is to make the review easy.

  • Keep it small. Small changes are reviewed faster and more carefully, and they cause fewer bugs. Google suggests about 100 lines is usually fine and 1,000 lines is usually too large. 4 A 200-line change in one file may be fine. Spread across 50 files, it is usually too large. 4
  • Write a clear description. The first line says what the change does, as a short order: "Delete the FizzBuzz RPC and replace it with the new system." The body says why, and what the known weak points are. 5 "Fix bug" is not a description. 5
  • Add tests in the same change. 4
  • Review it yourself first. Read your own diff before you ask anyone else. GitHub's docs say this catches mistakes early. 8 Tell the reviewer where to look first. 8

As the reviewer

Start with risk. Do not read files in alphabetical order. First find the parts where a mistake costs the most: data deletes and migrations, money, login and permissions, secrets, and code that runs in parallel. Concurrency bugs are hard to find by running the code, so you must reason about them while you read. 3 (The risk list is our advice.)

Read every line you are asked to review. Google's guide says you can sometimes skim generated code and data files. But do not skim a human-written function and assume it is fine. 3 If you cannot understand it, ask the author to make it clearer. 3

Read the tests. Ask one question: "Will the tests actually fail when the code is broken?" 3 Tests do not test themselves, so a person must check them. 3

Ask questions. "What happens if this list is empty?" works better than "This is wrong."

Write kind, specific comments. Comment on the code, not the person. Explain why. 6 Label each comment, so the author knows what is required:

  • Nit: small, fine to skip.
  • Optional: a good idea, but not required.
  • FYI: something for the future. 6

When you see good work, say so. 6

Be fast. Google says one business day is the maximum time to respond. 7 You can approve with comments when you trust the author to fix small points. 7

What changes when AI wrote the code

The rules above stay the same. What changes is the kind of mistake.

  • More code, faster. An agent can write 600 lines in minutes. Your reading speed did not change. Ask for smaller changes.
  • Plausible but wrong. The code has good names and comments, so it looks reviewed. Read it anyway. Google's "do not skim" rule names human-written code. 3 Our advice is to apply it to AI-written code too.
  • Invented APIs and packages. A study of 16 models and 576,000 code samples found that, on average, at least 5.2% of the packages that commercial models suggested were invented. For open-source models it was 21.7%. 9 An attacker can publish a real package under an invented name. The paper calls this a form of package confusion attack. 9 Many people now call it "slopsquatting", a name credited to Seth Larson of the Python Software Foundation. 14 The same invented names often come back: 43% of them appeared again in all 10 repeats of the same prompt. 9 So an attacker can predict them.
  • Missing edge cases. Empty lists, time zones, retries, a second request at the same moment.
  • Tests that test nothing. Tests that mock the code under test, or check only that "no error was thrown".
  • Over-broad changes. "While I was there, I also cleaned up..." Every extra file is extra risk.
  • Instructions hidden in the input. An agent may read a README, an issue or a web page with hidden instructions in it. This is indirect prompt injection. 10 It can steer the code the agent writes. So you are still responsible for reviewing everything the agent proposes. 13

A checklist for AI-written diffs

This list is our advice. Use it on top of a normal review.

  1. Does every new package exist, with the exact name, in the official registry? Is it the one you meant, and is it maintained?
  2. Does every API, method and config option exist in the version you use?
  3. Are there files in the diff that the task did not need?
  4. Does any catch or except hide an error, or return a default value?
  5. Would each test fail if the code were wrong? Is the code under test mocked?
  6. Are edge cases covered: empty input, nulls, limits, time zones, a repeat call?
  7. Are there secrets, tokens or personal data in the code, tests or logs?
  8. Can the author explain every line without asking the agent?

AI as a reviewer

AI review is a good second pass. Anthropic's Code Review service runs several agents over a pull request, checks their findings, and leaves comments on the exact lines. 11 It never approves or blocks a pull request, so the decision stays with your team. 11 Its docs also warn that a review with no findings does not mean the code is free of errors or secure. 11

You can also run /code-review before you open the pull request. It reviews the changes on your branch. By default it runs in a separate subagent with its own context. 12

Section 4 of 8

Trade-offs

Review styleCatches deep bugs?CostUse it when
Skim and "LGTM"No It approves what it never read.Almost none, until something breaks.Never for real code.
Full human review of every lineYes , if the change is small.Slow on big diffs. Reviewers get tired.Risky code: money, data, security.
Risk-first human review with automated checksYes Time goes where mistakes cost most.Needs good CI and a linter set up once.Most changes.
Add an AI second passYes , as an extra layer. Can be noisy or miss things.Tokens or a paid service, and more comments to read.Larger diffs, and all AI-written code.
AI review only, no humanNo Nobody owns the decision.Cheapest.Never as the final check.

Simple rule: the less you wrote yourself, the more carefully you read.

Section 5 of 8

At work: how a senior uses this

  • Before you ask for review, read your own diff on the review page, line by line, as if a stranger wrote it.
  • Put "How to review this" in the description: "Start with ledger.ts. The rest is renames."
  • Split agent output into small pull requests before anyone reviews it. A 1,500-line AI diff is a request to skim.
  • Ask: "What is the worst thing this change can do in production?" Review that part first.
  • For every new dependency, open its page in the registry yourself. Check the owner, age and downloads.
  • Search the diff for catch, except, TODO, mock and skip before you read the rest.
  • Mark every optional comment with Nit: and approve. Do not block a good change because of your personal taste. 2
Section 6 of 8

With AI

What to ask the agent

"Before I open a pull request, list every new dependency you added, with a link to its registry page. Flag any you are not sure exists."

"Review this diff as a strict senior reviewer. Focus on data loss, security and error handling. Ignore style. For each issue, give the line and a test that would show the bug."

"For each test you wrote, tell me what bug it would catch. If a test would still pass with the function body deleted, say so."

What to check yourself

  • Each new package exists, has the exact name you expect, and comes from the official registry. 9
  • Tests call the real code and would fail if it were wrong. 3
  • No error is swallowed and turned into a quiet success.
  • The diff touches only what the task needed.
  • No input the agent read (an issue, a README, a web page) could have carried hidden instructions. 10
  • You, not the AI reviewer, made the final decision, and you can explain every line. 11
Section 7 of 8

Check yourself

1. A pull request has a clear design and good tests. You would name one variable differently. What should you do?

Show answer

Approve, and leave a comment that starts with "Nit:". Google's guide says to approve once a change clearly improves code health. Mark small, optional points as "Nit:" so the author can choose.

2. An agent's diff imports a package you have never heard of. The tests pass. What do you check first?

Show answer

That the package really exists in the official registry, is the one you expect, and is maintained. Models invent package names, and attackers can publish real packages under those names. Passing tests may only mean the package was mocked.

3. Which of these tests is a warning sign in an AI-written diff?

Show answer

A test that mocks the function under test and then checks that the mock was called. A test that mocks the code it should test cannot fail when that code is broken. Ask "would this test fail if the code were wrong?"

4. Your team turns on an AI reviewer for every pull request. It finds no issues in a change. Is the change safe to merge?

Show answer

Not by itself. A review with no findings does not mean the code is correct or secure. A person still decides. Anthropic's own docs say an empty AI review does not mean the code is free of errors. Use AI as a second pass, not as the decider.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 14 sources and related lessons
  1. Google, “Google's Code Review Guidelines”, Google Engineering Practices (opens in a new tab)
    The start page of Google's public review guide, with one guide for reviewers and one for authors.
  2. Google, “The Standard of Code Review”, Google Engineering Practices (opens in a new tab)
    The main rule of review at Google. Approve when the change makes code health better, even if it is not perfect.
  3. Google, “What to look for in a code review”, Google Engineering Practices (opens in a new tab)
    Design, functionality, complexity, tests, naming and more. Also why you read every line.
  4. Google, “Small CLs”, Google Engineering Practices (opens in a new tab)
    Why small changes get faster and better reviews, and how to split a big one.
  5. Google, “Writing good CL descriptions”, Google Engineering Practices (opens in a new tab)
    How to write the first line and body of a change description, with bad examples.
  6. Google, “How to write code review comments”, Google Engineering Practices (opens in a new tab)
    Be kind, explain why, label each comment as Nit, Optional or FYI, and give praise.
  7. Google, “Speed of Code Reviews”, Google Engineering Practices (opens in a new tab)
    Answer within one business day, and when to approve with comments.
  8. GitHub Docs, “Helping others review your changes” (opens in a new tab)
    Short advice for authors. Small pull requests, clear descriptions and reviewing your own work first.
  9. Spracklen et al., “We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs”, USENIX Security 2025 (arXiv 2406.10279) (opens in a new tab)
    A study of 16 models and 576,000 code samples. How often models invent package names, and how attackers can use this.
  10. OWASP Gen AI Security Project, “LLM01:2025 Prompt Injection” (opens in a new tab)
    What prompt injection is, including indirect injection through files and web pages a model reads.
  11. Anthropic, “Code Review”, Claude Code documentation (opens in a new tab)
    A managed AI review service for GitHub pull requests. It comments but never approves or blocks.
  12. Anthropic, “Review locally with /code-review”, Claude Code documentation (opens in a new tab)
    How to run an AI review of your own branch in a separate subagent before you open a pull request.
  13. Anthropic, “Security”, Claude Code documentation (opens in a new tab)
    Prompt injection defences, and why you are responsible for reviewing what the agent proposes.
  14. Infosecurity Magazine, “AI Hallucinations Create ‘Slopsquatting’ Supply Chain Threat”, 14 April 2025 (opens in a new tab)
    News report on the Spracklen et al. study. It says Seth Larson of the Python Software Foundation coined the word "slopsquatting".

Related: Working with coding agents · Security risks in AI-written code (coming soon) · Testing strategy that scales

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper