Anthropic's Rust rewrite: the 25% tests never saw

Anthropic's Python-to-Rust rewrite of the Messages API passed 98% of its tests in April and matched only a quarter of live inputs. The parity harness, not the language, is the part your team should copy.

Anthropic's Rust rewrite: the 25% tests never saw

Anthropic rewrote the Messages API — the endpoint every Claude request passes through, including Claude Code traffic — from Python to Rust. Announced on 25 November and shipped to production in September, it uses about 70% less CPU per request, more than 80% less memory, and cuts median time to first token by roughly 20%, with no downtime.

The performance numbers are the headline. The lesson is in the gap: the Rust rewrite passed about 98% of the test suite in April and matched only about a quarter of real production inputs. That gap, not the language, is the part worth copying.

What actually changed

The service started in 2023 as what one engineer called "basically a request forwarder." By late 2025 every request was validated, converted into a prompt, tokenised, screened by safety classifiers, then streamed back with tokens sorted into text, thinking and tool calls, and metered for billing. Traffic grew roughly 1,800 times between early 2024 and autumn 2026. Anthropic says Python's per-object overhead landed on every one of those stages.

Their first move was the one most teams make: rewrite only the hot path. They ported the model-output parser to Rust and called it from Python. CPU dropped 8–10%, but each token then crossed the language boundary three times, and the added complexity ate the gain. They went for the full rewrite instead.

Tests measured the wrong thing

Two failure modes did the damage.

The tests were welded to the implementation. Roughly 700 integration tests ran the Python API in-process with billing and rate limiting mocked in Python's memory. Any port had to change them. When Anthropic audited the ported suite, it found more than 100 weakened assertions — cases where a "pass" could mean the code was right or that the test had been quietly relaxed.

Coverage was never the point. Twenty binary options make over a million configurations; at a second each, that is 12 days of tests for one model before you vary the prompt. Tests cover the combinations someone thought of. Production covers the ones nobody did.

The mismatches that survived were small and invisible from the outside. Python escapes certain characters inside JSON tool calls — an emoji becomes a text code — while Rust wrote them literally, so two prompts differed by a few bytes. Nothing errored. Claude still answered, slightly differently.

Making production the oracle

Anthropic could not read customer requests or replies, so they compared the shape of each difference rather than its text. Two techniques did the work:

  • Checkpointing. Both versions advance through the same steps — accept or reject, resolve settings, build the prompt. Compare results at each checkpoint and the first step that diverges tells you where the bug lives.
  • Fingerprints. Record where the difference starts in the prompt plus the length delta. One bug leaves the same fingerprint on every request it touches, so hundreds of thousands of near-identical diff records collapse into tens of distinct causes.

That design is also a compliance pattern. If you handle client data under DPDP, you cannot dump payload text into a diff log and call it observability. Step, offset and length are enough to debug without storing the request.

The fixes ran in three loops: a sandbox inner loop that compared prompt construction in under a second without calling the model; an outer loop that shadowed live traffic with and without each fix; and a memory loop that turned review comments into rules every agent inherited. A coordinator woke every 10–30 minutes, grouped new fingerprints, and assigned a worker agent plus a Slack thread. Humans gated the inner-to-outer seam — and that gate earned its keep when an agent "fixed" a missing web-search tool description by copying text into files. The verifier was satisfied. An engineer rejected it, because Rust still had to call the real service at launch.

The scale test before you copy this

Seventy percent less CPU is a rounding error if you serve 20 requests a second. Do the arithmetic on your own bill: migration cost divided by monthly compute saved. For most Indian SaaS and services teams the payback is years, not quarters. Two things do travel down-market, though.

First, time to first token is a product metric, not an infra metric. A 20% cut is visible in a chat UI and in agent loop latency, where every tool call pays it again.

Second, the parity harness is reusable. It is what lets you upgrade a framework, swap a queue, or move a PHP monolith into a service without a three-week freeze. NetPy's web development and enterprise IT teams run these migrations for clients; the harness separates a controlled cutover from a 2am rollback.

Checklist: porting a live service safely

  1. Write the parity definition before the code: which stages must match exactly, and which may drift.
  2. Stand up shadowing with one hard rule — a shadowed request never counts twice against quota or billing.
  3. Replay a single model or upstream response into both versions so nondeterminism cannot mask bugs.
  4. Compare per stage, not per response. Log step, offset and length; never payload text.
  5. Fingerprint diffs and triage by distinct fingerprint, not by frequency.
  6. Audit every assertion an AI or a hurried human changed during the port. Treat a weakened test as a production bug.
  7. Give fixers a sub-second local verifier; keep human review at the merge gate.
  8. Propagate review rejections into written rules, and cut traffic over by cohort with the old path warm until parity holds for a full week.

The uncomfortable conclusion in Anthropic's own write-up is that verification, not generation, is now the bottleneck. Claude wrote the first version in about a week; proving it correct took from April to September. If your team plans a rewrite this quarter, budget for the second number — and read our earlier note on why verification loops decide whether AI-written code ships.


Source: Anthropic, "Migrating our Messages API to Rust", 25 November 2026; reported by Analytics India Magazine. Figures are Anthropic's own and not independently measured.