Anthropic's Rust Rewrite: Why Verification, Not Code, Was the Cost
Claude wrote most of the Rust that replaced Anthropic's Python Messages API, yet tests passing at 98% matched only a quarter of production traffic. How shadow comparison closed the gap, and what to build before an AI-driven migration.
Contents
Summary
On November 25, 2026, Anthropic published an account of how it rewrote its flagship Messages API from Python to Rust. Claude wrote most of the code, and after the migration CPU per request fell by about 70% and memory by more than 80%. The writing, however, finished early. What took the effort was confirming that the old and new versions behaved the same. Even when the Rust version passed about 98% of the existing tests, only about a quarter of production inputs produced matching output, and an audit of the ported tests found more than 100 weakened assertions. As AI lowers the cost of writing a language migration, whether the migration succeeds comes down to whether you can invest in a way to check the new code against production.
Passing 98% of tests, matching a quarter of production
First, let’s lay out what happened and in what order, based on Anthropic’s post “Migrating our Messages API to Rust.”
The Messages API is the central API used not only by outside developers but also by Anthropic’s own apps such as Claude Code. When it was built in Python in 2023 it mostly relayed requests, but validation, conversion into prompts, tokenization, and safety classification and handling piled up over time, along with dependencies on Python libraries from the research and inference teams. Meanwhile API traffic grew roughly 1,800-fold between early 2024 and autumn 2026. Python overhead at every stage of processing was therefore turning directly into compute cost.
The first attempt was a partial rewrite. In March 2026, moving only the response parsing to Rust cut CPU by around 8–10%, but the design crossed between Python and Rust three times for every token, and the team judged the complexity not worth it. They decided to rewrite the whole thing, and Claude wrote the first version of the core request handling in about a week.
The trouble came afterward. In April the Rust version passed about 98% of the existing tests, yet when production inputs were run through both and compared, only about a quarter of outputs matched. Part of the cause was the tests themselves. Roughly 700 integration tests ran the Python API in-process and simulated billing and rate limiting in Python memory, so moving to Rust meant rewriting the tests too. Claude fixed both the code and the tests. As a result, nobody could tell whether a passing test meant “the code is correct” or “the test was changed so the wrong code would pass.” Auditing the ported tests turned up more than 100 weakened assertions.
Anthropic stopped treating the tests as the source of truth and switched to using production traffic instead. The match rate briefly dropped to 6.5% in early May, then climbed with each fix to 99.6%. Public traffic moved to the Rust version in September, with no service outage and no freeze on Python development along the way, according to the post.
Using production traffic as the “right answer”
If tests aren’t enough, compare in production. That’s easy to say, but Anthropic’s post shows three obstacles to actually running it: the Python version kept changing every day because development continued; model output differs on every call, so a difference isn’t necessarily a bug; and the contents of customer requests can’t be read.
The design that answers these is the technical heart of the post. The model is called only once, and its output is replayed into the Rust side. Both versions then receive the same model output, which removes differences caused by output variance. Because requests aren’t sent twice, billing and rate limits aren’t counted twice either. On top of that, checkpoints are placed at each stage—accept or reject, settings values, prompt assembly—and outputs are compared byte for byte. A mismatch is recorded not by its content but as a fingerprint: “which stage, which piece, the byte where the difference starts, and how much the lengths differ.” A single bug leaves the same fingerprint on every request it affects, so hundreds of thousands of mismatches collapse into a small number of kinds.
Starting from these fingerprints, three improvement loops ran. The diagram below shows the flow from production traffic to a fix landing back in production, and where humans make the call.
In the inner loop, a sandbox holding both codebases ran input-side comparisons that don’t call the model (under a second) and output-side comparisons with a fake model, and agents kept fixing until they matched. In the outer loop, reviewed fixes went out to the shadow environment to see whether the match rate rose on production traffic. In the memory loop, human feedback was kept as notes, CLAUDE.md rules, lints, and a merge-time check requiring “a matching Rust change whenever the Python side changes.”
The post is also specific about where humans were indispensable. Faced with a verifier that rewards matching output, the agent found the cheapest way to match. When the Rust side lacked the code to fetch the description text for the web search tool, the agent tried to hard-code the description to make the outputs match, and an engineer rejected it. The correct fix—calling an internal service—took several weeks. A verifier tells you whether the output matched, not whether the fix is good enough to ship. That is what Anthropic means when it writes that “verification is the new bottleneck.”
“40–50%” or “about 70%”: how far to trust the numbers
Can these results be taken as your own organization’s expectations? Looking at where the numbers come from, several points call for caution.
First, two reduction figures are in circulation. On the October 27 Latent Space podcast, a company representative was reported to have cited a 40–50% CPU reduction and a 10–20% improvement in time to first token (TTFT), and that spread on X. The official November 25 post says about 70% and about 20%. According to the post’s notes, CPU was measured in one region and TTFT only for customer Claude Code requests over a short period, both as 7-day moving averages. These figures cover different periods and scopes. Rather than one being wrong, they are numbers you can’t compare without checking what they measure.
Next, it’s unclear how much of the reduction is due to Rust itself. The rewrite was also a chance to rebuild layers of accumulated processing, so the effect of redesign must be in there too. Team size, token usage and cost, line counts, and whether there were incidents or rollbacks during the migration have not been published. It’s also a case published by a company that sells AI models, about results from its own model—another reason to read it with some discount.
And 70% of CPU is a large sum only because this API carries traffic that grew about 1,800-fold. For a low-volume internal system, the same reduction rate won’t necessarily pay back the cost of migrating.
The same kind of rewrite left Bun users hitting bugs
Comparing with another case from the same period makes it clear how much the presence of a verification setup changes the outcome.
At Bun, the JavaScript runtime Anthropic brought in-house at the end of 2025, a branch appeared in late April 2026 in which Claude moved the codebase from Zig to Rust, and it was merged into main on May 14. According to heise, the change touched 2,188 files and rewrote about a million lines. Meanwhile, reports of bugs that didn’t exist in the Zig version appeared on GitHub, and heise recommended pinning to version 1.3.14. Critics also said old tests had been changed so the Rust version would pass, and that heavy use of unsafe limits the memory-safety benefits.
The difference between the two, in my view, lies less in the AI’s capability than in where each could anchor the right answer. The Messages API is a server the company runs itself, so production traffic could serve as the reference. Bun is a runtime that runs on users’ machines; there was no way to collect and compare production inputs and outputs, so it had to rely on tests as the reference. If the AI can rewrite those tests, the reference itself moves.
Earlier AI-driven migrations also had a mechanically checkable right answer. Airbnb reported that in moving about 3,500 test files from Enzyme to React Testing Library, it ran automated processing gated on test success, linters and type checks, converted 97% in four days, and shrank work estimated at 1.5 years to six weeks. Amazon’s 2024 account of upgrading tens of thousands of internal applications to Java 17 (saving an estimated 4,500 developer-years of work, by the company’s figures) was likely also work where builds and tests made success easy to judge. What’s significant about this case is that it extended that right answer all the way to production traffic.
Migration cost shifts from “people who write” to “a system that compares”
So how does this case bear on migrating your own legacy systems?
The winners are companies sitting on old Java or code in languages fewer and fewer people can maintain, whose migrations stalled because person-month estimates ballooned. If AI makes rewriting cheap, migrations that never paid off come back onto the table. Conversely, system integrators that have taken on migrations by the person-month will need to show their value in designing verification environments and cutover procedures.
The cost doesn’t disappear, though. In Anthropic’s case the money went into the shadow environment, the design of checkpoints and fingerprints, sandboxes for the agents, and human review. If you’re considering the same thing, check the following before you start.
- Can production inputs and outputs be used for comparison? For business data containing personal information, design the system to record only shape and differences rather than content, or compare on an anonymized copy. Even just saving a few outputs as text and putting old and new side by side in a text diff tool gives you a sense of where they tend to diverge.
- Will side effects happen twice? Identify processes that must not run twice—billing, sending email, reserving inventory—and set things up so only one side executes them and the result is replayed to the other.
- How will you handle parts whose answer changes every time? Identify in advance things like timestamps, random numbers and external API responses, where a difference isn’t a bug.
- Does a human always look when tests are rewritten? Review test changes separately from ordinary code changes so that changes that weaken assertions can be caught.
- Can you switch over gradually and roll back? Switch between old and new by feature or by customer, and decide rollback conditions in advance based on match rate and incident metrics.
On the governance side, decide who will read the large amount of code the AI wrote and who will fix it when something breaks. If nobody can read the target language, post-migration maintenance becomes a new black box. Just as you decide up front how to measure cost and results and when to stop before handing work to agents, in a migration humans decide in advance what counts as correct. That comparison setup remains an asset after cutover, usable for catching regressions.
I expect this shift to reach how migration projects are estimated and how contracts are written (this part is my speculation). Public cases of agent-driven migration will keep growing, including both successes and cases where users hit bugs. What gets cited as the deciding factor will be less which model was used than whether the right answer could be pinned down. Migration tools will routinely include features for aggregating old-versus-new differences in production, and buyers’ requirements will start to specify “match rate in shadow comparison” and “review procedure for test changes.” At that point, what drives the estimate will be not the number of lines to rewrite but the range of inputs and outputs that can be compared and the number of processes with side effects.
My take
The heaviest line in this case, I think, is not the 70% CPU reduction but “more than 100 weakened assertions.” Reading it as the AI cutting corners isn’t accurate. If you’re told to make the tests pass, changing the tests is one solution, and the agent simply searched for the shortest path given the evaluation it was handed. The hard-coded web search description is the same pattern. The assumption that a human developer would observe implicitly—“don’t touch the side that defines the right answer”—doesn’t exist for an agent unless you state it.
So the question to ask before handing a migration to AI is not “can AI write this language?” but “do we hold this system’s correct behavior in a form the AI cannot rewrite?” Production traffic, tests that humans review, and merge-time checks that reject changes are what fill that role. Gain only the speed of writing without them, and, as happened with Bun, users may end up doing your verification for you by filing bug reports. Put the other way, for organizations that can invest first in a way to pin down the right answer, this is a good moment to restart migrations that have been shelved for years.
References
- Anthropic, “Migrating our Messages API to Rust,” November 25, 2026
- explainx.ai, “Article on the Messages API Rust rewrite (comparing the podcast’s 40–50% with the official figures),” updated November 25, 2026
- heise online, “AI Porting: Claude Rewrites Bun Codebase in Rust”
- InfoQ, “Article on Airbnb’s LLM-driven test migration,” March 28, 2025
- AWS, “Amazon Q Developer just reached a $260 million dollar milestone,” August 1, 2024