How the Claude Code team does code review
https://claude.dev/blog/solving-code-review-at-anthropic/📌 【Anthropic 實戰】Claude Code 團隊如何審查 AI 寫的九成程式碼
TL;DR:PR 量半年翻倍、revert 比例反而下降四成,關鍵是把閱讀程式碼的工作大量交給機器。
Claude Code 團隊曾公開表示,Claude 寫了這個產品大約九成的程式碼。問題是:當程式碼產出速度這麼快,人力審查真的追得上嗎?這篇文章給出的答案不是放棄審查,而是重新定義「誰該審查什麼」。
🤔 變更量暴增後,逐行人工審查已經不現實
Anthropic 的 monorepo 每日變更量從 5 月的約 2500 筆,暴增到 9 月超過 30000 筆;Claude Code 雖然是獨立的程式碼庫,也承受著同樣的壓力。團隊因此重新思考 code review 原本要做的兩件事:在上線前找出並修正問題,以及在團隊內建立共享的程式碼理解。文章把重心放在第一件事上,並指出過去把「有沒有人讀過這段程式碼」當作品質的代理指標並不精確,真正該問的是「這個改動可能出什麼問題,該用自動化還是人工檢查去抓」。這個思路轉變也改變了審查發生的時間點:過去審查是終點關卡(寫完程式、開 PR、等同事看),現在審查更像邊寫邊跑的拼字檢查,持續運作;多數變更在交給人之前,已經被 Claude 審查並修正過至少一次。
🧩 六層防線,大多數交給機器,人力只接最後一關
團隊把人力時間視為最稀缺的資源,涵蓋審查花掉的時間、以及壞程式碼造成問題後修復花掉的時間——只縮短前者而讓後者增加並不算真正省到時間。目標是讓 Claude Code 旗下各個 repo(CLI、桌面與網頁版、行動版)裡多數 PR 最多只需要一位人類在迴圈中(可以是作者本人),同時不讓 revert 或事故率上升。團隊靠每個 PR 的人工核准數(中位數與 95 百分位)、人工留言數、PR 等待人工處理的時間來衡量人力投入,再用 revert 與事故率作為護欄指標。具體的六層防線包括:
- PR 開出前先自我驗證:給 Claude 可執行的驗證方式(跑測試、build,或拿截圖比對設計稿),要求它直接展示結果而不是宣稱「做完了」,再由另一個全新上下文的 subagent 審查這份 diff。不少工程師在開 PR 前還會跑內部技能:一個專門抓 bug、一個簡化 diff、一個端到端檢查行為,UI 變更則另外比對設計規範。Claude Code 創造者 Boris Cherny 認為,給 Claude 一個驗證自己工作的方式,可能是拿到好結果最重要的一件事,估計能讓最終結果好上兩到三倍。當自動審查反覆標記同一類問題,團隊會從源頭修正:寫進技能、加 lint 規則,或更新 CLAUDE.md、REVIEW.md 這類說明文件。CLAUDE.md 告訴 Claude 這個專案的技術堆疊、慣例與目標,每次審查都會載入,所以在大型程式碼庫裡要保持簡短;審查者也會標記違反其中慣例、或讓 CLAUDE.md 內容過時的變更。REVIEW.md 由程式碼擁有者撰寫,告訴審查者這部分程式碼該在意什麼,寫得好的版本通常簡短,會說明這個 repo 裡「失敗長什麼樣子」(像文件類是「它說謊」、設定類是「它導錯路」),限制瑕疵(nit)數量、列出可以跳過的路徑,並要求以具體檔案與行號作為證據,而不是憑名稱猜測。
- 每個 PR 都有一次 AI 審查:Claude 對照整個程式碼庫與 PR 自述的意圖讀這份 diff,判斷這個改動是否解決了它要解決的問題、是否符合系統設計、會不會弄壞別的東西;遇到 bug 修復,它會去追根本原因。多個代理平行找 bug,再由驗證者對每個發現投票,存活下來的發現依嚴重程度排序。
- 獨立的安全審查:與 AI 程式碼審查分開進行,兩者中任何一方留下未解決的發現,都會卡住合併。
- 風險分級核准:一個分類器決定這個變更需不需要人核准、需要一個人還是兩個人,部分高風險路徑則永遠需要人工核准。
- 合併佇列:在合併前,把變更套用到最新的主幹上再跑一次檢查。
- 合併後的漸進發布與快速回滾:新功能先藏在功能旗標(flag)後面,由 Anthropic 員工自己先用;正式發布也分「最新」與「穩定」兩個通路,穩定通路落後一步跟進;作者與 on-call 人員盯著上線狀況,旗標能快速關閉,壞掉的 build 會被回滾。
📊 PR 量翻倍,revert 反而更少
從 6 月到 9 月,Claude Code 程式碼庫合併的 PR 數量成長超過一倍,同期需要被回滾(revert)的比例卻下降超過四成。團隊公開的另一組數字是 Anthropic monorepo 每日變更量,從 5 月約 2500 筆攀升到 9 月超過 30000 筆。
💡 把人力放在只有人能解決的問題上
這套流程背後的核心邏輯,是把稀缺的人力時間,集中在真正需要人類判斷的環節,剩下能被自動化檢查住的問題,就交給一層又一層的機器審查去攔截,再用快速回滾機制接住漏網的部分。團隊也坦言,用這種方式衡量的不是「有沒有人看過程式碼」,而是「每一類風險,有沒有被對的檢查機制接住」。
🎯 實務啟示
對正在把大量程式碼產出交給 AI agent 的團隊,這套分層防線提供一個可直接參考的骨架:開 PR 前先給 AI 可執行的驗證方式、每個 PR 都跑一次獨立上下文的 AI 審查、安全審查單獨成一道關卡、用風險分類器決定人工核准的層級、合併前在最新主幹上重新驗證、上線後靠功能旗標與漸進發布搭配快速回滾收尾。其中「給 AI 一個驗證自己工作的方式」被團隊視為效果最明顯的單一槓桿,值得優先導入。
🔗 來源
- 標題:How the Claude Code team does code review
- 作者/機構:Anthropic
- 連結:https://claude.dev/blog/solving-code-review-at-anthropic/
#ClaudeCode #Anthropic #CodeReview #AIAgents #SoftwareEngineering #DevOps #CICD #EngineeringCulture #AIAssistedCoding #DeveloperProductivity
原始資料 Claude Blog · 收集於 2026-10-16
摘要原文
We've said before that Claude writes about 90 percent of Claude Code's own code. So how do we review code at the volume we produce it? Does anyone read code anymore? And if something breaks, who catches it? This post covers the code review flow on the Claude Code team and how it has evolved. From June to September, merged pull requests to Claude Code's codebase more than doubled while the share that had to be reverted fell by more than 40 percent. We didn't remove review. But we did move most of the reading to machines, optimized for human time and attention, and invested heavily in making it fast and easy to undo mistakes. RETHINKING THE PURPOSE OF CODE REVIEW When agents write code, the number of changes goes up, fast. In Anthropic's monorepo, changes landing per day went from about 2,500 in May to more than 30,000 in September this year. Claude Code lives in its own repository, separate from the monorepo, but it's seeing a lot of pressure too. When you are shipping this fast, manual, line-by-line code review is incredibly difficult if not impossible. Code review does two jobs: Find and fix issues before they ship Build shared context and codebase understanding across the team This article mainly focuses on finding and fixing issues, but we will come back to the second job near the end. We think "did a human read the code?" is an imprecise proxy for "what could go wrong with this change, and which check—automated or human—is the right one to catch it?" Asking that question also changed when review happens. Before, review was a gate at the end of the road: write the code, open a PR, wait for your colleague. Now, review runs continuously, more like spellcheck while you write. Most changes have been reviewed and fixed by Claude at least once before a human is asked to look. This catches most routine mistakes, and saves team attention for higher-level questions and scrutiny. THE SCARCE RESOURCE: HUMAN TIME AND ATTENTION We want to preserve human time and attention for issues only humans can solve and make sure automated checks catch the rest. At our current rate of change, there is still an incredible amount of work for humans to do, and our team encounters new and novel challenges almost daily. Human time covers both sides of review's cost: the time people spend reviewing, and the time they spend fixing what bad code breaks. Cutting the first doesn't help if the time just shows up in the second. So the goal is that most pull requests in the Claude Code repos (the CLI, the desktop and web apps, and the mobile apps) merge with at most one human in the loop, who can be the author, with no increase in reverts or incidents. To measure human time, we track human approvals per PR (median and 95th percentile), human comments, and how long a PR waits on a person. Revert and incident rates are the guardrail: if they rise, we haven't saved human time, we've only moved it. THE LIFE OF A CHANGE A typical change, from an engineer's laptop (or a Claude session in Slack), goes through multiple layers of code review. The life of a change png A typical Claude Code change, from the author's machine to users BEFORE THE PULL REQUEST The work is verified Claude runs the tests, build and linter; a second agent reviews the diff in a fresh context ON EVERY PULL REQUEST Required CI Lint, types, tests across platforms, build and packaging. Red blocks the merge Claude code review Agents hunt for bugs in parallel, verifiers vote on each finding, survivors ranked by severity Security review A separate pass. Open findings from either review block the merge Risk-based approval A classifier sets the tier: no person, one, or two. Some paths always need a person MERGING Merge queue Checks run again on the latest main with the change applied AFTER THE MERGE Behind a flag, used internally first Anthropic employees run it before it reaches everyone Gradual release The latest channel first; the stable channel trails it Watch, fix forward or roll back The author and on-call watch; flags turn off quickly, broken builds get reverted automated a person decides, scaled by risk recovery BEFORE THE PULL REQUEST The work is verified Claude runs the tests, build and linter; a second agent reviews the diff in a fresh context ON EVERY PULL REQUEST Required CI Lint, types, tests across platforms, build and packaging. Red blocks the merge Claude code review Agents hunt for bugs in parallel, verifiers vote on each finding, survivors ranked by severity Security review A separate pass. Open findings from either review block the merge Risk-based approval A classifier sets the tier: no person, one, or two. Some paths always need a person MERGING Merge queue Checks run again on the latest main with the change applied AFTER THE MERGE Behind a flag, used internally first Anthropic employees run it before it reaches everyone Gradual release The latest channel first; the stable channel trails it Watch, fix forward or roll back The author and on-call watch; flags turn off quickly, broken builds get reverted automated a person decides, scaled by risk recovery FIG A Most of the path is automated; a person's attention goes where the risk is LAYER BY LAYER Layers, not one gate png Six layers of checks, with rollback under them problems in verification required CI AI review security review human approval merge queue + flags fast rollback problems in verification required CI AI review security review human approval merge queue + flags fast rollback FIG B Each layer catches some problems and misses others. Few get through all of them, and rollback handles the rest. 1. The work is verified before anyone else looks Most review now happens before a PR exists. We give Claude something it can run—like tests, a build or a screenshot to compare against the design—and ask it to show the output instead of saying it's done. Then a subagent reviews the diff with fresh context. Both habits come from our best-practices guide . Before opening a PR, many of us also run a few internal skills: one hunts for bugs, one simplifies the diff, and one checks the behavior end to end. UI changes also get checked against our design guidelines. Boris Cherny, who created Claude Code, has called giving Claude a way to verify its work probably the most important thing for getting good results. He estimates it makes the final result two to three times better, and writes, "Verification looks different for each domain. It might be as simple as running a bash command, or running a test suite, or testing the app in a browser or phone simulator." When the automated reviewer keeps flagging the same thing, we fix it at the source: in the skill, with a lint rule, or with updates to instructional files such as: CLAUDE.md tells Claude what the project is: the stack, the conventions, the goals and the non-goals. Every review loads it, so in a large codebase we keep it short and point to other docs from there. The reviewer also flags code that breaks a convention in it, and changes that make a line in it out of date. REVIEW.md , written by code owners, tells the reviewer what matters in their part of the code. We check separately whether the reviewer actually follows it. The good ones are short. They say what failure looks like in that repo (for docs it's "it lies," for config it's "it misroutes"), cap the nits, list paths to skip, and ask for a file and line as evidence instead of a guess from a name. They also ask for a summary that starts with a count and says plainly when there's nothing to fix. 2. AI review on every pull request Every pull request gets a Claude review before a person looks. It reads the diff against the whole repo and the PR's stated intent, and asks: does the change solve its problem, fit the system, or break something else? On a bug fix, it looks for the root cause. The public version, Code Review for Claude Code , is now generally available on Team and Enterprise plans, and /code-review runs a lighter version locally.
由 claude-code/sonnet 自動生成