AI engineering

Anthropic's Rust Rewrite: The Hard Part Was the Verifier

Claude wrote a first Rust request path for Anthropic in about a week. Proving it matched production was the real work. Notes from a migration I led by hand.

In this post
  1. The first version took a week
  2. The incremental route cost too much to keep
  3. Mirrored traffic only tells you that something differs
  4. The verifier rewards matching, not good fixes
  5. Corrections turned into rules, lints and a merge check
  6. The service I would still leave alone

I joined InsideTrack in 2018 and led our migration from Ruby to Elixir. The Rails API service went last and most carefully, because it was the customer-facing surface. We ran a dual-deploy period for two months with traffic mirrored to both stacks for parity testing. When I wrote the migration up, one thing I said I would change was this: “I’d build the dual-stack observability layer first.” We had bolted it on. The full story is in the Ruby to Elixir post.

Anthropic’s write-up of moving its Messages API from Python to Rust came out on November 25, 2026. Most of it describes a layer like the one I wished I had built first, with agents working inside it.

The first version took a week

The authors say Claude wrote a first version of the API’s core request path in about a week. They also say that by May 2026 Claude was writing more than 80% of the code Anthropic merged, a figure that counts lines merged to production. Then they state the problem in one sentence: “Verification, not generation, had become the bottleneck.”

The numbers that show it are about tests. They had about 700 integration tests. In April the Rust build passed about 98% of its tests. On production traffic, only about a quarter of inputs matched what the Python API produced.

The post gives two reasons for the gap. One is plain coverage. Python escapes certain characters, an emoji for example, when it writes JSON tool calls. Rust wrote them as is, so the two prompts differed by a few bytes. No test had covered that. The other is how production counts. A test suite counts each case once. In live traffic, one common bug shows up on every request that triggers it.

The tests had a second problem. The old tests ran the Python API inside the test’s process, with billing and rate limiting mocked in Python’s memory, so they were ported along with the code, and Claude worked on both. When Anthropic audited the ported tests, they found more than 100 weakened assertions. A pass could mean the code was right, or it could mean the ported test checked less than the original. That’s a cousin of the tautological tests I wrote about in the agent bugs I catch every week.

The incremental route cost too much to keep

Anthropic tried the cautious path first. They rewrote the code that parses a model’s output in Rust and called it from Python. That cut CPU by about 8% to 10%. But every token of a reply now made three trips between Python and Rust, and Anthropic decided the savings weren’t worth the added complexity.

What changed their mind was that writing code got cheap. Checking it didn’t get cheap at the same rate. A full rewrite moves every behavior at once, including the ones nobody remembers the system has, so the checking covers the whole surface. That is where Anthropic spent its effort.

Mirrored traffic only tells you that something differs

Anthropic shadowed production: real requests ran through both versions and the results were compared. Two details make theirs harder than the textbook version.

Claude can reply differently to the same input, so a difference between two outputs doesn’t necessarily mean a bug. They ran the model once and replayed its output to the Rust side. And they couldn’t read customer requests or replies. So instead of text, they recorded the shape of each difference. Both versions go through the same steps, such as accepting the request, resolving settings and building the prompt, and the first step where they diverge says roughly where the bug lives. That’s the checkpoint. Then they recorded where in the prompt the difference began and how many bytes it was off by. That’s the fingerprint, and one bug tends to leave the same one on every request it touches.

Anthropic shows an example record with made-up values. These are theirs, not from real traffic:

step: build prompt
piece: 2
first diff: byte 17
python: 190 bytes
rust: 190 bytes

One bug could leave hundreds of thousands of near-identical records. So a script ran every 10 to 30 minutes, grouped records by which fields differed, and alerted a coordinating agent only when it saw a new kind. The coordinator assigned a worker agent to own each new kind and opened a Slack thread for engineers to follow.

A mirrored-traffic setup that only says “these two responses differ” leaves all the real work to people, who now have a pile of diffs. Anthropic’s lessons section says it directly: a proof assistant points at the failing step and a test names the failing case, but a production system often offers no such signal by default, and much of their effort went into building one. What I described wanting was consistent metrics across both stacks. A record that an agent can pick up and act on is a step past that.

The verifier rewards matching, not good fixes

Agents worked from the fingerprint in a cloud sandbox with both codebases and fast local checks. The input check built the prompt each version would send and showed the difference, without calling the model, in under a second. An agent would guess the cause, write its own request to trigger it, and edit the Rust until the two matched. Then it had to add a test that failed on the old code and passed on the new.

In mid-May one of the largest remaining differences came from web search. The production API fetched the tool’s description from an internal service. Rust didn’t call that service yet, so the text was missing from its prompts. An agent proposed copying the text into files Rust could read. The prompts matched and the local verifier passed. An engineer turned it down: Rust would have to call the service before launch anyway, and the workaround would be thrown away.

Anthropic’s explanation: “the verifier rewarded matching outputs, and the agent found the cheapest way to produce them.” I made the same point about DHH’s Campfire benchmark: agents meet the bar you set. The post goes on: “A verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship.”

So the human gate went at the seam between two loops: a fast one in the sandbox and a slower one that checks each fix against shadowed production traffic. A fix crossed only after PR review, which let engineers look at proposed fixes instead of guesses, and at questions no verifier can answer, such as whether a difference was a bug or a deliberate change. The correct fix took the team weeks to build. In the meantime the bug kept producing records, some with new fingerprints. The agent had saved a note to memory about the rejected shortcut and the right fix, and later agents that checked it linked the new records to the known bug instead of writing another workaround.

Corrections turned into rules, lints and a merge check

When an agent guessed at Python’s behavior, an engineer made it a rule to “port exactly what Python did.” An agent then compared the existing code against that rule and found seven more places where the port had relied on a guess. In June an agent read about 60 of the team’s review comments, grouped the recurring problems and proposed rules. An engineer edited and approved them for CLAUDE.md. That’s the same pattern I found on my own project in what I put in CLAUDE.md after 50 commits: the entries worth keeping trace back to a specific failure.

Anthropic calls this the memory loop, and it didn’t stop at documentation. Some corrections became checks: tests that fail when Rust drifts from Python, lints for the patterns reviewers kept flagging, and later a merge check. After that, a change to the Python code needed a matching change in Rust, or an exemption request, to merge. The Python API kept changing during the whole migration, so parity was a moving target. A rule in CLAUDE.md is something an agent reads. A lint or a merge check is something an agent can’t talk its way past, which is the argument of the deterministic checks post. That post is the cheaper version of the same idea.

The service I would still leave alone

In my own migration, the Rails web monolith stayed Ruby: too much business logic, too low a marginal benefit. When I wrote it up in February I said I’d make the same call again. Anthropic’s post doesn’t change that. Agents lower the price of writing the port. Somebody still has to prove the port does what the old code did, and the benefit has to pay for that.

Anthropic’s benefit did. API traffic grew roughly 1,800 times from early 2024 to fall 2026. The Rust version uses about 70% less CPU per request and cuts median time to first token by about 20%. The service stayed online and feature work kept going the whole time. Shadow testing started in April, and public traffic moved to Rust in September. To get there they built a sandbox loop, a production loop, a memory of corrections and a coordinating agent.

If you’re deciding whether an agent-written migration is worth it, start by listing what your verifier would be and who reads its output. If you want help with that list, it’s work I take on. The consulting page has the details.

Read next: the InsideTrack migration write-up, including the parts I would do differently.