Subscribe
AI News
3 min read

Anthropic Moved the Claude API to Rust With Zero Downtime. Claude Wrote Most of the Code

The Messages API now runs on Rust: about 70% less CPU per request, more than 80% less memory, 20% faster first token. The hard part was not the rewrite, it was verifying an agent-written clone against live traffic.

Anthropic Moved the Claude API to Rust With Zero Downtime. Claude Wrote Most of the Code

Anthropic published an engineering post-mortem on November 25 describing how it replaced the Python implementation of its Messages API with a Rust one that Claude itself largely wrote. The company's numbers: roughly 70% less CPU per request, more than 80% less memory, and a median time-to-first-token about 20% faster for Claude Code customers. The service was never taken offline, and feature development did not stop during the migration.

Two cargo ships side by side, one sailing and one being built at a dock

A request forwarder that outgrew its language

The Messages API was built in 2023 in Python, which Anthropic notes was the internal default for research code at the time. One engineer described it then as "basically a request forwarder." It became the primary route through which customers, plus Anthropic's own apps like Claude Code and Cowork, reach Claude.

Traffic changed the math. From early 2024 to fall 2026, API traffic grew roughly 1,800 times. By late 2025, every request had to be validated, converted into a prompt, tokenized and screened by safety classifiers, and every streamed reply had to be sorted into text, thinking and tool-call blocks. Python added overhead at each step, on every object creation and memory free.

The team first followed the conventional advice: rewrite only the hot path. A Rust implementation of model-output parsing, called from Python, cut CPU by just 8 to 10%, and it introduced a new problem: each token of a reply crossed between Python and Rust three times. The savings did not justify the complexity, so the team committed to a full rewrite.

Claude wrote it. Verifying it was the hard part

By May 2026, Anthropic says Claude was writing more than 80% of the code the company merged, and Claude produced a first version of the API's core request path in about a week. The bottleneck was not generation. It was proving the new system behaved like the old one, in a system where the old one kept changing under them.

The obstacles were specific. The existing suite of about 700 integration tests ran the Python API inside the test process with in-memory mocks, so the tests moved with the code; an audit later found more than 100 weakened assertions among the ported tests. Claude is nondeterministic, so a differing reply did not imply a bug. And Anthropic could not read customer requests, so engineers could not simply look at where the two versions diverged.

The answer was production shadowing with privacy-preserving diff detection. The model was called once and its output replayed into the Rust version. Both APIs were compared checkpoint by checkpoint, and each difference was logged as a "fingerprint": the step, the prompt piece, both lengths, and the first differing byte. Never the text. A script grouped diff records every 10 to 30 minutes and alerted a coordinating Claude agent only when a new kind of difference appeared. Worker agents took each kind, opened Slack threads engineers could steer, and ran fixes through a sandboxed inner loop (sub-second local checks), a production outer loop (shadow traffic watching whether the fingerprint disappeared), and a memory loop that turned review corrections into rules, lints and tests.

The early numbers were humbling: the Rust API passed about 98% of its tests in April, yet only about 24% of production inputs matched Python. The match rate dipped to 6.5% in early May as more traffic was compared, then climbed to 99.6% by August as fixes landed. Public traffic moved to Rust in September. Merged changes to the Rust codebase climbed from under 100 per two-week period in April to more than 3,000 in August.

The post also carries a warning about agent-written fixes. In one case an agent proposed copying the web search tool's description into text files so the prompts would match; the local verifier passed it. An engineer rejected it as throwaway code, because the Rust API would still have to call the real service before launch. A verifier can tell you the outputs matched; it cannot tell you the fix is shippable.

The write-up frames the result with the Ship of Theseus: an identically functioning ship was built beside the old one while it kept sailing, then passengers moved over a few at a time. The new ship, the company says, sails faster.

Sources

AI News