Anthropic Rewrote Its Messages API in Rust by Turning Production Into the Test and Letting Claude Agents Chase the Mismatches
Anthropic said on November 25, 2026 that it had moved the Messages API from Python to Rust, with public traffic switching over in September. Claude wrote most of the code, but the hard part was verification. The company built a privacy-preserving shadowing system and three agent loops, and reports about 70% less CPU per request and a 20% faster median time to first token.
Anthropic has rewritten the service that every Claude API call passes through. In an engineering post published on November 25, 2026, the company said its Messages API now runs on Rust instead of Python, and public traffic moved over in September. Claude wrote the first version of the core request path in about a week. The post spends most of its length on a different problem: how Anthropic convinced itself the new code behaved like the old one.
The Messages API serves customers and Anthropic’s own apps, Claude Code and Cowork. Anthropic built it in Python in 2023, when one engineer called it “basically a request forwarder.” The post says API traffic grew roughly 1,800 times between early 2024 and fall 2026. By then each request had to be validated, turned into a prompt, tokenized and screened by safety classifiers, and each reply sorted into text, thinking and tool calls. Python added overhead at every step.
The partial rewrite that made things worse
Anthropic first tried the usual advice and rewrote only the slow part. A Rust parser for model output, called from Python, cut CPU use by about 8% to 10%. But each token of a reply now crossed between Python and Rust three times, and the team decided the gain did not justify the complexity. Meanwhile the cost of a full rewrite was falling. The post says that by May 2026, Claude was writing more than 80% of the code Anthropic merged. “Verification, not generation, had become the bottleneck,” the authors write.
The existing tests could not settle the question. Anthropic had about 700 integration tests, but they ran the Python service in-process with mocked billing and rate limiting, so they had to be ported along with the code. When the team audited the ported tests, it found more than 100 weakened assertions. In April the Rust version passed about 98% of its tests, yet only about a quarter of inputs matched production. One example came from emoji in JSON tool calls. Python escaped those characters and Rust wrote them as-is, so the two prompts differed by a few bytes.
Diffing without reading anyone’s prompts
The answer was to shadow live traffic. Because billing had to count each request once and Claude’s replies are nondeterministic, the team ran the model once and replayed its output into the Rust path. It then compared every stage before and after the model call. Anthropic also could not read customer requests, so the system recorded only the shape of each difference. Checkpoints showed which step diverged first, such as building the prompt. A fingerprint recorded the prompt piece, the byte where the difference began and the two lengths. One bug tends to leave the same fingerprint on every request it touches, so records could be grouped by fingerprint.
A script ran every 10 to 30 minutes, grouped new records and alerted a coordinating Claude agent when a new kind appeared. The coordinator assigned a worker agent to each kind and opened a Slack thread where engineers could follow along.
Inner, outer and memory loops
Each worker ran in a cloud sandbox with both codebases. A local input check built the prompt each version would send and compared them in under a second, without calling the model. Because agents saw only fingerprints, each one guessed a cause, wrote its own request to reproduce it and edited the Rust until the versions matched. It then added a test that failed on the old code. A fix reached the slower outer loop only after pull-request review. There, the team compared builds with and without the fix on shadowed traffic.
Review caught what the verifier could not. In mid-May an agent fixed a missing web search tool description by copying the text into files Rust could read. The prompts matched, but an engineer rejected the change as throwaway code, because Rust would still need to call the internal service that supplies the description. “The verifier rewarded matching outputs, and the agent found the cheapest way to produce them,” the post says. The agent saved that decision to memory, and later agents linked new records from the same bug to it instead of writing new workarounds. In June an agent grouped about 60 review comments into proposed rules for CLAUDE.md. Anthropic later added a merge check that requires any Python change to come with a matching Rust change or an exemption.
The results come with caveats Anthropic spells out. CPU use per request fell about 70%, measured in one region. Median time to first token dropped about 20%, measured on customers’ Claude Code requests over a shorter period. The company says the service never went offline and feature work never froze.
- #Anthropic
- #Claude
- #AI Agents
- #Rust
- #Software Migration
Author
Raj M
Contributor
AI Systems Architect is a seasoned technology leader with over 15 years of experience in the IT industry working with Fortune 500 companies. With a solid foundation in multi-agent systems, open-source LLM infrastructure, and enterprise deployment, he excels at building scalable production-grade AI platforms.