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's Python to Rust Migration: The Method, Step by Step

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:

  1. A request counts once. A shadowed copy must never count twice toward a customer's limits or bill.
  2. 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.
  3. 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.
Compare every step around the model, not only the answerOne Messages API request, with the model run once and its output replayed to Rust
Input path
1Accept or rejectA field Python allowed, refused by Rust
2Resolve settingsEach step leaves a result to compare
3Build the promptAbout a quarter matched at first
The model, once
4Claude repliesIts output is replayed to Rust
Output path
5Sort the replyText, thinking and tool calls
6Stream and count usageFor limits and billing
More differences found between the two
A 1M limit read as 200K
Stripped newlines
Missing usage fields
The risk designed against
A copy counted twiceSo a shadowed request counts once

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:

Plaintext
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        ← fingerprint

The 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.

WhoWhat it didWhat it never decided
A grouping scriptEvery 10 to 30 minutes, grouped the records by which fields differedNothing: it only alerted the coordinator to a new kind
The coordinating agentAssigned a worker agent to own each new kind and opened a thread for it in a shared Slack channelWhether a fix shipped
A worker agentOwned one kind of difference. It reproduced the difference, fixed the Rust, added a test, opened a pull request, posted its evidence and watched productionWhether its fix was good enough to merge
EngineersFollowed and steered the threads, reviewed every fix, judged bug versus deliberate change, and wrote the rulesWhich hypotheses an agent tested, or how it reproduced a bug
Agents, for memorySaved notes on decisions, searched for repeats of known mistakes, and turned review comments into proposed rulesWhich rules took effect: an engineer edited and approved them

The work ran in three loops, each one there to catch what the loop inside it missed.

Three loops: each one catches what the one inside it missesHow one kind of difference went from a record to a closed task
Inner loop · a sandbox, seconds
1Read the fingerprintStep, piece, first byte, lengths
2Reproduce itWrite a request or reply that triggers it
3Edit until they matchThen add a test that fails on the old code
The seam
4An engineer reviews the pull requestProposed fixes only, never guesses
Outer loop · production, hours or days
5DeployA test environment, then production
6Watch the fingerprintBuilds with and without the fix
7Gone after repeated checksThe task closes
Memory loop · every agent after
A ruleRead first by each new agent
A searchFor the same mistake elsewhere
A checkA test, a lint or a merge rule

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.

The inner loop on Anthropic's made-up record (an illustration)
record

build prompt · piece 2 · first diff byte 17 · python 190 bytes · rust 190 bytes

Agent · worker

Same length, different from byte 17. Guess: the same keys in a different order. Writing a request that should trigger it.

input check

piece 2 differs from byte 17 · under a second · no model call

Agent · worker

Reproduced as recorded. Editing the Rust until both prompts match.

input check

prompts match

Agent · worker

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.

The web search shortcut, after Anthropic’s Slack figure (shortened)
You · engineer · #rust-migration

Explain your next target.

Agent · coordinator

One of the largest remaining differences: the web search tool's description is missing from Rust's prompts. It is already tracked.

Agent · worker

Fix: load the description from text files Rust can read. The prompts match and the local check passes.

You · engineer

We know we have to fetch that text before we ship, so this seems like throwaway code. Abandon that PR.

memory

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.

What went wrongHow it lookedWhat caught it
Ported tests had been weakenedThe suite still passedAn audit of the ported tests: more than 100 weakened assertions
Production used cases the tests never covered, such as escaped emojiAbout 98% of tests passed, while about a quarter of inputs matchedShadowing live traffic
One bug at the start of the prompt hid older onesNearly all mismatches carried one fingerprintRegrouping after the fix, which exposed two more
An agent wrote a workaround for web searchThe prompts matched and the local verifier passedAn engineer's review at the seam
A fix passed in the sandbox but not in productionThe fingerprint stayed in the new build's recordsThe outer loop, or an alert from the coordinator
An agent guessed at what Python didAn engineer's correction: "Did you make that up yourself?"A new rule, and a search that found seven more guesses
Feedback on each guess took hours or daysEvery hypothesis needed a review and a deployA sandbox with checks that take under a second

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

