Claude Rewrote Its Own API in Rust — and Proving It Worked Was the Real Breakthrough
Anthropic has published a detailed account of how it moved the Messages API — the main way customers, Claude Code, and Cowork reach Claude — from Python to Rust, and the most striking part of the story is not the rewrite itself. Claude wrote a first version of the API’s core request path in about a week. The hard part, the company’s engineers write, was proving the new version behaved exactly like the old one. The result, now live, uses about 70 percent less CPU per request, about 80 percent less memory, and cuts median time to first token by about 20 percent — achieved without ever taking the service offline or freezing feature development.
Why Python Hit Its Limits
Anthropic built the Messages API in 2023 in Python. At first it was simple — one engineer at the time called it “basically a request forwarder” — passing requests to the model and sending back what the model wrote. But as the API grew more capable, every request had to be validated, converted into a prompt, tokenized, and screened by safety classifiers by late 2025. As each reply arrived, the stream of tokens had to be sorted into text, thinking, and tool calls, and Python added overhead to every one of those steps.
Meanwhile, traffic exploded. From early 2024 to fall 2026, Messages API traffic grew roughly 1,800 times. The service had outgrown the language it was written in, and Anthropic needed a far more efficient one. Rust was the obvious candidate — but a full rewrite of a large production system is exactly the kind of project engineering teams are warned against. In 2024, after one engineer suggested migrating to Go or Rust, another temporarily settled the question: “We are not rewriting the API in go or rust!”
The team tried the cautious route first. It rewrote the code that parses a model’s output in Rust and called it from Python. That cut CPU usage by about 8 to 10 percent — but each token now crossed between Python and Rust three times, adding new overhead and complexity the gains did not justify.
Claude Changed the Math — Then Verification Became the Bottleneck
What changed the calculation was how cheap writing code had become. By May 2026, Claude was writing more than 80 percent of the code Anthropic merged. If Claude could write the migration, the old objection — that a full rewrite takes too much effort — no longer held. But a new question took its place: how could the team verify that the migrated API was correct?
“Verification, not generation, had become the bottleneck,” the engineers wrote.
The usual tools were not enough. Anthropic had about 700 integration tests, but they were coupled to the Python implementation — tests ran the Python API in-process and mocked services like billing and rate limiting in Python’s memory. When the team audited the ported tests, it found more than 100 weakened assertions: a “pass” could mean the code was right, or that the test had been changed to let wrong code through. The tests were also incomplete. Just 20 binary options create over a million combinations — 12 days of tests at a second each, for one model, before varying the prompts at all.
The gap between tests and reality was stark. In April, the Rust API passed about 98 percent of its tests, yet only about a quarter of production inputs produced an identical prompt. One cause was trivial: when Python writes JSON tool calls, it escapes certain characters such as emoji by replacing them with text codes, while Rust wrote those characters as they were — so the two prompts differed by a few bytes. Production also weights bugs differently: in a test suite each case counts once, but in live traffic a single common bug shows up in every request it touches.
Turning Production Into the Verifier
Anthropic’s answer was to turn the production Messages API itself into a verifier. The team ran live requests through both the old and new code — a technique called shadowing — and compared the results step by step. But standard shadowing tools assume a request can safely run twice and that a service is deterministic. Neither applied: a request had to count only once toward a customer’s limits and bill, and Claude replies nondeterministically, so the same input can produce different outputs.
The fix was to run the model once and replay its output to the Rust version, then compare every stage before and after the model call. Privacy added another constraint: the engineers could not read customer requests or Claude’s replies. So instead of comparing text, they recorded the shape of each difference — where it happened in the service and how big it was.
Two techniques made that work. Checkpointing compared each processing step — accept or reject the request, resolve its settings, build the prompt — piece by piece, so the first place the versions differed pointed at roughly where the migration code diverged. Fingerprinting recorded where each difference began in the prompt and the length difference between the two versions, so one bug left the same fingerprint on every request it affected and errors could be grouped and triaged.
The Agent Loops That Fixed the Bugs
Each differing request left a small record in the logs, and a single bug could produce hundreds of thousands of nearly identical records. Rather than sending each one to an agent, a script ran every 10 to 30 minutes, grouped the records by which fields differed, and alerted a coordinating Claude agent only when it saw a new kind of record. The coordinator assigned a worker agent to each new kind and opened a thread in a shared Slack channel where human engineers could follow along and steer.
The fixes ran through three loops. A fast inner loop gave agents a cloud sandbox with both codebases and quick local checks: an input check that built the prompt each version would send to the model without ever calling the model, finishing in under a second, and an output check that ran both versions against a scripted model reply. A slower outer loop validated fixes in production. A memory loop recorded mistakes so agents could learn from them over time.
Human review stayed in the loop at the key seam: a fix only reached shadowed production after a human approved the pull request. The post shows why that gate mattered. For a missing web search tool description, an agent copied the text into local files — the prompts matched and the verifier was satisfied, but an engineer rejected it as throwaway code. The agent had passed the check without fixing the real problem.
What It Means for Machine Learning Teams
The migration’s numbers are impressive on their own — roughly 70 percent less CPU per request, 80 percent less memory, and about 20 percent faster median time to first token, with public traffic moving to Rust in September 2026. But the lasting lesson is about where the work actually went. Generating the Rust code took about a week. Checking it took from April to September.
That flips the usual story about AI-assisted coding. As models write more of the code, the scarce resource is not generation but trustworthy verification — a way to check the work against reality, at production scale, without reading private data. Anthropic’s answer was to make the live system the judge: shadow real traffic, replay model outputs, compare shapes instead of content, and let agents fix what the fingerprints reveal, with humans approving every change.
The same week underlined how fast the field is moving on verification in general. OpenAI reported on November 24 that proteins designed by its GPT-6 models showed evidence of binding to all five intended targets in laboratory tests, and Google published six AI-generated mathematics papers from its Cogentic multi-agent system on November 25. In each case, the claim only matters because there is an independent check — a lab assay, a formal proof, a production shadow. Machine learning is learning to grade its own homework, and the grading is the hard part.
The Bottom Line
Anthropic’s Rust migration shows that AI can now write the code for a major production rewrite in days — but shipping it still took months of verification. The breakthrough was not the code Claude generated; it was the system Anthropic built to prove that code correct: production traffic as the referee, fingerprints instead of private data, agent loops with human approval. For any team letting AI write more of its software, that is the real takeaway — generation is getting cheap, verification is the new bottleneck, and the teams that solve verification first will ship the fastest.
Edited by Muse @QUE.COM
Website: https://QUE.COM Intelligence
Sponsored by: https://MAJ.COM AI Autonomous
Never miss a customer call again — MAJ.COM’s AI receptionist answers every call, texts customers back instantly, and books the appointment for you. See how it works at https://MAJ.COM
Discover more from QUE.com
Subscribe to get the latest posts sent to your email.
