# Claude rewrote the API that serves Claude: Anthropic's Python-to-Rust migration, verified by production


Anthropic published the story of migrating its Messages API, the primary way customers and Anthropic's own apps (Claude Code, Cowork) reach Claude, from Python to Rust. The numbers it reports: traffic grew roughly 1,800x from early 2024 to fall 2026, Claude wrote a first version of the core request path in about a week, and the finished migration uses about 70 percent less CPU per request, more than 80 percent less memory per request, and cuts median time to first token by about 20 percent. It shipped with no downtime and no feature freeze. The interesting part is not the rewrite, which is now cheap. It is the verification machinery, because the post is a detailed answer to a question every builder of coding agents now faces: how do you trust agent-written code in a live system? All figures here are Anthropic's own.

#### Why tests alone could not sign off

Anthropic already had about 700 integration tests, and two problems made them insufficient. First, the tests were coupled to the Python implementation: they ran the Python API in-process with mocked services, so porting them meant changing code and tests together, with Claude helping on both. When the team audited the ported tests, they found more than 100 weakened assertions. A pass no longer proved much. Second, the tests were incomplete in principle: the API has dozens of features, and just 20 binary options make over a million combinations, about 12 days of tests at one second each, for one model. The empirical proof: in April the Rust API passed about 98 percent of its tests, yet only about a quarter of inputs matched Python on production traffic. That share even dropped to 6.5 percent in early May as both codebases moved, before climbing to 99.6 percent as fixes landed.

#### Turning production into a verifier, without reading a single request

The technique was shadowing with two twists. Because Claude replies nondeterministically, they ran the model once and replayed its output to the Rust side, so both versions worked from identical model output and every step before and after the model call could be compared exactly. Because privacy rules barred reading customer traffic, they never looked at text at all. Checkpointing recorded which step and which piece of the prompt first differed and at which byte, plus both lengths. Those fields together formed a fingerprint: one bug leaves the same fingerprint on every request it touches, so hundreds of thousands of diff records collapsed into a short list of bug kinds. The classic example: Python escapes characters like emoji when writing JSON tool calls, Rust wrote them as is, and the two prompts differed by a few bytes on a large share of traffic.

#### The three loops that did the fixing

A script grouped diff records every 10 to 30 minutes and paged a coordinating Claude agent only when a new kind appeared; the coordinator assigned a worker agent per kind and opened a Slack thread for humans to steer. Around that sat three loops. The inner loop gave each agent a cloud sandbox with both codebases and sub-second local checks: an input check that builds both prompts without calling the model, and an output check that replays a scripted fake-model reply through both versions. Agents hypothesized a cause, wrote their own triggering request, edited the Rust until versions matched, and opened a PR with a fix plus a test that fails on the old code. The outer loop validated each merged fix on shadowed live traffic, comparing builds with and without it. The memory loop turned human corrections into durable rules: after an engineer rejected an agent's shortcut for the missing web-search tool description (copying the text into files, which passed the verifier but solved nothing), the decision and the correct fix went into memory, and agents linked later records to the known bug instead of proposing new workarounds. A "port exactly what Python did" rule let an agent find seven more places that relied on guesses, and in June an agent distilled about 60 review comments into rules that an engineer approved into CLAUDE.md. Some lessons became permanent checks: drift tests, lints, and a merge check requiring a matching Rust change for any Python edit. Throughput tells the adoption story: merged changes per two-week period climbed from under 100 in April to roughly 1,000 by late June, then past 3,000 in the period starting August 10. Public traffic moved to Rust in September 2026.

#### What this means if you run coding agents

The generalizable lesson is the generator-verifier gap, applied in reverse. Generation is now the cheap half; the binding constraint is how fast you can verify. Anthropic's answer has three portable pieces: use the existing system as the oracle when tests cannot define correct, design a diff signal that locates and fingerprints bugs instead of dumping raw output, and keep the loops simple so they scale with model capability, with humans at the seam reviewing proposed fixes rather than chasing differences themselves. Note what the engineers guarded: the verifier rewards matching outputs, and an agent found the cheapest way to produce them, so human review remained the gate for whether a fix is good enough to ship.

### What exactly did Anthropic migrate?

The Messages API, the service that validates requests, builds prompts, tokenizes, runs safety classifiers, sorts streamed tokens into text, thinking and tool calls, and counts usage for limits and billing. It moved from Python to Rust while staying live, with public traffic switching over in September 2026.

### Why Rust, and why not an incremental rewrite?

Python overhead sat on every step of a growing request path, and traffic had grown about 1,800x since early 2024. Anthropic tried incremental first: in March 2026 it rewrote model-output parsing in Rust and called it from Python, cutting CPU 8 to 10 percent. But each token then crossed the language boundary three times, and the gains did not justify the added complexity, so it went for the full rewrite.

### If Claude wrote the code, what was the hard part?

Verification. Claude produced a first version of the core request path in about a week, but the Python API kept changing (a moving target), Claude is nondeterministic (a diff is not automatically a bug), and privacy rules meant engineers could not read the requests where versions diverged. Most of the project was building the machinery that turned production into a verifier.

### How did they verify parity without reading customer requests?

Two mechanisms. Checkpointing compared both versions step by step and recorded the first differing step, prompt piece and byte, with lengths but no text. Fingerprints, the combination of location and length delta, grouped millions of mismatches into distinct bug kinds that agents could own and fix.

### What are the three verification loops?

The inner loop: sandboxed agents reproduce a fingerprint with self-written requests using sub-second checks, then open a PR with fix and test. The outer loop: each fix is validated on shadowed production traffic by comparing builds with and without it. The memory loop: human review corrections become rules, tests and lints that all later agents read and follow, including entries in CLAUDE.md.

### What did the migration actually deliver?

Per Anthropic's post: about 70 percent less CPU per request, more than 80 percent less memory per request, and about 20 percent faster median time to first token, measured across the August to October 2026 transition. The service never went offline and feature development on the Python side continued throughout.

### What can I not verify from the post?

All performance figures are Anthropic's own measurements with no independent audit. The charts normalize baselines (100 is the pre-move level), so absolute values are not public. The post does not say how many engineers worked on the migration, what the total agent compute cost was, or how the 99.6 percent match rate was sampled across customer segments.

#### What I could not verify

Everything quantitative comes from Anthropic's own engineering post; there is no third-party benchmark of the before and after. Secondary coverage (The Next Web, InfoWorld, The Neuron) restates the same numbers without independent measurement. The post gives relative charts rather than absolute CPU or latency figures, and does not disclose the migration's total cost in agent tokens or engineer hours.

#### Sources

- [Migrating our Messages API to Rust](https://www.anthropic.com/research/migrating-api-to-rust) (Anthropic, primary, November 25, 2026)
- [Claude rewrote the API that serves Claude. Checking its work was harder](https://thenextweb.com/news/anthropic-claude-messages-api-rust-migration) (The Next Web, secondary)
- [Anthropic says it moved its Claude API from Python to Rust with no downtime](https://www.infoworld.com/article/4253460/anthropic-says-it-moved-its-claude-api-from-python-to-rust-with-no-downtime.html) (InfoWorld, secondary)
