Anthropic 详解 Claude Code 的 AI 代码审查流程
原题Anthropic Outlines Its AI-Powered Code Review Process for Claude Code
读前速览
Anthropic 为 Claude Code 建立了多层代码审查流程,结合自动化验证、AI 审查和基于风险的人类审批,以高效处理不断增加的 AI 生成代码。
审查前自动化验证
在提交拉取请求之前,Claude 会运行测试、构建和代码检查工具,以发现基本错误。另一个独立智能体还会在全新的上下文中审查改动,确保代码已准备好进入主要审查流程。
AI 驱动的多轮审查
多个 Claude 智能体会独立分析代码中的错误和安全问题。系统将审查轮次限制为 3 轮,以避免产生过多反馈;之后的审查只关注新增改动。
基于风险的人类审批
人工参与程度会根据改动风险进行调整。低风险更新可能无需审批,而高风险修改或涉及 CI 工作流等敏感区域的改动则始终需要人工监督。
合并后监控
合并后的改动通常会通过功能标志控制发布,并在全面上线前进行内部测试。团队会追踪事故和回滚的改动,持续改进自动化审查算法。
完整摘要
文章介绍了 Anthropic 的 Claude Code 团队如何调整代码审查策略,以适应 AI 生成代码贡献的快速增长。如今,这套流程包含早期自动化检查、多轮 AI 驱动的审查,以及基于风险分级的人类审批系统,在显著减少人工审查时间的同时维持代码质量。
Anthropic 概述了随着 AI 代理越来越多地参与其代码库,Claude Code 团队如何处理代码审查。该方法依赖多层自动验证、AI 驱动的审查以及基于风险的人工审批,旨在减少人工审查时间,同时避免增加回归问题或生产事故。Anthropic has outlined how the Claude Code team handles code reviews as AI agents increasingly contribute to its codebase. The approach relies on multiple layers of automated verification, AI-powered reviews, and risk-based human approval, aiming to reduce manual review time without increasing regressions or production incidents.
Addy Osmani、Morgan Westlee Lunt 和 Qing Wang 介绍了团队的评审流程如何随着 AI 生成代码量的增长而不断演进。从 6 月到 9 月,合并到 Claude Code 代码库的拉取请求数量增加了一倍以上,而需要回滚的更改比例则下降了 40% 以上。Addy Osmani, Morgan Westlee Lunt and Qing Wang described how the team's review process has evolved alongside the growing volume of AI-generated code. Between June and September, merged pull requests to the Claude Code repository more than doubled, while the proportion of changes requiring a revert fell by over 40%.
团队不再依赖传统的逐行审查,而是将大部分验证工作提前到开发流程中。在发起拉取请求之前,Claude 会运行测试、构建和代码检查工具,同时由另一个代理在全新的上下文中审查这些更改。Rather than relying on traditional line-by-line reviews, the team has moved much of the verification earlier in the development process. Before opening a pull request, Claude runs tests, builds, and linters, while a separate agent reviews the changes in a fresh context.
随后,每个拉取请求都会经过多项自动化检查。由 Claude 驱动的审查器会检查代码变更中可能存在的错误,多个智能体会独立调查发现的问题,再由另一组智能体进行验证。如果仍有未解决的问题,单独的安全审查也可以阻止合并。Every pull request then goes through several automated checks. Claude-powered reviewers inspect code changes for potential bugs, with multiple agents independently investigating findings before another group verifies them. A separate security review can also block a merge if unresolved issues remain.
这种方法也引发了关于软件工程、测试和质量保证之间不断演变的边界的讨论。正如一位评论者所说:This approach also raises questions about the evolving boundaries between software engineering, testing, and quality assurance. As one commenter put it:
所以现在代码审查正式等同于测试了吗?代码审查机制应该由 QA 团队负责吗?现在还有 QA 团队吗?So code review is officially synonymous with testing now? Should the code review mechanism be owned by QA team? Is there still a QA team?
是否需要人工参与取决于变更的风险。低风险修改(例如更新文档或通过功能标志控制的内部功能)可能无需人工批准。中风险变更需要一人批准,而高风险修改则需要两人批准。对特别敏感领域的变更(包括 CI 工作流)始终需要人工监督。Human involvement depends on the risk associated with a change. Low-risk modifications, such as documentation updates or internal features behind feature flags, may require no human approval. Medium-risk changes require one person, while high-risk modifications need two approvals. Changes to particularly sensitive areas, including CI workflows, always require human oversight.
团队还引入了机制,以防止自动化审查产生过多反馈。审查周期最多进行三轮,之后会要求作者重新考虑实现方案。后续审查将聚焦于新增的更改,而不是反复检查整个拉取请求。The team also introduced mechanisms to prevent automated reviews from generating excessive feedback. Review cycles are capped at three rounds before the author is asked to reconsider the implementation. Subsequent reviews focus on new changes rather than repeatedly examining the entire pull request.
These adjustments have improved review efficiency. According to Anthropic, the share of internal pull requests passing after one review and fix round increased from 65% to 78%. Meanwhile, the proportion requiring five or more rounds dropped from 8.9% to 1.5%.
Source: Cloude.dev
不过,架构决策、产品方向、高风险变更以及最终结果仍由人工审核人员负责。团队还强调,指挥 AI 智能体的人员仍须对其生成的代码负责。Human reviewers nevertheless remain responsible for architectural decisions, product direction, high-risk changes, and the final outcome. The team also emphasizes that the person directing an AI agent remains accountable for the code it produces.
Anthropic 的方法不仅限于代码审查本身。合并后的更改通常会通过功能标志控制发布,先在内部进行测试,然后逐步向用户推出。发生的事故和回滚的更改也会纳入不断扩充的评估数据集,用于衡量和改进自动化审查工具。Anthropic's approach extends beyond code review itself. Merged changes are typically released behind feature flags, tested internally, and gradually rolled out to users. Incidents and reverted changes are also incorporated into a growing evaluation dataset used to measure and improve the automated reviewers.
核心思路是围绕变更引入的风险来优化代码审查,而不是看人类亲自阅读了多少代码。随着 AI 生成的代码越来越普遍,Anthropic 的经验表明,工程团队可能需要重新思考自动化验证与人工监督之间的平衡。The central idea is to optimize code review around the risks a change introduces rather than the amount of code a human has personally read. As AI-generated code becomes more common, Anthropic's experience illustrates how engineering teams may need to rethink the balance between automated verification and human oversight.