跪拜 Guibai
← Back to the summary

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:

  1. Find and fix bugs before they go live
  2. 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.

Lifecycle of a code change

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.

Multiple layers of defense, not a single gate

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:

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:

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:

The surviving issues appear as inline comments, sorted by severity and labelled as:

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.

Claude code review and security review as two complementary perspectives

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.

Human approval requirements by risk level

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.

Our incident log is the eval set

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:

A review process that converges

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:

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.

If machines read most code, how do humans understand the codebase?

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:

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.

Four-phase rollout checklist from pre-PR validation to post-merge rollback

Before the pull request

On every pull request

Approval

Merging and post-merge

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 欧呦).

Comments

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.