How the Claude Code team does code review Claude Code 团队如何做代码审查
Introduction引言
原文为图片,已转录 · Image text, transcribed
Article cover image (orange geometric abstract).
文章封面图(橙色几何抽象图)。
We previously mentioned that Claude writes about 90 percent of the code for Claude Code. So how do we do code review at this scale? Who reads code anyway? What happens if code goes wrong?
我们此前提到过,Claude Code 大约有 90% 的代码是由 Claude 写的(作者自述,未经独立核实)。那么在这种规模下,我们怎么做代码审查?到底谁在读代码?出了错又怎么办?
This post describes our team's code review process at Claude Code and how we have improved it. Between June and September, we saw more than double the number of pull requests that were merged to the codebase for Claude Code, while the share of pull requests that had to be reverted fell by more than 40 percent.
这篇文章介绍 Claude Code 团队的代码审查流程,以及我们如何改进它。作者自述:6 月到 9 月间,合并进 Claude Code 代码库的 PR 数量翻了一倍多,而不得不回滚的 PR 占比下降超过 40%(未经独立核实)。
We didn't stop doing code review. Instead, we've automated the majority of reading and tuned it to optimize for human time and effort. We've also made significant investments into improving the speed and ease of reverting mistakes.
我们并没有停止代码审查,而是把大部分「阅读」自动化了,并针对人的时间与精力做了调优;同时也大力投入,让犯错后的回滚更快、更省事。
Rethinking the goal of code review重新思考代码审查的目标
With agents writing code, the volume of changes increases rapidly. In our monorepo, we went from approximately 2,500 changes merging each day in May to over 30,000 in September of this year. (Related: https://www.anthropic.com/engineering/redesigning-source-control)
有 agent 写代码后,变更量会迅速膨胀。作者自述:在他们的 monorepo 里,每天合并的变更从 5 月约 2,500 次涨到今年 9 月超过 30,000 次(未经独立核实)。相关阅读:https://www.anthropic.com/engineering/redesigning-source-control
While Claude Code is not in our monorepo, it has a lot of pressure on it as well. When you're moving fast like that, it becomes increasingly hard, if not impossible, to do code review manually, line by line.
虽然 Claude Code 不在这个 monorepo 里,但它同样压力很大。以这种速度推进时,逐行人工审查会越来越难,甚至不可能。
Code review serves two purposes:
代码审查有两个目的:
- Detect and correct bugs before they ship在上线前发现并修正 bug
- Develop a shared understanding of the codebase形成对代码库的共同理解
While this article focuses primarily on the first goal, we'll discuss the second goal toward the end of the post.
本文主要谈第一个目标;第二个目标会在文末讨论。
We view "did someone read the code?" as an imprecise measure of "what could go wrong with this change, and what check — automated or human — is the right one to catch it?"
我们不再把「有没有人读过这段代码」当作精确指标,而是追问:「这次变更可能出什么问题?该用哪一种检查——自动化还是人工——来拦住它?」
This question also changed the timing of code review. Traditionally, code review was a check performed after the fact, when the code was written, the PR was filed, and someone waited for someone else to take a look. Instead, we've integrated code review into the workflow. It's more like a spellcheck that you continuously do while writing.
这个问题也改变了审查时机。传统做法是事后检查:代码写完、PR 提了,再等人来看。我们则把审查嵌进工作流,更像写作时持续开启的拼写检查。
The majority of changes have already been reviewed and corrected by Claude, at least once, before a human is asked to take a look. In this way, we catch most of the routine bugs and reserve human attention for more high-level considerations.
多数变更在请人看之前,已经至少被 Claude 审查并修正过一轮。这样能拦住大部分常规 bug,把人的注意力留给更高层的判断。
Human time and attention人的时间与注意力
We want to reserve human time and attention for things only humans can handle, while making sure we have enough automation to cover the rest. Even at our current pace, there is still an incredible amount of work for humans to do, and our team is encountering new and novel challenges almost every day.
我们希望把人的时间留给只有人能做的事,其余尽量用自动化覆盖。即便以现在的速度,人要做的事依然极多,团队几乎每天都碰到新问题。
For this reason, human time is a dual-sided cost. Not only do we count the time people spend doing code review, but also the time that they spend fixing bugs that are introduced by bad code. If we reduce the first without reducing the second, we're not really saving human time.
因此,人的时间是双边成本:既要算审查花掉的时间,也要算烂代码引入 bug 后去修的时间。如果只压前者、不压后者,并没有真正省下人时。
So, our goal is that the majority of pull requests in our Claude Code repos (the CLI, the desktop and web apps, and the mobile apps) should merge with a maximum of one person in the loop (who could be the author) without an increase in reverts or incidents.
因此目标是:Claude Code 相关仓库(CLI、桌面与网页、移动端)里,大多数 PR 最多只需一个人介入(可以是作者本人)就能合并,且回滚与事故率不上升。
We track our human time in terms of median human approvals per PR (along with the 95th percentile), the number of human comments, and how long a PR waits on a person. We use the revert and incident rates as a guardrail: if these metrics increase, we haven't reduced human time, just relocated it.
人时方面,我们跟踪每个 PR 的人工批准数中位数(以及第 95 百分位)、人工评论数、以及 PR 等人的时长。回滚率与事故率是护栏:这些指标上升,说明人时只是被挪了地方,并没有真正减少。
What's the journey of a change?一次变更要走完怎样的路程?
A typical change, whether it's from an engineer's laptop or a Claude session in Slack, goes through multiple layers of review.
一次典型变更——无论来自工程师笔记本,还是 Slack 里的 Claude 会话——都会经过多层审查。
原文为图片,已转录 · Image text, transcribed
Title: The life of a change — A typical Claude Code change, from the author's machine to users.
Before the Pull Request:
• The work is verified (automated): Claude runs tests, build, and linter; a second agent reviews the diff in a fresh context.
On Every Pull Request:
• Required CI (automated): lint, types, tests across platforms, build and packaging. Red blocks the merge.
• Claude code review (automated): agents hunt for bugs in parallel; verifiers vote on each finding; survivors ranked by severity.
• Security review (automated): a separate pass; open findings from either review block the merge.
• Risk-based approval (a person decides, scaled by risk): a classifier sets the tier — no person, one, or two; some paths always need a person.
Merging:
• Merge queue (automated): checks run again on the latest main with the change applied.
After the Merge:
• Behind a flag, used internally first (automated): Anthropic employees run it before everyone else.
• Gradual release (automated): latest channel first; stable trails it.
• Watch, fix forward or roll back (recovery): author and on-call watch; flags turn off quickly; broken builds get reverted.
Legend: checkmark = automated; orange diamond = a person decides, scaled by risk; circular arrow = recovery.
标题:一次变更的生命周期——从作者机器到用户的典型 Claude Code 变更。
提 PR 之前:
• 工作已验证(自动化):Claude 跑测试、构建与 linter;第二个 agent 在全新上下文里审 diff。
每个 PR 上:
• 必过 CI(自动化):lint、类型、跨平台测试、构建与打包;红灯阻断合并。
• Claude 代码审查(自动化):多个 agent 并行找 bug;校验者对每条发现投票;留下的按严重度排序。
• 安全审查(自动化):单独一轮;任一审查的未关闭发现都会阻断合并。
• 按风险分级的批准(人按风险决定):分类器定档——无人 / 一人 / 两人;部分路径永远需要人。
合并:
• 合并队列(自动化):在最新 main 上叠加本次变更再跑检查。
合并之后:
• 先挂 feature flag、内部先用(自动化):Anthropic 员工先跑。
• 渐进发布(自动化):先 latest 通道,stable 随后。
• 观察、前向修复或回滚(恢复):作者与 on-call 盯着;flag 可快速关掉;坏构建会被回滚。
图例:对勾=自动化;橙菱形=人按风险决定;循环箭头=恢复。
Above is the typical Claude Code change, from the author's environment to production. Most of this process is automated, with human attention focused on the risky part.
上图是一次典型 Claude Code 变更:从作者环境到生产。流程大多自动化,人的注意力集中在高风险部分。
We have six layers of checks with a rollback mechanism to handle any issues that get through.
我们有六层检查,外加回滚机制,兜住漏网问题。
原文为图片,已转录 · Image text, transcribed
Title: Layers, not one gate — Six layers of checks, with rollback under them.
Swiss-cheese style diagram. Problems enter from the top. Six stacked layers: (1) verification, (2) required CI, (3) AI review, (4) security review, (5) human approval, (6) merge queue + flags. Each layer has holes; some problems are caught on a layer, some fall through. A path can pierce every hole down to the bottom, where "fast rollback" sits as the last net.
标题:多层,而不是一道闸——六层检查,底下是回滚。
瑞士奶酪式示意图。问题从上方进入。六层依次为:(1) 验证 (2) 必过 CI (3) AI 审查 (4) 安全审查 (5) 人工批准 (6) 合并队列 + flag。每层都有「洞」;有的问题被拦下,有的掉到下一层。也可能一路穿透所有洞,落到最底下的「快速回滚」安全网。
Each layer catches some bugs while missing others. Few bugs get through all of the layers, and if some do, we have a rollback mechanism in place.
每一层都会拦住一些 bug,也漏掉一些。能穿过全部层的很少;万一漏了,还有回滚兜底。
1. Pre-PR verification1. 提 PR 前的验证
1. Pre-PR verification:
1. 提 PR 前的验证:
Most of our review is done before we create a PR. We ask Claude to do something runnable, such as running tests, the build, or comparing a screenshot to the design. Instead of saying the task is done, we ask it to show us the result. Then, a subagent reviews the diff with fresh context. Both these strategies are part of our guide to best practices (https://code.claude.com/docs/en/best-practices).
大部分审查发生在创建 PR 之前。我们让 Claude 做可运行的事:跑测试、构建,或把截图和设计稿对比。不是嘴上说「做完了」,而是展示结果。然后用一个子 agent,在全新上下文里审 diff。这两招都写在最佳实践指南里:https://code.claude.com/docs/en/best-practices
Before opening a PR, many of us also run a handful of internal skills — bug hunting, diff reduction, end-to-end validation, and checking our UI changes against our design guidelines.
开 PR 前,很多人还会跑一批内部 skills:找 bug、压缩 diff、端到端验证,以及对照设计规范检查 UI 改动。
According to Boris Cherny, who created Claude Code, equipping Claude with a verification process is probably the biggest key to higher quality outcomes. (https://x.com/bcherny/status/2007179861115511237)
Claude Code 创建者 Boris Cherny 认为,给 Claude 配上验证流程,大概是提升质量最关键的一把钥匙。(https://x.com/bcherny/status/2007179861115511237)
He estimates that a verification process improves the quality of Claude's output by a factor of two to three.
他估计,验证流程能把 Claude 输出质量提高约两到三倍(作者转述的估计,未经独立核实)。
The verification process for any given domain can be very different:
不同领域的验证流程可以差很多:
Sometimes it's as simple as running a bash command. Sometimes it's running a test suite. Sometimes it's testing the app in a browser or phone simulator.
有时只是跑一条 bash;有时是整套测试;有时是在浏览器或手机模拟器里测应用。
If the automated reviewer is consistently flagging the same issue, we fix it at the source — via the skill itself, a lint rule, or updating documentation files like:
如果自动审查员总在标同一类问题,我们就从源头修:改 skill、加 lint 规则,或更新这类文档:
CLAUDE.md — The project description file that you can use to give Claude context about the project (technology stack, conventions, goals, non-goals). Claude Code pulls this file in for every single review, so we keep it brief for large codebases and reference the rest of the documentation here. When code breaks a convention in this file, or an update makes something in it out of date, the reviewer flags it.
CLAUDE.md——给 Claude 项目上下文的描述文件(技术栈、约定、目标与非目标)。每次审查 Claude Code 都会读它,所以大仓库里我们写得很短,其余文档在这里引用。代码违反其中约定,或更新导致文件过时,审查员都会标出来。
REVIEW.md — The file where code owners tell the reviewer what matters in their part of the code. We separately verify whether the reviewer is actually following these guidelines. Good ones are brief and focus on:
REVIEW.md——代码负责人告诉审查员「自己这块什么最重要」的文件。我们会单独核查审查员是否真按这些指南做。好的 REVIEW.md 很短,重点放在:
- Defining project failure (the docs should not lie; the config should not misroute)定义项目级失败(文档不能撒谎;配置不能误路由)
- Limiting nitpicking限制抠细节式 nitpick
- Defining ignored paths定义可忽略路径
- Requiring file + line reference, not guessing filenames要求给出文件+行号,而不是猜文件名
- Requiring top-level summary including count and clear statement of "no issues"要求顶层摘要:含数量,并明确写出「无问题」
2. AI review on every pull request2. 每个 PR 上的 AI 审查
2. AI review on every pull request
2. 每个 PR 上的 AI 审查
Every PR receives a Claude review before a human review.
每个 PR 在人工审查前,都会先过一轮 Claude 审查。
The diff is analyzed against the entire codebase and the intent of the PR as stated by the PR author. It checks that: the change actually addresses the issue; the change fits into the larger system; the change does not break other parts of the codebase.
它会对照整个代码库,以及作者陈述的 PR 意图来分析 diff,检查:改动是否真的解决了问题;是否契合更大系统;是否会弄坏代码库其他部分。
When reviewing a bug fix, the bot tries to find the root cause.
审 bug 修复时,bot 会尝试找根因。
Our public product, Code Review for Claude Code (https://code.claude.com/docs/en/code-review), is now available to all Team and Enterprise customers. There is a lighter version for local use as well — /code-review.
对外产品「Code Review for Claude Code」(https://code.claude.com/docs/en/code-review)现已对全部 Team 与 Enterprise 客户开放;本地也有轻量版:/code-review。
Since we released the research preview, the share of our internal PRs getting substantive review comments has gone from 16% to 54%. Code Review detects issues on the majority of PRs with more than 1,000 lines and returns clean results on most smaller PRs. Repos can be configured by admins to use Quick, Standard, or Deep modes. Deep is useful in cases where the cost of missing a single bug is higher than the time spent reviewing code.
作者自述:研究预览发布后,内部 PR 中收到实质性审查意见的比例从 16% 升到 54%(未经独立核实)。千行以上的 PR,多数能被检出问题;较小的 PR 多数返回干净结果。管理员可把仓库配成 Quick / Standard / Deep。漏掉一个 bug 的代价高于审查时间时,适合用 Deep。
Findings are vetted by multiple other agents before human review:
发现在给人看之前,会先经多个其他 agent 筛过:
- Multiple agents run in parallel to hunt for bugs多个 agent 并行找 bug
- A separate vote decides if a finding is valid or a false positive, only confirming the findings that have enough votes另设投票判定真阳性或误报,票数够才确认
- Findings that are only style/diagnostics/cleanup related are filtered out (we A/B tested these filters on our own PRs before rolling them out)纯风格 / 诊断 / 清理类发现会被滤掉(上线前在自家 PR 上做过 A/B)
The remaining findings are presented as inline comments, ordered by severity level and marked as:
剩下的发现以行内评论呈现,按严重度排序,并标成:
- ImportantImportant(重要)
- NitNit(吹毛求疵级)
- Pre-existing (so we don't unfairly penalize the author for bugs that were not introduced by the PR)Pre-existing(已有问题,避免把非本次引入的 bug 算到作者头上)
All findings must be addressed — fixed or the thread is resolved with a reason. In many cases, an agent will fix the problem overnight so the author returns to a PR that's already been through another review pass.
所有发现都必须处理:修好,或带着理由关闭讨论。很多情况下,agent 会连夜修好,作者回来时 PR 已经又过了一轮审查。
3–7. Security, CI, human approval, merge, rollback3–7. 安全、CI、人工批准、合并与回滚
3. Security review that can block
3. 可阻断合并的安全审查
We also run an automated security review. No PR can be merged while there is still an open finding (either from the code review or the security review). The author can either fix the issue or close the thread with a short reason (how we deal with a false positive).
我们还会跑自动化安全审查。代码审查或安全审查只要还有未关闭发现,PR 就不能合。作者可以修掉问题,或用简短理由关闭讨论(处理误报的方式)。
A finding will be auto-closed if a subsequent commit addresses the problem. You can set up the same thing with the open-source security review GitHub Action, or the /security-review command. See automated security reviews in Claude Code for a guide on how to set this up.
后续 commit 修好问题后,发现会自动关闭。可用开源的 security review GitHub Action,或 /security-review 命令搭同样的东西;Claude Code 文档里有自动化安全审查指南。
4. Automated checks that block
4. 可阻断合并的自动化检查
Standard checks: lint, type checks, tests on all platforms, build. (We wrote about how we scaled CI here.) A typical CLI PR can have dozens of checks run before anyone looks at it. The PR template has questions about how the change was tested and how to revert it. Claude can answer those for you, but the author is responsible for reviewing them.
标准检查:lint、类型检查、全平台测试、构建。(他们另文写过如何扩容 CI。)一个典型 CLI PR,在任何人看之前就可以跑几十项检查。PR 模板会问如何测试、如何回滚;Claude 可以代填,但作者必须审过这些内容。
5. Human approval, scaled by risk
5. 按风险缩放的人工批准
Some changes are more risky than others (e.g. a docs fix vs. an auto-updater change), so they require different levels of review.
有的变更风险更高(比如改文档 vs 改自动更新器),审查力度也不同。
原文为图片,已转录 · Image text, transcribed
Risk / Examples / Human approvals
Low Risk — Docs, copy, internal-only features, additive changes behind a flag. — None required once automated review and security checks are green.
Medium Risk — Ordinary product changes, and changes to sensitive areas such as caching, the auto-updater, or system prompts. — One person.
High Risk — The highest-risk code, plus a small set of paths that always need two people. — Two people.
风险 / 示例 / 人工批准
低风险——文档、文案、仅内部功能、挂在 flag 后的增量改动。——自动审查与安全检查变绿后可不要求人工。
中风险——普通产品改动,以及缓存、自动更新器、系统提示词等敏感区。——一人。
高风险——最高风险代码,外加一小批永远需要两人的路径。——两人。
The tier is determined by the change, not the author. A classifier determines the risk level based on the change. Another classifier determines if a particular change actually requires another approval, even if the tier does not say it does. Some paths always require another approval — anything marked as sensitive by owners, and any CI workflow file.
档位由变更本身决定,不看作者是谁。一个分类器按变更定风险;另一个判断即便档位未要求,是否仍需额外批准。有些路径永远需要额外批准:负责人标为敏感的路径,以及任何 CI workflow 文件。
Only authors on the repo's trusted list receive relaxed review requirements, and that's generally the team that owns the repo. All others require a second person to approve. Agent approvals don't count as human approvals. Automated review can clear a low-risk change, but it can't stand in for a human when one is required.
只有仓库信任名单上的作者能享受放宽要求,通常就是仓库所属团队。其他人必须第二人批准。Agent 批准不算人工批准。自动审查可以放行低风险变更,但在需要人的时候不能顶替人。
The author of the change is responsible for it, so if an agent authors a PR the operator of the agent is always counted as one of the required reviewers. A PR approval is only good for one commit. If a new commit lands that can't be trusted (e.g. an agent pushed something, or someone resolved a merge by hand), the PR must be reapproved.
变更作者要负责:若 PR 由 agent 撰写,操作该 agent 的人永远算作必需审查者之一。一次批准只对一个 commit 有效。若出现不可信的新 commit(例如 agent 又推了东西,或有人手搓合并解决冲突),必须重新批准。
6. Merge queue, feature flags and staged rollouts
6. 合并队列、feature flag 与分阶段放量
The merge queue ensures that all the checks run on main with the change applied. This prevents merging two successful PRs into a broken main. Typically, new features are rolled out behind a feature flag, with Anthropic employees getting access first. Because we use the product extensively, we often notice regressions before our users do.
合并队列确保检查是在「已叠上本次变更的最新 main」上跑的,避免两个各自绿灯的 PR 合出坏掉的 main。新功能通常挂在 feature flag 后先放给 Anthropic 员工。因为自己重度使用产品,回归往往比用户更早发现。
When we roll out publicly, changes go to the latest channel first, and the stable channel trails behind.
对外放量时,先上 latest 通道,stable 通道随后跟上。
7. Fast feedback and rollback
7. 快速反馈与回滚
Some bad merges will inevitably make it through. This is our last line of defense, focused on identifying these as quickly as possible. Changes behind feature flags can be disabled without deploying.
总会有坏合并漏网。这是最后一道防线,重点是尽快发现。挂在 feature flag 后的变更可以不发版就关掉。
Claude Code runs a weekly on-call rotation and any incident reviews involve looking back to see what layer should have caught the problem. It's still up to the author and on-call to notice bad merges, in addition to monitoring the revert and incident dashboards. We don't yet have circuit breaker mechanisms that adjust approval requirements based on these, but it's something we're looking into as we're making progress toward less human intervention in merging.
Claude Code 有每周 on-call 轮值;事故复盘会回看本该由哪一层拦住。发现坏合并仍靠作者与 on-call,外加回滚与事故看板。他们还没有按这些指标自动收紧批准要求的熔断机制,但在减少合并人工介入的路上正在考虑。
One team member noted that slowing down and reducing output can actually improve accuracy, but that's mostly because the amount of work being done decreases overall. Our priority is really on improving our ability to identify and correct issues quickly.
有位同事说,放慢、少产出确实能提高准确率,但多半是因为总工作量下降了。真正优先的是更快发现问题并修正。
How we make the reviewer better我们如何把审查员做得更好
Our code review process is an ongoing cycle of improvement:
代码审查流程是持续改进的循环:
We use incidents as an evaluation metric. The team collected incident-causing PRs, their fix-forwards and reverts, and had the engineers who understand the codebase verify the location and correctness of each bug. The review system is evaluated daily against this collection.
事故本身就是评测指标。团队收集导致事故的 PR、前向修复与回滚,由熟悉代码库的工程师核对每个 bug 的位置与判定是否正确。审查系统每天对照这套集合评测。
原文为图片,已转录 · Image text, transcribed
Title: Our incidents are the eval — Built from past incidents and reverts, run every day.
Flow: Incident or revert (a change that broke something) → Expert-checked case (experts confirm the bug) → Added to the set (each incident adds a case) → Change the reviewer (its prompts, tools or model) → Daily eval run (scored against every case) → Score went up? (keep it; if not, drop it) → next change loops back to changing the reviewer.
标题:事故就是评测集——由历史事故与回滚建成,每天跑。
流程:事故或回滚(弄坏东西的变更)→ 专家核对案例(确认 bug)→ 加入集合(每次事故加一条)→ 改审查员(提示词、工具或模型)→ 每日评测(对照每条案例打分)→ 分数升了吗?(升了就留下,否则丢掉)→「下一次改动」再回到改审查员。
Every incident adds to the collection and every change to the review system is evaluated against the entire collection.
每次事故都会进集合;对审查系统的每次改动,都用整套集合来评。
To measure noise, we observe how humans react to the review comments. It's easy to improve our bug-finding rate if we're okay with reporting lots of non-bugs, so this needs to be regulated. We categorize each review comment into how the person on the PR handled it: fixed the issue, rejected it, clarified it as intentional, or decided it didn't matter. Additionally, we run the review system on PRs we know to be clean and observe how often the system reports something that would have resulted in a harmful change.
测噪声时,看人对审查意见的反应。如果愿意报大量非 bug,检出率很容易虚高,所以必须管控。每条意见按处理方式归类:修了、拒了、澄清为有意为之、或判定无关紧要。另外,还会在已知干净的 PR 上跑审查,看系统多久会报出会导致有害改动的东西。
Our stated priorities are first, detecting real bugs, and second, reducing the number of review cycles.
公开优先级:先抓真 bug,再减少审查轮次。
It's more costly for an author to have to deal with a review comment when they're an agent. It only takes a second for a human to dismiss a nit, but when an agent has to address it, this results in another commit, and another cycle of review.
作者若是 agent,处理一条审查意见的成本更高。人一秒钟就能关掉 nit;agent 一处理就会再出一个 commit,再多一轮审查。
The review process must converge. It's possible for an agent author and an agent reviewer to cycle forever. We observed one PR in our CLI project cycle more than fifty times overnight, due to the back-and-forth between the agent author and the agent reviewer. This cycle was stopped manually, but it could have gone on indefinitely.
审查过程必须收敛。agent 作者和 agent 审查员有可能永远互怼。作者自述:CLI 项目里曾有一个 PR 一夜循环五十多次,最后靠人手停掉,否则可能无限转下去(未经独立核实)。
When we ran git blame on what the review system kept flagging, ~59% of it was code that had been there since its first pass. Essentially, the review system was rarely finding new bugs, but finding a few more old ones on each cycle.
作者自述:对审查系统反复标出的内容做 git blame,约 59% 是第一轮就已存在的代码——系统很少发现新 bug,只是每轮多挖出一点旧问题(未经独立核实)。
We made this worse because we had gotten into the habit of running several review cycles by default, because each cycle can find a different bug. While it can be useful to iterate through several review cycles for a high-risk change, it's not needed for every PR. Our team started tracking the number of cycles-to-pass in addition to recall, and updated re-review to:
默认多跑几轮审查让情况更糟——因为每轮可能挖到不同 bug。高风险变更多轮迭代有用,但不是每个 PR 都需要。团队开始在 recall 之外跟踪「通过所需轮次」,并把复审改成:
- Limit the number of cycles. The review system asks the author to re-evaluate the approach after three cycles.限制轮次。三轮后审查系统会要求作者重新评估方案。
- Limit re-review to just diff after the initial cycles.初期几轮之后,复审只看 diff。
- Specify the class of bugs, so the author can correct all of them, not just one line.点明 bug 类别,让作者一次改整类,而不是只改一行。
- Avoid re-reporting issues already observed.避免重复报告已见过的问题。
The review agents are also run on the current codebase overnight, helping us identify historical bugs before they propagate.
审查 agent 还会连夜在当前代码库上跑,帮助在历史 bug 扩散前发现它们。
原文为图片,已转录 · Image text, transcribed
Title: Review that converges — Internal pull requests, before and after the convergence changes.
Pass after one review and fix round (higher better): before 65% → after 78%.
Need five or more rounds (lower better): before 8.9% → after 1.5%.
Mean reviews to pass (lower better): before 2.08 → after 1.32.
(Author's internal metrics; not independently verified.)
标题:会收敛的审查——内部 PR,收敛改动前后对比。
一轮审查+修复即通过(越高越好):前 65% → 后 78%。
需要五轮及以上(越低越好):前 8.9% → 后 1.5%。
通过所需平均审查次数(越低越好):前 2.08 → 后 1.32。
(作者内部指标,未经独立核实。)
Reduction in the average number of review rounds per internal pull request after Convergence.
「收敛」改动之后,内部 PR 平均审查轮次下降。
Humans in the loop人在回路里
Having a senior engineer stop working to review a common error is an expensive process compared to automating that process. Human reviewers are still essential for some tasks:
让资深工程师停下手里的活去审一个常见错误,比自动化贵得多。但有些事仍必须靠人:
- Should we even build this? Deciding whether or not to build something, setting the vision, taste, and goals for the product.该不该做?决定做不做、定产品愿景、品味与目标。
One team that claims they have solved the bottleneck of code review still performs human review for changes from outside the team to ensure that it is the right thing to build.
有个自称解决了审查瓶颈的团队,对外来变更仍做人工审查,确认「该不该造这个」。
- Auditing dangerous code (billing, auto-updater, CI workflows).审计危险代码(计费、自动更新器、CI workflow)。
- Architecture review, because those choices set the conventions others follow.架构审查——这些选择会定下别人要遵守的约定。
- Verifying proofs (test output, commands run, screenshots, reviewer comments). If you can't describe what the checks would miss, don't ask for a 👍, you need a real review!核验证据(测试输出、跑过的命令、截图、审查意见)。如果你说不清检查会漏什么,就别只求一个 👍——需要真审查!
- Taking responsibility. A person answers for every change that ships, whoever typed it.承担责任。每个上线的变更都有人对它负责,不论是谁敲的字。
Team context团队上下文
Code review has always served the dual purpose of communicating codebase changes. Reading the diff of a colleague's change is how people usually understand what has changed, and how the codebase works. If the bulk of the reading is done by machines, what becomes the way to learn the codebase?
代码审查一向也有沟通变更的作用。读同事的 diff,通常是人理解「改了什么、代码库怎么转」的方式。如果大部分阅读交给机器,人还怎么学代码库?
We don't have any formal mechanism for this. No member of the team has a full mental model of Claude Code in their head, nor do we think anyone needs to. Rather, when anyone wants to learn about a piece of the codebase, they ask Claude to generate an explainer about that exact slice. It only takes a few minutes and the explainer is always up to date.
他们没有正式机制。团队里没人脑中有完整的 Claude Code 心智模型,也不认为需要有。想了解某一块时,就让 Claude 针对那一小片生成讲解:几分钟,而且永远跟当前代码同步。
原文为图片,已转录 · Image text, transcribed
Title: Sharing context across the team.
The codebase: a grid of modules; highlighted slice labeled "managed settings — the part you want to understand." Caption: Nobody keeps a complete mental model of it in their head.
Ask Claude about exactly that slice. Example: "How does Claude Code retrieve managed settings?"
Two outcomes: (1) Claude writes an explainer — takes minutes and reflects the code as it is today. (2) Some go a step further: Claude builds a small artifact — visualizes that part and teaches it the way that person likes to learn.
Contrast: Reading trivial diffs line by line (a one-line copy change teaches you almost nothing) vs. An explainer for the module you're about to change teaches you a lot.
标题:在团队间共享上下文。
代码库:模块网格;高亮的一块标为「managed settings——你想搞懂的那部分」。说明:没人脑子里装着完整心智模型。
就问 Claude 那一小片。例:「Claude Code 怎么取 managed settings?」
两种结果:(1) Claude 写讲解——几分钟,且反映今天的代码。(2) 有人更进一步:让 Claude 做一个小产物——把那块可视化,并按此人喜欢的方式教。
对比:逐行读琐碎 diff(一行文案改动几乎学不到东西)vs. 针对你即将改动的模块做讲解,能学到很多。
For some of us, we go the extra step and have Claude generate a mini artifact that visualizes this area and teaches it in our preferred style.
有些人还会更进一步,让 Claude 生成可视化该区域、并按自己偏好风格教学的小产物。
This is a better way to focus our human attention than reading trivial diffs line by line, which teaches you very little (e.g. a one-line copy change). Creating an explainer about the module you're going to change teaches you a lot.
这比逐行读琐碎 diff 更能把人的注意力用在刀刃上——一行文案改动几乎学不到东西;给即将改动的模块写讲解,能学到很多。
Plus, we're generally open by default, working in open Slack channels, and seeing what others are building as they build it.
另外,默认开放:在公开 Slack 频道工作,边建边看别人在做什么。
"You land it, you own it"「你合的,你负责」
If you merge a small or medium change, and something still goes wrong, the general expectation is that you usually fix it yourself. There are a few reasons why this doesn't spiral out of control:
合入中小变更后若仍出问题,一般期望你自己修。之所以不会失控,有几条原因:
- Small changes that are easy to review, debug, and revert.变更小,易审、易调、易回滚。
- Everything can be reverted. Feature flags, reverts, and staged rollouts can reverse most mistakes in minutes.几乎都能回退。feature flag、回滚与分阶段放量,多数错误几分钟内可逆。
- Blast radius sets the bar. More expensive code gets more eyes and validation.爆炸半径定标准。代价越高的代码,看得越多、验得越严。
- Regressions are surfaced quickly by telemetry and internal usage.遥测与内部使用能快速浮出回归。
- It's not a blame game. The person who fixes the issue owns it because they have the most context. Incident reviews consider the system.不是甩锅游戏。修的人负责,是因为他们上下文最多。事故复盘看的是系统。
- Plus, much of the team shares responsibilities by working in open channels. Anyone can see what others are building, join in on the conversation, or have Claude look for gaps. Feedback also comes from non-code owners. That openness is a big part of why quality stays high without a gate on every line.再加上开放频道共担:谁都能看见别人在建什么、加入讨论,或让 Claude 找缺口。非代码负责人也会给反馈。这种开放,是「不必每行设闸」还能维持质量的重要原因。
Changing course改弦更张
With agents, it is cheap to start new work, but sometimes you shouldn't. This typically arises when someone in the channel calls out the proposed change as an invalid path (citing previous decisions or suggesting a better path), and the author either closes the PR or changes the implementation.
有了 agent,开工很便宜,但有时不该开。典型情况是频道里有人指出方案是无效路径(引用既有决策或提出更好路径),作者关掉 PR 或改实现。
Because it was easy to write the code in the first place, it doesn't feel like a loss to close the PR. The key is to pivot early in the thread, instead of waiting until the end to make a blocking comment on a finalized PR.
因为代码本来就好写,关 PR 也不觉得亏。关键是在讨论早期转向,而不是等 PR 定稿后再丢阻塞性评论。
How to implement怎么落地
Most of the components of this approach are already available to your team.
这套做法里的多数组件,你的团队已经能用上。
Before the pull request
提 PR 之前
- Give the agent a checklist of checks it can run. List these checks in a short CLAUDE.md file给 agent 一份可跑的检查清单,写进简短的 CLAUDE.md
- Set up the agent to call formatters and linters via hooks用 hooks 让 agent 调用 formatter 与 linter
- Run /code-review and /security-review locally or have a new-context subagent review the changes本地跑 /code-review 与 /security-review,或用全新上下文的子 agent 审改动
- Create a REVIEW.md, and use it to track recurring review issues建 REVIEW.md,用来跟踪反复出现的审查问题
On every pull request
每个 PR 上
- Enforce CI强制过 CI
- Update your PR template with "Testing", "Risk" and "How to revert"PR 模板加上「测试」「风险」「如何回滚」
- On one repo, add an AI reviewer (Code Review for Claude Code, or the Claude Code GitHub Action), and iterate on your REVIEW.md for a few weeks before rolling it out to more repos.先在一个仓库加 AI 审查员(Code Review for Claude Code,或 Claude Code GitHub Action),把 REVIEW.md 迭代几周再推广到更多仓库。
- Add an automated security review加上自动化安全审查
- Require that all review threads be resolved before merging合并前要求所有审查讨论已解决
- Apply review rigor according to risk: a quick pass for routine changes, and a thorough review for high-risk areas (where bugs are expensive). Code Review has Quick, Standard and Deep levels.按风险定审查力度:常规变更快走一遍,高风险区(bug 代价高)细审。Code Review 有 Quick / Standard / Deep。
- Limit the number of review rounds, and after a few rounds, just review the new diff.限制审查轮次;几轮之后只审新 diff。
Approval
批准
- Define risk levels, which are set based on the change, not the author. Start strict, and progressively relax as you see evidence.按变更(不是按作者)定义风险档。先严,有证据再逐步放宽。
- Reserve lenient approval paths for trusted authors.宽松批准路径留给信任作者。
- Bot approvals cannot be used to satisfy a required approval. Dismiss any approvals when new commits are pushed.Bot 批准不能顶替必需的人工批准。有新 commit 就作废旧批准。
- Designate humans as the approvers for code and policies controlling auth, billing, CI, and release workflows, as well as installers. Use CODEOWNERS and branch protection for this.鉴权、计费、CI、发布流程与安装器等,指定人做批准人;用 CODEOWNERS 与分支保护落实。
Merging and post-merge
合并与合并之后
- Set up a merge queue建合并队列
- Experiment with feature flags试 feature flag
- Launch to internal users first先放内部用户
- Roll out in stages分阶段放量
- Create a one-step revert mechanism做一键回滚
- Build a set of evals by logging incidents and reverts用事故与回滚日志建评测集
- Rescore the reviewer any time you change its prompts, tools or model改提示词、工具或模型后,重新给审查员打分
- Track human effort, using reverts and incident rates as guardrails跟踪人时,用回滚与事故率做护栏
Where this is headed往哪走
Code Review was announced with the intention that the final approval decision would still be made by a human. All the product does is post its findings. But in our own repos, we are going further: Owners are deciding which low-risk changes can be merged automatically when the automated checks pass. And this boundary will continue to evolve.
对外宣布 Code Review 时的设想是:最终批准仍由人做,产品只是贴出发现。但在他们自己的仓库里走得更远:负责人在决定哪些低风险变更在自动检查通过后可自动合并。这条边界还会继续演进。
So whenever our reviewers miss something, we ask ourselves what wasn't in the model's context, and turn that into a CLAUDE.md file, a skill or a new check. And we haven't changed our goal: To reduce the amount of human effort per change while keeping our revert rate no higher than it is now.
所以审查员漏了什么,就问模型上下文里缺了什么,再写进 CLAUDE.md、做成 skill 或新检查。目标没变:降低每次变更的人时,同时让回滚率不高于现在。
So if you also allow agents to create pull requests, please let us know what checks you've automated, what requires a human, and what we're getting wrong.
如果你也允许 agent 提 PR,欢迎告诉他们:你们自动化了哪些检查、哪些仍需人、以及他们认为哪里说错了。
A rewrite of our original article (https://claude.dev/blog/solving-code-review-at-anthropic/) and checked with Pangram.
本文是对原文章(https://claude.dev/blog/solving-code-review-at-anthropic/)的改写,并用 Pangram 做过检查。