Anthropic's Six-Layer Review Pipeline: How Claude Code Reviews AI-Generated Code at Scale
Original author: Addy Osmani (Anthropic team) (English original: https://claude.dev/blog/solving-code-review-at-anthropic/), Chinese translation and engineering concept supplements by 欧呦 (Oil 欧呦).
We've mentioned before that roughly 90% of Claude Code's code is written by Claude. So at that scale, how do we do code review? Who actually reads the code anymore? What happens if something goes wrong?
This article explains the code review process of our Claude Code team and how we improved it. Between June and September, the number of PRs (pull requests) merged into the Claude Code repository more than doubled, while the share of PRs that had to be reverted dropped by more than 40%.
We didn't stop doing code review. Instead, we automated the vast majority of the code-reading work and tuned the process around saving human effort and time. At the same time, we invested heavily in making it faster and easier to roll back mistakes.
Rethinking the Goal of Code Review
Once agents write code, the volume of changes rises sharply. In our monorepo, the number of merged changes per day jumped from roughly 2,500 in May of this year to over 30,000 in September.
Although Claude Code is not in that monorepo, it faces similar pressure. At this pace, relying on humans to line-by-line review code becomes increasingly difficult, and eventually impossible.
Code review has two purposes:
- Find and fix bugs before they go live
- Build shared team understanding of the codebase
This article focuses on the first goal, and touches on the second at the end.
We argue that "has anyone read this code?" is a poorly calibrated measure. The real question is: "What could go wrong with this change? Which check — automated or human — is best suited to catch it?"
This question also changes the timing of code review. Traditionally, code review is a post-hoc check: code is written, a PR is opened, then you wait for another person to look at it. We've folded code review into the workflow, more like a spell-check that runs continuously as you write.
Before any human gets involved, the majority of changes have already been reviewed and fixed by Claude at least once. This way, we catch most routine bugs, leaving human attention for higher-level concerns.
Human Time and Attention
We want to reserve human time and attention for the things only humans can handle, while ensuring enough automation covers the rest. Even at our current pace, there's still plenty of work requiring humans, and the team hits genuinely new challenges almost every day.
For that reason, accounting for human time cannot be one-sided: we have to count not just time spent reviewing code, but also time spent firefighting and fixing bugs if bad code slips through. If we only reduce the former without controlling the latter, we haven't actually saved human time.
So our goal is: across Claude Code's various repositories (including the CLI, desktop and web apps, and mobile apps), the vast majority of PRs should merge with at most one human intervention (that human may be the author themselves), without pushing up the revert or failure rate.
We track human effort via these metrics: median (and P95) number of human approvals per PR, number of human comments, and how long PRs wait for human attention. Meanwhile, we treat revert rate and failure rate as guardrail metrics: if those rise, we haven't reduced human time — we've just shifted the time cost elsewhere.
Oil's perspective supplement: P95 percentile and Guardrail Metrics
- Median vs. P95 percentile: If you line up 100 PRs by wait time from shortest to longest, the 50th one is the "median," representing typical cases. The 95th one is the "P95 percentile," which specifically captures those "hardest-to-chew, stuck-longest" extreme slow cases, preventing a pretty average from hiding high-risk code stuck in the process.
- Guardrail metric: Like crash barriers on a highway. You want to make review faster (primary goal), but if you blindly approve everything to go faster, online errors and rollbacks shoot up immediately — setting revert rate as a guardrail means: no matter how you speed up, the bottom line is you must never hit the "higher online failure rate" barrier.
What Happens to a Code Change?
A typical code change, whether from an engineer's laptop or a Claude session in Slack, goes through multiple layers of review.
The diagram above shows the full journey of a typical Claude Code change from the author's local environment to production. Most of this flow is automated, with human attention concentrating on high-risk parts.
We have six layers of checks, plus a rollback mechanism to handle anything that slips through.
Each layer catches some bugs and misses others. Very few bugs penetrate all layers; even if one does, we have a rollback mechanism as a backstop.
1. Verification before Opening the PR
Most of our review work happens before the PR is even created. We have Claude run executable validations, such as running tests, executing builds, or comparing UI screenshots against design specs. We don't just take its word that "the task is done" — we ask it to show the results. Then, a subagent with a fresh context reviews the diff. Both of these strategies are in our best practices guide.
Before opening a PR, many of us also run a few internal Skills: debugging issues, slimming down the diff, end-to-end validation, and checking UI changes against design specs.
As Boris Cherny, creator of Claude Code, put it, giving Claude a verification process is probably the most critical factor for higher-quality output. He estimates that a verification process can improve Claude's output quality two to three times.
Verification processes vary a lot between domains: sometimes it's just running a bash command, sometimes it's a test suite, sometimes it's testing the app in a browser or mobile simulator.
Oil's perspective supplement: Why use a "fresh-context subagent" to review code?
If you ask the same AI session that just wrote the code to "check your own work," it tends to assume the logic is fine based on its earlier reasoning. Spinning up a separate subagent that has no conversation history and looks only at the final diff avoids being led by the earlier context, and can surface hidden problems (for practical guidance, see "How to use subagents well").
If the automated review tool keeps flagging the same class of issue, we fix it at the source — for example, by modifying the relevant Skill, adding a lint rule, or updating one of these documentation files:
CLAUDE.md— A project instruction file that provides Claude with context (tech stack, coding standards, goals, and non-goals). Claude Code loads this file into every review, so for large codebases we keep it short and reference other docs from it. The review tool flags cases where code violates the file's rules, or where a change makes the file's content outdated.REVIEW.md— A file code owners use to tell the review tool "what matters most in the modules I own." We also separately verify that the review tool actually follows these guidelines. A goodREVIEW.mdis usually concise and focuses on:- Defining what counts as a "project-level error" (e.g., docs must not lie; configs must not be misrouted)
- Limiting nitpicking
- Defining paths to ignore
- Requiring specific file names and line numbers instead of guessing
- Requiring a top-level summary that includes the number of issues, or explicitly states "no issues"
2. AI Review on Every PR
Every PR gets a Claude review before it goes to human review.
It analyzes the diff against the full codebase and the PR author's stated intent, checking:
- The change actually solves the stated problem
- The change fits into the larger system architecture
- The change doesn't break other parts of the codebase
When reviewing a bug fix, the bot also attempts to identify the root cause.
Our public product Code Review for Claude Code is now available to all Team and Enterprise customers. There's also a lightweight local version — /code-review.
Since releasing the research preview, the share of internal PRs receiving substantive review comments has risen from 16% to 54%. For large PRs over 1,000 lines, Code Review catches issues in the vast majority of cases; for most small PRs, it returns a clean pass. Admins can configure Quick, Standard, or Deep modes for a repository. Deep mode is useful when a missed bug costs more than the time spent on code review.
Before issues go to human review, they are cross-checked by multiple other agents:
- Multiple agents run in parallel to hunt bugs
- An independent voting mechanism judges whether an issue is real or a false positive; only issues reaching enough votes are confirmed
- Comments about code style, diagnostic messages, or cleanup are filtered out (we ran A/B tests on our own PRs before rolling out these filters)
The surviving issues appear as inline comments, sorted by severity and labelled as:
- Important
- Nit
- Pre-existing — so we don't unfairly blame an author for a bug not introduced by their PR
All flagged issues must be addressed — either fixed or dismissed with a reason by resolving the thread. Often, agents fix issues overnight, so when the author returns, the PR has already passed a fresh review round.
3. Blocking Security Review
We also run automated security review. As long as unresolved threads exist (from either code review or security review), the PR cannot merge. The author can fix the issue or dismiss the thread with a short reason (that's also how we handle false positives).
If a later commit resolves the issue, the corresponding review item auto-closes. You can replicate this setup with the open-source security review GitHub Action or the /security-review command. See the guide on automated security review in Claude Code for configuration.
4. Blocking Automated Checks
Standard checks include lint, type checking, tests on all platforms, and builds. A typical CLI PR may run dozens of checks before any human sees it. The PR template includes questions about "how to test this change" and "how to revert." Claude can help fill these, but the author is responsible for reviewing the content.
5. Risk-Based Human Approval
Some changes are riskier than others (e.g., fixing docs vs. modifying the auto-updater), so they require different levels of review.
Risk level is determined by the change itself, not by who the author is. A classifier judges risk based on the change, and another classifier determines whether a specific change needs extra human approval even if its risk tier doesn't require it. Some paths always need extra approval, including code marked sensitive by owners, and all CI workflow files.
Only authors on the repository's trusted list enjoy relaxed approval requirements; these are typically team members who own the repo. Everyone else needs a second person to approve. Agent approvals don't count and cannot substitute for human approval. Automated review can pass low-risk changes, but it can't replace humans where human judgment is required.
The change's author is responsible for it, so if a PR was written by an agent, the person operating that agent is always counted as one of the required reviewers. A PR approval is valid only for the current commit. If a new commit that can't be trusted directly gets pushed (e.g., an agent pushes new code, or someone manually resolves a merge conflict), the PR must be approved again.
6. Merge Queue, Feature Flags, and Progressive Rollout
The merge queue ensures all checks run against the main branch with the change applied, preventing two PRs that each pass on their own from breaking main when combined. New features typically ship behind feature flags and roll out first to Anthropic employees. Because we use the product heavily ourselves, we often catch regressions before external users do.
When we release publicly, changes first go to the latest channel, with stable lagging behind.
Oil's perspective supplement: Merge Queue, Feature Flag, and Regression
These are three protection mechanisms before a big engineering team's release:
- Merge queue: Imagine two engineers each change code and tests pass on their own branches. But if merged at the same time, the two changes together might conflict and break the main branch. A merge queue requires PRs to line up in order, and each PR must re-run tests against the latest main branch combined with the preceding merge, and only pass if all tests pass.
- Feature flag: Code is already merged and live, but wrapped behind a config toggle. You can enable it for internal employees first. If an anomaly appears after launch, you don't need to rebuild or deploy; just turn off the toggle in the backend so external users are unaffected.
- Regression: An old, previously working feature that breaks because you changed something else — that's a regression.
7. Fast Feedback and Rollback
Some problematic merges will inevitably slip through. This is our last line of defense, and the key is identifying them as fast as possible. Changes behind feature flags can be turned off without redeploying.
Claude Code runs a weekly on-call rotation, and any incident review looks back at which layer failed to contain the problem. Besides monitoring the rollback and failure dashboards, we still rely on authors and on-call engineers to keep an eye out for problematic merges. We haven't yet built a circuit breaker that would automatically tighten approval requirements based on these metrics, but as we gradually reduce human intervention in the merge process, that's an area we're exploring.
One team member noted that slowing down and producing less does improve accuracy, but mainly because total workload decreases. Our priority is always to improve our ability to quickly find and fix problems.
How We Make the Review System Better
Our code review process is in a continuous improvement loop:
We treat production incidents as evaluation metrics (evals). The team collects PRs that caused incidents, the corresponding fix-forwards, and rollback records, and engineers familiar with the codebase verify the exact location and accuracy of each bug. The review system is evaluated against this sample set every day.
Every new incident is added to this set, and every change to the review system is evaluated against the entire set.
To measure noise (false positives), we look at how humans react to review comments. It's easy to inflate bug detection if you tolerate reporting lots of "fake bugs," so we must constrain that. We categorize how each PR owner handles each review comment: fixed, rejected, clarified as intentional, or deemed irrelevant. We also run the review system on known-clean PRs to see how often it suggests changes that would actually lead to harmful edits.
Our stated priorities are: first, detect real bugs; second, reduce review rounds.
When the author is an agent, processing a review comment costs more. A human can ignore a nitpick in a second, but an agent handling it produces a new commit, which triggers another review round.
The review process must converge. Otherwise, the author agent and the reviewer agent can go back and forth endlessly. We saw a PR in the CLI project loop more than 50 times overnight because the author agent and reviewer agent kept nitpicking each other's edits. That loop was finally stopped by a human; otherwise it might have run forever.
When we ran git blame on code repeatedly flagged by the review system, about 59% of it already existed in the first review round. That means the review system rarely discovers newly introduced bugs in later rounds; instead, it digs up more old issues each round.
We also contributed to this ourselves — because each round could catch different bugs, we had gotten into the habit of running multiple review rounds by default. While multi-round iterative review is useful for high-risk changes, not every PR needs it. So, in addition to recall, our team started tracking "cycles-to-pass" and made these updates to the re-review mechanism:
- Limit review rounds: After three rounds, the review system asks the author to reassess the overall implementation.
- After the first round, only review the new diff: Subsequent rounds review only added code changes.
- Specify bug categories: Let authors fix all issues of the same class at once, instead of only the line that was pointed out.
- Avoid re-reporting known issues.
- Nightly full scan: The review agent also runs nightly on the current codebase, helping us find legacy bugs before they spread.
After introducing convergence mechanisms, the average review rounds per internal PR dropped significantly.
Human-in-the-Loop
Automating review of routine errors makes sense; stopping a senior engineer to review common mistakes is expensive. But human reviewers remain indispensable for these tasks:
- Should we even build this? Deciding whether to build a feature, and setting product vision, taste, and goals. A team that claims to have solved the code review bottleneck still does human review for changes coming from outside the team, to ensure it's the right feature to build.
- Auditing high-risk code (billing, auto-updaters, CI workflows).
- Architecture review, because those choices establish the patterns everyone else follows.
- Verifying evidence (test output, commands run, screenshots, review comments). If you can't articulate what automated checks would miss, don't settle for a thumbs-up — you need an actual human review!
- Taking responsibility. Every change that ships, regardless of who typed the code, is ultimately owned by a specific person.
Team Understanding of the Codebase
Code review has always carried the secondary role of "syncing the codebase." People typically learn what's happening in the codebase and how it works by reading colleagues' diffs. If most of the reading is done by machines, how does everyone learn the codebase?
We have no formal mechanism for this. No one on the team carries the entire Claude Code codebase in their head, and we don't think anyone needs to. Instead, when anyone wants to understand a part of the codebase, they ask Claude to generate an explainer document for that specific piece of code. This takes a few minutes, and the generated explanation is always up to date.
Some of us go further and ask Claude to generate an interactive mini page or visual diagram (mini artifact) that visualizes the code, explained in a style we like.
Compared to line-by-line reading of trivial diffs (like a one-word copy change, where you learn almost nothing), focusing human attention on this is far better. Generating an explainer for the module you're about to change teaches you a lot.
We also default to working in public by default, operating in public Slack channels, so people can see what others are building in real time.
"Whoever Merges Owns It"
If you merge a small- or medium-sized change and it goes wrong, the team expectation is that you fix it yourself. This pattern doesn't spiral out of control for several reasons:
- Small change size makes them easy to review, debug, and roll back.
- Everything is revertible. Feature flags, code rollback, and staged rollout reverse most errors in minutes.
- Blast radius sets the review bar. Higher-cost code gets more eyes and more validation.
- Telemetry and heavy internal usage surface regressions quickly.
- No blame culture. The person who fixes a problem owns it because they hold the most context; incident reviews focus on the system.
- Public collaboration shares responsibility. Most of the team works in public channels, so anyone can see what others are doing, join discussions, or ask Claude to help spot gaps. Non-code-owners also give feedback. This openness lets us maintain quality without gating every line.
Course-Correction, Act Fast
With agents, the cost of starting new work is low, but sometimes you shouldn't start at all. A common pattern: someone in the channel points out the proposed direction won't work (citing a past decision or suggesting a better approach), and the author simply closes the PR or adjusts the implementation.
Because writing the code in the first place was easy, closing the PR feels like no loss. The key is to course-correct early in the discussion, rather than vote no at the end against a fully-formed PR.
How to Roll This Out
Most of the components in this approach can be adopted by your team today.
Before the pull request
- Give the agent a checklist it can run itself, and list those checks in a short
CLAUDE.mdfile - Configure hooks so the agent automatically runs formatters and linters
- Run
/code-reviewand/security-reviewlocally, or get a fresh-context subagent to review the diff - Create a
REVIEW.mdto record recurring review issues
On every pull request
- Enforce CI
- Update your PR template to include "Testing", "Risk", and "How to revert"
- Introduce AI review (Code Review for Claude Code, or the Claude Code GitHub Action) to one repository, iterate on
REVIEW.mdfor a few weeks, then roll out more broadly - Add automated security review
- Require all review threads to be resolved before merging
- Calibrate review strictness by risk: quick pass for routine changes, thorough review for high-risk areas. Code Review offers Quick, Standard, and Deep modes
- Limit review rounds; after a few rounds, only review the new diff
Approval
- Define risk tiers, based on the change, not the author. Start strict and relax as evidence accumulates
- Reserve the relaxed approval path for trusted authors
- Bot approvals cannot substitute for required human approval; auto-dismiss existing approvals when new commits are pushed
- Designate humans as approvers for auth, billing, CI, release workflows, and installer-related code and policies, enforced via
CODEOWNERSand branch protection rules
Merging and post-merge
- Set up a merge queue
- Try feature flags
- Roll out to internal users first
- Do staged rollouts
- Build a one-click rollback mechanism
- Build an eval set by recording incidents and rollbacks
- Re-score the review tool every time you change its prompts, tools, or models
- Track human effort while using rollback rate and failure rate as guardrails
Future Direction
When we first released Code Review, our design intention was that the final approval decision stays with humans; the product just posts the issues it finds. But in our own repositories, we're taking a step further: code owners are deciding which low-risk changes can auto-merge after all automated checks pass. That boundary will keep evolving.
So whenever our review system misses something, we ask ourselves: what was missing from the model's context at that time? Then we distill that into a CLAUDE.md file, a Skill, or a new automated check. Our goal remains unchanged: continuously reduce human effort per change while keeping the revert rate no higher than it is today.
If you also allow agents to open PRs, tell us which checks you've automated, where you still need human intervention, and what we're getting wrong.
Note: This article is adapted from Anthropic's original blog post and checked with Pangram.
This article is compiled from the "Oil Book" AI practical notes series by 欧呦 (Oil 欧呦).
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
Using a fresh-context sub-agent for review is a brutal move; reviewing your own work indeed easily leads you astray.