Anthropic's Python to Rust Migration: The Method, Step by Step
How Anthropic moved its Messages API from Python to Rust: the old service as the check, Claude agents fixing each difference, and a checklist to copy.
Published

Anthropic has moved its Messages API, the main way customers and its own apps reach Claude, from Python to Rust. Claude wrote the first version of the core request path in about a week. Proving that the new service behaved like the old one was the hard part. This is the method from Anthropic's post of November 25, 2026, as steps a team can copy, followed by what the post leaves out.
What Anthropic migrated, and why
The Messages API is, in the post's words, "the primary way that customers–as well as our own apps, like Claude Code and Cowork–reach Claude." Anthropic built it in Python in 2023, when one engineer called it "basically a request forwarder." Over time it came to share dependencies with Python libraries owned by the research and inference teams. Moving it to another language "would mean building logging, metrics, and tools all over again."
By late 2025 the work done on each request had grown. It had to be validated, converted into the prompt, tokenized and screened by safety classifiers. The reply's stream of tokens had to be sorted into text, thinking and tool calls. Python added overhead to every one of those steps. Traffic grew roughly 1,800 times between early 2024 and fall 2026. "Rust would allow us to use far less CPU per request."
Anthropic tried the standard advice first and rewrote only the slow part. As of March 2026 the code that parses a model's output ran in Rust and was called from Python. CPU use fell by about 8% to 10%. Each token of a reply now crossed between Python and Rust three times, though, and "the gains didn't justify the added complexity."
The case for a full rewrite changed because the effort of writing code was dropping fast. By May 2026, Claude was writing more than 80% of the code Anthropic merged. The open question was how to trust the result. Three things made that hard:
- Parity was a moving target. The Python API kept changing throughout the migration, as new models and features shipped.
- The same request can get a different reply. Claude is nondeterministic, so two outputs that differ do not prove a bug.
- Nobody could read the traffic. Anthropic couldn't read customer requests, so it could not simply look at where the two versions diverged.
The finished Rust API uses about 70% less CPU and more than 80% less memory per request. Median time to first token is down about 20%. The service was never taken offline, and feature development never froze. Public traffic moved to Rust in September 2026.
Why the test suite could not be the judge
Anthropic had about 700 integration tests, and two things kept them from settling the question.
The tests were tied to the Python code. They ran the Python API inside the test's own process and mocked services such as billing and rate limiting in Python's memory. Porting the API meant porting the tests, and "Claude helped with both." A passing test could then mean the code was right, or that the test had been changed to let wrong code through. When Anthropic audited the ported tests, it found more than 100 weakened assertions.
The tests were incomplete. The API has dozens of features. Just 20 on-off options make over a million combinations, which would take 12 days to run at one second each, for one model, before the prompts inside them vary at all.
The gap showed in April. The Rust API passed about 98% of its tests, while only about a quarter of inputs matched on production traffic. One cause was small. When Python writes a JSON tool call, it replaces certain characters, such as an emoji, with text codes, and Rust wrote them as they were. The two prompts differed by a few bytes, and the model still answered. Live traffic also weighs bugs differently from a test suite. A test counts each case once, but a common bug shows up on every request that triggers it.
How the old service became the check
The post names three common sources of "correct". You can write a rule that a proof assistant such as Lean checks. You can use examples, as Bun did when it moved from Zig to Rust: its test suite was written in TypeScript, so the same tests could judge both versions. Or the existing system can serve as the oracle. Anthropic chose the third.
Running the same requests through old and new code and comparing the results is called shadowing. Anthropic notes that common shadowing tools, GitHub's Scientist among those it links, often assume that a request can safely run twice, or that a service is deterministic. Neither assumption held here, so Anthropic worked to three rules:
- A request counts once. A shadowed copy must never count twice toward a customer's limits or bill.
- The model runs once. Anthropic ran the model once and replayed its output to Rust, so both versions worked from the same reply. Diff tools often run the old code twice, learn what varies on its own and ignore it. Every Claude reply varies, so those tools would have ignored the replies along with any bugs in them.
- Every step must match exactly. Claude accepts almost any prompt, so a small deviation can change the answer without raising an error. Anthropic compared each step before and after the model call.
As of Nov 26, 2026 · Source: Anthropic, Migrating our Messages API to Rust
Record the shape of a difference, never its text
Because no one could read the requests or the replies, Anthropic recorded the shape of each difference rather than its content. It did that in two ways.
Checkpoints. Both versions handle a request in the same steps, and each step leaves a result that can be compared. The prompt is compared piece by piece. The first step to differ shows roughly where the Rust code departs from the Python.
Fingerprints. For each difference, the record also keeps where it began in the prompt and how far apart the two lengths are. Combined with the step and the piece, that is a fingerprint, and one bug tends to leave the same fingerprint on every request it affects. Records can then be grouped by bug. This also exposed hidden bugs. In one kind of request, a bug at the very start of the prompt accounted for nearly all mismatches. Once it was fixed, two older differences appeared behind it.
This is the record Anthropic shows, with its own made-up values:
step: build prompt ← where in the code
piece: 2 ← where in the prompt
first diff: byte 17 ← fingerprint
python: 190 bytes ← fingerprint
rust: 190 bytes ← fingerprintThe record holds no text, so it can go straight to an agent.
How the agents were organised
One bug could produce hundreds of thousands of nearly identical records. Anthropic sent agents kinds of difference, never single records.
The work ran in three loops, each one there to catch what the loop inside it missed.
As of Nov 26, 2026 · Source: Anthropic, Migrating our Messages API to Rust
The inner loop: a sandbox with both codebases
In April, the first version of this loop was slow. An agent guessed the cause from the code and opened a pull request. The fix had to be reviewed, merged and deployed to staging before anyone could tell whether the difference was gone. Each guess took hours or days.
Anthropic moved each agent into its own cloud sandbox holding both codebases and two fast local checks:
- The input check takes a request and builds the prompt each version would send to the model, then shows what differs. It never calls the model, so a comparison takes under a second.
- The output check runs both versions against a fake model. It passes a scripted reply, such as a tool call, through each one and compares the results.
The agent sees only the fingerprint, never the request behind it, so it has to recreate the bug. It forms a hypothesis and writes its own request or model reply that should trigger the difference. Because it wrote that input itself, it can read both results in full. If they match, the guess was wrong and it tries again. If they differ in the way the record described, it edits the Rust until the two versions match. It then adds a test that fails on the old code and passes on the new, and opens a pull request.
build prompt · piece 2 · first diff byte 17 · python 190 bytes · rust 190 bytes
Same length, different from byte 17. Guess: the same keys in a different order. Writing a request that should trigger it.
piece 2 differs from byte 17 · under a second · no model call
Reproduced as recorded. Editing the Rust until both prompts match.
prompts match
Added a test that fails on the old code and passes on the new. Opening a pull request.
The seam: what people reviewed and decided
A fix crossed from the sandbox to production only after review of its pull request. That put engineers where their time counted. They read proposed fixes rather than guesses, and they answered the questions a verifier can't, such as whether a difference was a bug or a deliberate change. Agents posted their fixes and evidence to their Slack threads.
The case Anthropic tells in detail came in mid-May. One of the largest remaining differences came from web search. The Python API fetched the web search tool's description from an internal service, and the Rust API did not call that service yet, so the description was missing from Rust's prompts. An agent proposed copying the text into files Rust could read. The prompts matched, and the local verifier passed. An engineer turned it down anyway.
Explain your next target.
One of the largest remaining differences: the web search tool's description is missing from Rust's prompts. It is already tracked.
Fix: load the description from text files Rust can read. The prompts match and the local check passes.
We know we have to fetch that text before we ship, so this seems like throwaway code. Abandon that PR.
note saved · the decision, the reason, the right fix: Rust calls the service that supplies tool descriptions
Anthropic's own lesson from it: "A verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship." The verifier rewarded matching outputs, and the agent had found the cheapest way to produce them. That is the reason a person stood at the seam.
The outer loop: is it gone in production?
Once an engineer approved a fix, it merged and deployed to a test environment, then to production. To keep the before-and-after comparison fair, Anthropic logged facts about each compared request without its text: the model, and features such as prompt caching, tools or extended thinking. Agents could then compare requests of the same kind on builds with and without the fix, and count how often the fingerprint still appeared.
The sandbox simulated production quickly but imperfectly. Agents tested only requests they had written, and the local verifier was not always configured exactly like production. So a fix sometimes passed in the sandbox while production still showed the difference. The worker saw it in the new build's records or was alerted by the coordinator, and went back to the inner loop with that evidence. When repeated checks found the fingerprint gone, the task closed. If the fingerprint came back, so did its thread.
The memory loop: never make the same correction twice
The first two loops fixed one difference at a time. The memory loop changed how every later agent worked, in four ways:
- Notes on decisions. After the web search rejection, the agent saved a note with the decision, the reason and the correct fix. Building the real service call took the team weeks, and the bug kept producing records in the meantime, some with new fingerprints. Agents checked the note, recognised the known bug and linked those records to it instead of writing another workaround.
- Rules from corrections. After one agent guessed at Python's behaviour, an engineer made it a rule to port exactly what Python did. Another agent then compared the existing code against that rule and found seven more places where the port relied on a guess.
- Rules from reviews. In June, an agent went through about 60 of the team's review comments and grouped the recurring problems. It proposed rules, which an engineer edited and approved for CLAUDE.md.
- Permanent checks. New tests failed when Rust drifted from Python, and lints banned patterns that reviewers kept flagging. Later, a merge check required anyone changing the Python code to make the matching change in Rust or request an exemption.
What went wrong, and what caught it
The post names these failures, and what caught each one.
The daily match rate started at 24% in late April and dropped to 6.5% in early May. It then climbed as fixes rolled out, with two falls caused by changes on the Rust side, and reached 99.6% by August. The comparison started on Anthropic's own traffic before moving to a wider sample.
The numbers, as the post states them
What the post does not say
As of November 2026, Anthropic's post does not give:
- The cost. It gives no token, compute or dollar figure for the agents, the sandboxes or the shadow system.
- The team size. It does not say how many engineers worked on the migration or how many agents ran at once.
- The model or the harness. It says "Claude agents" and "a cloud sandbox." The one product it links for the rules is the CLAUDE.md documentation.
- The size of the job. It does not say how large the codebase is, or how many distinct bugs or fingerprints were fixed.
- The rollout. It says traffic moved "a few at a time" once the two versions behaved the same. It gives no percentages, no schedule and no account of customer-facing incidents.
- The code. It publishes nothing for the shadow system, the grouping script or the sandbox checks.
A team planning its own migration has to estimate those parts itself.
Should your team try this?
The method fits a particular kind of system. Choose your source of correctness before you choose your agents.
Anthropic's case had all the hard parts: a live system, a codebase that kept changing, a nondeterministic step, side effects tied to money, and traffic no one could read. Each one your service lacks is a part you can leave out. With no model in the path there is nothing to replay. With no billing or other side effect there is no count-once rule. With readable traffic, an agent can read the request behind a record instead of recreating it.
A checklist for a small service
Name what counts as correct
A rule, an independent test suite, or the old service. If it is the old service, keep it running and shadow it.
Audit any test an agent ported
Compare each ported assertion against the original before you trust a green run.
Make side effects happen once
A shadowed copy must not bill, rate-limit, email or write twice.
Run the unpredictable step once and replay it
Send the same model output, or any other nondeterministic result, to both versions.
Compare every step, and record only shapes
Log the step, the piece, the first differing byte and both lengths. Leave out the content.
Group records by fingerprint
On a timer, wake an agent only for a new kind of difference, and give each kind one owner.
Give agents a fast sandbox
Both codebases and a local check that takes seconds. A fix has to come with a test that fails on the old code and passes on the new.
Review every fix before production
Ask whether the fix is real or only makes the outputs match, and whether the difference was a bug or a deliberate change.
Close a task only when production agrees
Compare builds with and without the fix on requests of the same kind, and reopen the task if the fingerprint returns.
Turn every correction into a rule and a check
A line in CLAUDE.md, a search for the same mistake, and a test or lint. Add a merge check that makes a change to the old code carry over to the new.
Did Claude write the Rust version of the Messages API?
Claude wrote a first version of the core request path in about a week, according to Anthropic's post. Teams of Claude agents then found and fixed the differences from the Python service. Engineers reviewed every fix before it reached production.
How long did Anthropic's Python to Rust migration take?
The post gives dates rather than a total. The partial rewrite ran in March 2026, shadow comparison began in April, inputs matched at 99.6% by August, and public traffic moved to Rust in September 2026.
Was the API taken offline during the migration?
No. Anthropic says it shipped the Rust API without ever taking the service offline or freezing feature development.
How much did the migration cost?
The post does not say. It gives no figure for tokens, compute or people.
Can I copy this without reading my users' data?
That is how Anthropic did it. The records it compared held where a difference was and how big it was, never the text. Agents reproduced each bug with requests they wrote themselves.
Where to go next
The seam in this method is a pull request, and a person reads it. If agents will be opening fixes at this rate, the reviewer's tooling comes first.
Best AI code review tools for small teams
What each reviewer catches on a pull request, and what it costs at 5, 20 and 50 developers.
Claude Approvals: who has to sign off on a pull request?
Put the human gate at the seam in a policy file, and keep branch protection in force.
Claude Ship
Code Review, PR Steward and Approvals: the agents that take a pull request from finding to fix.
Always-on agents
An agent that sleeps, wakes on an event, does one short run and saves what it learned, like the coordinator here.
Claude Code GitHub Actions
Ask Claude for a pull request review or a small fix from GitHub, with a person deciding what merges.
- Published
- Category
- Build







