Rewrite a live Python API in Rust and verify it by shadowing real traffic

Anthropic had Claude agents rewrite its Messages API from Python to Rust, then spent months checking it against real traffic. It reports about 70% less CPU and over 80% less memory per request.

Done withClaude· Nov 26, 2026

What they did

Anthropic's Messages API, the service that sits between customers, Claude Code and Cowork and the models, was written in Python in 2023. Traffic grew about 1,800 times between early 2024 and fall 2026, and a small partial port to Rust had not paid off. As the models got better at code, the team had Claude agents write a full Rust version. The agents produced a first version of the core request path in about a week. To check it, the team ran traffic shadowing: the same requests went through the old and new services, the model ran once with its output shared by both, and only the points where they differed were recorded, not customer conversations. When a new kind of mismatch turned up, a coordinating Claude agent handed it to another agent, which reproduced it in a separate environment, tried fixes and sent a proposed fix to an engineer for review.

How it went

By April 2026 the Rust service passed about 98% of its tests, yet only about a quarter of real inputs were processed the same way as the old service, and more than 100 test assertions had been weakened during the port. Shadowing closed that gap over several months, while customers kept using the API and new features kept shipping. The finished rewrite uses about 70% less CPU and over 80% less memory per request, and median time to first token for customer Claude Code requests fell by 20%. In one case an agent fixed a missing web search tool description by copying the text into local files; an engineer rejected it because the text has to come from an internal service, and that feedback was saved as a standing instruction so later agents stopped proposing the same shortcut.

Worth knowing

Writing the code took a week and proving it correct took months, so budget for the verification harness, not the port. A passing test suite was misleading here because the agents had loosened tests along the way; compare behaviour on real inputs instead. This is Anthropic reporting on its own product, relayed by The Neuron from Anthropic's November 25 engineering report. The harness the agents ran in is not named.

Try it

With Claude· 8 parts to fill in

Help me port [service name] from [current language] to [target language] without changing its behaviour. First write the new implementation of [the core request path] only. Then build a shadowing harness: send the same [recorded or live] requests to the old and new versions, share any nondeterministic output between them, and log every difference without storing [sensitive payloads]. For each new class of difference, reproduce it in [a test environment], propose a fix and stop for my review before applying it. Never weaken, skip or delete an existing test to make it pass; if a test looks wrong, flag it to me. Keep a file of my review decisions and follow it on later fixes. Stop when [N days or N requests] of shadowed traffic show no differences.

Square brackets are the parts to fill in. The prompt is ours; the story is theirs.

Where they said it

Related