WhatAs stated
API traffic growthRoughly 1,800 times, early 2024 to fall 2026
Partial rewrite (output parser in Rust)About 8% to 10% less CPU
First Rust version of the core request pathAbout a week
Integration testsAbout 700
Weakened assertions found in ported testsMore than 100
Tests passing in AprilAbout 98%
Inputs matching production24% in late April, 6.5% in early May, 99.6% by August
Grouping scriptEvery 10 to 30 minutes
Local input checkUnder a second
Review comments turned into proposed rulesAbout 60, in June
Changes merged to the Rust code per two weeksUnder 100 in April, roughly 1,000 by late June, more than 3,000 from August 10 (not all migration work)
Public traffic on RustFrom September 2026
CPU per requestAbout 70% less
Memory per requestMore than 80% less
Median time to first tokenAbout 20% lower, measured on customers' Claude Code requests

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.

Your situationYour source of "correct"What the agents act on
The behaviour can be written as rulesA rule checker, like a proof assistantThe step that does not follow
An independent test suite already covers the behaviour, as Bun's didThe tests, run against both versionsThe failing test
The old service is the only full definition of correctThe old service, shadowedA record of where the two versions differ

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

  1. 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.

  2. Audit any test an agent ported

    Compare each ported assertion against the original before you trust a green run.

  3. Make side effects happen once

    A shadowed copy must not bill, rate-limit, email or write twice.

  4. Run the unpredictable step once and replay it

    Send the same model output, or any other nondeterministic result, to both versions.

  5. Compare every step, and record only shapes

    Log the step, the piece, the first differing byte and both lengths. Leave out the content.

  6. Group records by fingerprint

    On a timer, wake an agent only for a new kind of difference, and give each kind one owner.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

Published
Category
Build
Related Articles
NotebookLM API Guide to Notebooks, Sources and Audio Overviews

NotebookLM API Guide to Notebooks, Sources and Audio Overviews

Create a Gemini Notebook from code, add a source and see which Google API can generate an Audio Overview for a personal or business workflow.Nov 26, 2026Build
Grok API: Get a Key and Make Your First Request

Grok API: Get a Key and Make Your First Request

Get a Grok API key, send the official first request, choose a model, and see how billing and rate limits work when you call Grok from code.Nov 26, 2026Build
Claude Code Skills: Where They Live and How to Add One

Claude Code Skills: Where They Live and How to Add One

Add a Claude Code skill from a copyable SKILL.md example. See which copy wins, how slash commands work, and when a team can block inline shell commands.Nov 26, 2026Build
Open WebUI: What It Is, What It Costs, and How to Start

Open WebUI: What It Is, What It Costs, and How to Start

See where team chats and documents go, how the Open WebUI License works, and how to start the interface with Docker and connect a model.Nov 26, 2026Build
Gemini CLI: Who Can Use It and How to Start

Gemini CLI: Who Can Use It and How to Start

Check which accounts still work with Gemini CLI, which models Google supports, and how to install the terminal agent or move a project to Antigravity CLI.Nov 26, 2026Build
Open Source AI Platforms in 2026: Ollama, LibreChat, Dify and 7 More

Open Source AI Platforms in 2026: Ollama, LibreChat, Dify and 7 More

Compare Ollama, LibreChat, Dify and seven more by licence, hosting effort and model costs. Choose the right layer for your company’s AI stack.Nov 26, 2026Build
Claude PR Steward

Claude PR Steward

See what Claude PR Steward does to one pull request, how to start it manually, where to cap spend, and which GitHub rules protect your merge.Nov 25, 2026Build
LibreChat: What It Is, What It Costs, and How to Start

LibreChat: What It Is, What It Costs, and How to Start

See who maintains LibreChat, which models it connects to, where conversations go, and how to get from a local Docker install to your first reply.Nov 25, 2026Build
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.