Anthropic自研版本控制系统Scion:面向AI Agent时代的工程实践
Redesigning source control at Anthropic
这是罕见的针对AI Agent规模化编码场景的基础设施深度复盘,给出了具体的架构取舍与可复用设计原则,做AI Infra或大规模研发效能的同学值得细读。
At Anthropic, coding is no longer the bottleneck to building systems or doing research. Claude is able to autonomously iterate on research loops, micro-optimize complex programs, and build new services from the ground up at a speed and scale we haven’t seen before. The bottleneck, now, is all of the developer infrastructure built for human scale: source control, builds, and CI.
在 Anthropic,编码已不再是构建系统或开展研究的瓶颈。Claude 能够自主迭代研究循环、对复杂程序进行微优化,并以我们前所未见的速度和规模从头构建新服务。如今的瓶颈,在于所有为人类规模而开发的开发者基础设施:源代码管理、构建和持续集成(CI)。
In May 2026, Anthropic averaged around 2,500 code changes merged per day; as of September, we merged over 30,000 per day. We don’t expect this rate of growth to slow down anytime soon; the latent demand for merging code is practically infinite, and every bottleneck we remove immediately leads to a further increase in the amount of code we produce.
2026 年 5 月,Anthropic 平均每天合并约 2,500 次代码变更;截至 9 月,我们每天合并超过 30,000 次。我们预计这种增长速度不会很快放缓;合并代码的潜在需求几乎是无限的,而我们消除的每一个瓶颈都会立即导致我们产生的代码量进一步增加。
Changes merged to our monorepo per day, from January to September 2026.
2026 年 1 月至 9 月期间,每日合并到我们的单体仓库(monorepo)的代码变更数量。
In order to support this growth, we built Scion, an in-house version control system, and fully migrated our monorepo from git in five months. We also built and shipped a code review surface (called Antique), code search, a rich source control IAM system, novel ways of managing and landing large amounts of reviewed code, and more, all in that same time period. In this post, we’ll focus on how we built Scion specifically. It makes for an interesting case study: Claude’s ability to write code was both what put us in this situation in the first place and how we were able to quickly build a high-quality, scalable system to deal with it.
为了支持这一增长,我们构建了自研的版本控制系统 Scion,并在五个月内将我们的单体仓库从 git 完全迁移过来。在同一时间段内,我们还构建并发布了代码审查界面(称为 Antique)、代码搜索功能、丰富的源代码管理 IAM 系统、管理和提交大量已审查代码的新方法等。本文将重点介绍我们如何构建 Scion。这是一个有趣的案例研究:Claude 编写代码的能力既是导致我们陷入当前局面的原因,也是我们能够快速构建高质量、可扩展系统以应对该问题的关键。
Growing our monorepo
扩展我们的单体仓库
Before we explore what we built, we should acknowledge how unusual our workload is. Unsurprisingly, Anthropic uses Claude to write software far more than almost any other company, so we’re often the first to see where tools built for human scale start to strain. Source control is just one example of this. While we don’t expect many organizations to have these problems in the very near term, we suspect it won’t be too long before others who use AI coding tools experience these same pressure points, which is why we wanted to share what we built and what we learned.
在我们探讨所构建的内容之前,有必要承认我们的工作负载有多么不寻常。毫不意外地,Anthropic 使用 Claude 编写软件的程度远超几乎所有其他公司,因此我们经常是第一个目睹为人类规模设计的工具开始出现瓶颈的地方。源代码管理只是其中一个例子。虽然我们不认为许多组织会在短期内遇到这些问题,但我们怀疑,其他使用 AI 编码工具的组织不久后也会面临同样的压力点,这就是我们希望分享我们所构建的内容以及所学经验的原因。
Git is a decentralized system: every clone is a complete, self-contained repository that can compute diffs, read history and blame, and check out any revision while fully offline. For the vast majority of repositories, this is the right design, and it’s a large part of why git became the standard.
Git 是一个去中心化系统:每个克隆副本都是一个完整、独立的仓库,可以计算差异、读取历史记录和 blame 信息,并在完全离线的情况下检出任何版本。对于绝大多数仓库而言,这是正确的设计,这也是 git 成为标准的重要原因之一。
As our monorepo grows, it increasingly doesn’t fit that design space. The history of our main branch alone is almost 100 GB, and a compressed working copy is over 25 GB. We perform on the order of 25 million code checkouts per day for CI, before counting developer environments, agent sandboxes, and research jobs. Fetched naively, that would be over 600 PB of git traffic per day.
随着我们的 monorepo 不断壮大,它越来越无法适应原有的设计空间。仅主分支的历史记录就接近 100 GB,压缩后的工作副本超过 25 GB。我们每天执行约 2500 万次代码检出以支持 CI,这还不包括开发者环境、代理沙箱和研究任务。如果采用朴素的方式拉取数据,每天的 git 流量将超过 600 PB。
Git offers tools for working with a slice of a repository, such as shallow clones, sparse checkouts, and promisor remotes. Beyond these, there are standard workarounds for large monorepos, like internal git mirrors and repository snapshots (seeds) kept in blob storage. We’ve used all of them—at our peak, we operated several hundred internal git mirrors to deal with the load. This bought us time, but they became harder to operate as our merge rate increased. Seeds fell further from the tip of main between refreshes, and it took more and more care to keep operations that depend on history, like diff and blame, working on partial clones.
Git 提供了用于处理仓库切片(slice)的工具,例如浅克隆(shallow clones)、稀疏检出(sparse checkouts)和承诺式远程仓库(promisor remotes)。除此之外,对于大型 monorepo 还有标准的变通方案,如内部 git 镜像以及存储在 blob 存储中的仓库快照(seeds)。我们都曾使用过这些方案——在高峰期,我们运行了数百个内部 git 镜像来应对负载。这为我们争取了时间,但随着合并率的增加,它们的运维变得越来越困难。种子文件在刷新之间与主分支顶端的距离越来越大,而维护依赖历史记录的操作(如 diff 和 blame)在部分克隆中正常工作也变得越来越需要谨慎。
The typical setup for scaling git checkouts.
扩展 git 检出的典型设置。
Taking a step back, we noticed that, like most companies, we were using git as a centralized system with one authoritative copy, but nearly all of our clients were agents and jobs that are online by definition. The properties that make git excellent for distributed, offline work were actively undermining our ability to scale as the repo grew. So we asked ourselves: if we designed source control with the fact that agents are always online in mind from the start, what would it look like?
退一步看,我们注意到,像大多数公司一样,我们将 git 用作具有单一权威副本的集中式系统,但我们几乎所有的客户端都是本质上在线的代理和任务。使 git 在分布式、离线工作中表现出色的特性,随着仓库规模的扩大,反而 actively 削弱了我们扩展的能力。于是我们问自己:如果我们从一开始就考虑到代理始终在线这一事实来设计源代码控制系统,它会是什么样子?
Principles for agent-scale source control
面向代理规模源代码控制的原则
With agentic coding, many common assumptions about how software is developed are evolving. We embraced these changes when building Scion, which allowed us to take a fundamentally different approach than git on several core principles. Source control for huge monorepos has prior art, notably Google’s Piper and Meta’s Sapling, so we were able to build Scion with their hard-won lessons in mind. Our principles are:
随着代理式编码的发展,关于软件开发方式的许多常见假设正在演变。我们在构建 Scion 时拥抱了这些变化,使我们能够在几个核心原则上采取与 git 截然不同的方法。针对超大规模 monorepo 的源代码控制已有先例, notably Google 的 Piper 和 Meta 的 Sapling,因此我们能够借鉴他们来之不易的经验教训来构建 Scion。我们的原则如下:
Clients are always online. Git assumes that clients work offline and need a complete copy of the repository. Since nearly all of our clients are agents and jobs, we designed Scion’s client and protocols around a server that is always reachable, and have clients fetch data when they need it.
客户端始终在线。Git 假设客户端可以离线工作并需要完整的仓库副本。由于我们几乎所有的客户端都是代理和任务,我们围绕一个始终可访问的服务器设计了 Scion 的客户端和协议,让客户端在需要时获取数据。
Client-server asymmetry. In git, every client is capable of being a full-fledged server. In Scion, the server answers questions about file history and blame, creates commits, performs merges and rebases, and so on. The client maintains a bounded local object cache, lays out the working copy files on disk, monitors for filesystem changes, and gives users an ergonomic way to work with the server. It can compute very little on its own but, in exchange, it requires much less data locally.
客户端-服务器不对称性。在 git 中,每个客户端都有能力成为一个功能完备的服务器。在 Scion 中,服务器负责回答有关文件历史和责任归属的问题、创建提交(commits)、执行合并(merges)和变基(rebases)等操作。客户端维护一个有界本地对象缓存,在磁盘上布局工作副本文件,监控文件系统变化,并为用户提供与服务器交互的便捷方式。它自身能进行的计算非常有限,但作为交换,它在本地所需的数据量要少得多。
A comprehensive source control service can power many novel applications. With git, a CI job or tool that needs to ask a question about the repository, such as who last changed a line or how two commits are related, has to maintain a local copy of the repo or hope that vendor-specific APIs provide the answer. With Scion, all of the source control queries the client uses are also exposed via API, so in many cases jobs don’t need a local repository at all. Many internal tools, such as our automated bisect and revert pipelines, wouldn’t be practical at scale without this cheap, programmatic access to source control.
全面的源代码控制服务可以支撑许多新颖的应用。使用 git 时,需要向仓库提问(例如谁最后修改了某一行或两个提交之间的关系如何)的 CI 作业或工具必须维护仓库的本地副本,或者指望特定厂商的 API 能提供答案。使用 Scion 时,客户端使用的所有源代码控制查询也都通过 API 暴露出来,因此在许多情况下,作业根本不需要本地仓库。如果没有这种廉价且可编程的源代码控制访问权限,许多内部工具(如我们的自动化二分查找和回退流水线)将无法大规模应用。
Everything must be horizontally scalable. At our peak, we ran several hundred git mirrors, which significantly strained capacity and no longer scaled once the repo outgrew the mirrors’ disks or memory limits. In Scion, the repository’s data is distributed, and every component is independently scalable; there is no fully materialized copy of the repo anywhere, even on the server. There is no equivalent of packfiles (git’s compressed bundles of objects), so no repository maintenance is needed.
一切必须具备水平扩展能力。在高峰期,我们运行着数百个 git 镜像,这严重限制了容量,并且一旦仓库超出镜像的磁盘或内存限制,便不再具备扩展性。在 Scion 中,仓库数据是分布式存储的,每个组件都可以独立扩展;即使是在服务器上,也不存在仓库的完全物化副本。没有类似 packfiles(git 的对象压缩包)的概念,因此无需进行仓库维护。
Commits must be cheap, incremental, and lock-free. In git, you commit locally and then push to share your work. In Scion, every commit, rebase, or merge happens on the server, so there’s nothing to push, but each of those operations needs to be fast. The cost of creating a commit and updating its downstream data structures has to scale with the size of the change, not the overall size of the repo, or the server can’t keep up. The development lifecycle in Scion discourages refs (pointers to commits, such as branches and tags), except for the main ref or release branches, because global state that every server has to agree on is a looming scaling problem.
提交必须是低成本、增量式且无锁的。在 git 中,你在本地提交,然后推送以共享你的工作。在 Scion 中,每次提交、变基或合并都在服务器上发生,因此无需推送,但这些操作都需要快速完成。创建提交及其下游数据结构更新的开销必须随变更的大小而扩展,而不是随仓库的整体大小扩展,否则服务器将跟不上节奏。Scion 的开发生命周期不鼓励使用 refs(指向提交的指针,如分支和标签),除非是主分支或发布分支,因为每个服务器都必须达成一致的全局状态是一个迫在眉睫的扩展问题。
The working copy is optional, and sparse by design. Because our monorepo is so large, and because we check out code tens of millions of times a day for CI, we wanted to avoid checkouts whenever we could. With Scion, a CI job that needs the diff between a commit and its merge base, for example, can ask the server for it. The same goes for writes: many write workloads can also skip the checkout and function entirely via API. Scion’s protocol is centered around sparse checkouts, which only contain the directories the client asks for, and virtualized checkouts, which materialize files on demand, so when a job does need files on disk, the client only pays for what it actually reads.
工作副本是可选的,并且设计上就是稀疏的。由于我们的单体仓库非常大,而且我们每天要进行数千万次的代码检出以用于持续集成(CI),因此我们希望尽可能避免进行检出操作。借助 Scion,例如,一个需要获取某个提交与其合并基础之间差异的 CI 作业,可以向服务器请求该差异。写入操作也是如此:许多写入负载也可以跳过检出,完全通过 API 进行操作。Scion 的协议围绕稀疏检出展开,稀疏检出仅包含客户端请求的目录;以及虚拟检出,后者按需生成文件,因此当作业确实需要在磁盘上获取文件时,客户端只需为其实际读取的内容付费。
How Scion works
Scion 的工作原理
It’s helpful to understand how these principles came together in practice when building Scion. These insights can apply to other source control systems or, more broadly, to other stages of the software development lifecycle.
了解在构建 Scion 的过程中这些原则是如何在实践中结合起来的,这将很有帮助。这些见解可以应用于其他源代码控制系统,或者更广泛地说,适用于软件开发生命周期的其他阶段。
Data structures
数据结构
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力