What Anthropic actually shipped
On November 25, 2026 Anthropic published a write-up of migrating its Messages API, the 2023 Python service behind the API, Claude Code and Cowork, to Rust. API traffic grew roughly 1,800x between early 2024 and fall 2026, and Python overhead in every step (validation, prompt building, tokenizing, safety classifiers, streaming, usage counting) was the bottleneck. A partial rewrite in March 2026 that moved only response parsing to Rust saved about 8 to 10% CPU, but each token crossed the Python/Rust boundary three times, so they went for a full port.
- Claude wrote the Rust core request path in about a week.
- Traffic moved to Rust in September 2026.
- About 70% less CPU per request and more than 80% less memory per request (Aug to Oct).
- Median time to first token down about 20%.
98% of tests passed. 25% of production matched.
This is the number that matters for anyone using coding agents. In April the Rust API passed about 98% of its roughly 700 integration tests, yet only about a quarter of production inputs produced matching results. An audit also found more than 100 weakened assertions in tests that had been ported. Tests were coupled to the Python implementation, and the agents optimized for passing them.
The verification loop, in three pieces
- Shadow production traffic. Call the model once, then replay its output into both the Python and Rust paths, so nondeterminism and billing are not doubled. They recorded only the shape of differences, never customer content.
- Checkpoint every stage. Compare accept/reject, resolved settings, the built prompt and each prompt piece, and stop at the first stage that differs.
- Fingerprint the diff. Stage, piece, first differing byte and length difference. Thousands of mismatches collapse into a short list of bugs, and an agent gets assigned to each new fingerprint.
Around that sit three loops: a sub-second inner loop in a sandbox, a slower outer loop on shadowed traffic, and a memory loop where every correction becomes a rule, test or lint. Humans sat at the seam between inner and outer loop, and once rejected an agent shortcut that copied tool descriptions into files just to make diffs match.
Run the pattern on your own port
This is a teaching version, not Anthropic's code. Both implementations are plain commands that read JSON lines and emit named checkpoints, so the port can be Rust, Go or TypeScript. The sample port has two planted bugs an agent could easily ship: a dropped system prompt line and escaped non-ASCII in tool-call JSON.
git clone https://github.com/seyiayeni/acadaai
cd acadaai/examples/claude-rust-api-rewrite
python3 make_requests.py > requests.jsonl
python3 shadow_diff.py requests.jsonl "python3 reference.py" "python3 port.py"500 requests | 273 match (54.6%) | 3 distinct fingerprints
[5fa29fee] x195 stage=prompt path=$.system len_delta=-25 first_byte=29
ref : "You are a helpful assistant.\nNo tools are available."
port: "You are a helpful assistant."
[3e57a3bd] x19 stage=prompt path=$.turns[1].text len_delta=+2 first_byte=83
[1635945b] x13 stage=prompt path=$.turns[1].text len_delta=+1 first_byte=78Notice the last two fingerprints are the same escaping bug (an emoji and an accented character). Fingerprints group; a human still decides what counts as one bug. That is the seam Anthropic describes.
def compare(ref: dict, port: dict):
"""Walk checkpoints in order; stop at the first stage that differs."""
for (stage, r), (_, p) in zip(ref["checkpoints"], port["checkpoints"]):
d = first_diff(r, p)
if d:
json_path, rv, pv = d
rs, ps = json.dumps(rv), json.dumps(pv)
byte = next((i for i, (x, y) in enumerate(zip(rs, ps)) if x != y),
min(len(rs), len(ps)))
# Fingerprint = where it broke + how, never the data itself.
fp = hashlib.sha1(
f"{stage}|{json_path}|{len(ps) - len(rs):+d}".encode()
).hexdigest()[:8]
return {"fingerprint": fp, "stage": stage, "path": json_path,
"first_byte": byte, "len_delta": len(ps) - len(rs)}
return NoneAgent prompt: fix one fingerprint at a time
You are porting <module> from <source language> to <target language>.
The reference implementation is the source of truth. Mirror-port exactly what it does; never guess.
Here is ONE fingerprint group from shadow_diff.py:
<paste the group: fingerprint, count, stage, path, ref/port snippets>
1. Find the line in the reference that produces the ref value.
2. Find the corresponding line in the port and explain the difference.
3. Fix the port only. Do not edit the reference, the harness or any test assertion.
4. Re-run: python3 shadow_diff.py requests.jsonl "<ref cmd>" "<port cmd>"
5. Stop when this fingerprint is gone. Report which other fingerprints changed.When to use this (and when not to)
- Use it for rewrites with a working reference: language ports, framework upgrades, refactors of request pipelines.
- Record checkpoints at stage boundaries you already have. Ten minutes of plumbing buys you a precise error signal.
- Never let the agent edit the harness or test assertions in the same loop it is being judged by.
- For greenfield code there is no reference to diff against; you need specs, property tests or formal checks instead.