# Anthropic's Rust rewrite had to match Python down to the emoji

**Summary:** Anthropic checked its Rust rewrite of Claude's Messages API against the live Python service, replaying one model reply to isolate differences in how the two APIs handled it.

- Canonical: https://markhuang.ai/news/anthropic-rust-api-shadow-traffic
- Language: en
- Author: [Mark Huang](https://markhuang.ai/about)
- Published: 2026-11-25
- Section: News
- Tags: Anthropic, Claude Messages API, Rust, Shadow Testing, AI Coding Agents
- Source: [Anthropic](https://www.anthropic.com/research/migrating-api-to-rust)
- License: https://creativecommons.org/licenses/by-nc/4.0/

---

![A prism splits one beam between two optical assemblies that project matching bands of light.](https://cdn.markhuang.ai/news/anthropic-rust-api-shadow-traffic/hero.webp)

*One source, two paths: Anthropic gave both versions of its API the same Claude reply to process. Conceptual illustration generated with imagegen.*

An emoji was enough to make Anthropic's Python and Rust services disagree. When Python put a tool call into the prompt, it wrote the emoji as an escape code. Rust wrote the emoji directly. The two forms represent the same character in JSON, the format used for the tool call, but they left different text in the prompt Claude would see.

In [Anthropic's November 25 case study](https://www.anthropic.com/research/migrating-api-to-rust), that kind of difference helps explain an odd result. In April 2026, the Rust rewrite passed about 98% of its tests, yet the inputs it prepared for Claude matched Python's for only about a quarter of the live requests Anthropic compared. That doesn't mean three quarters of customer requests failed. The comparison was checking for identical inputs, and a single bug could affect many requests.

Anthropic says it moved public traffic to Rust in September 2026 without taking the Messages API, the service apps use to talk to Claude, offline. It kept Python serving customers while it checked the Rust rewrite against live traffic. The trick was to let both versions handle the same reply without asking the model to answer twice.

## One Claude reply, two ways to handle it

Running a new service alongside the old one to compare their behavior is called shadow testing. Twitter's [Diffy tool](https://blog.x.com/en/engineering/diffy-testing-services-without-writing-tests), for example, sent requests to two copies of the old service as well as the new one. If the old copies disagreed on their own, Diffy could use that noise to filter the comparison. For Anthropic, that would have meant filtering out the model replies it needed to check. Running a request twice also raised a billing problem: a customer's request should only count once.

Anthropic compared what Python and Rust prepared for the model, then let the live Python path call Claude. Rust got a replay of that same output. Now both APIs had the same material to turn into a streamed reply. If they handled it differently, Anthropic could look at the API code instead of wondering whether Claude had just answered differently the second time.

```mermaid
flowchart TB
    Request[Customer request] --> PythonInput[Python prepares input]
    Request --> RustInput[Rust prepares input]
    PythonInput --> InputCheck[Compare inputs]
    RustInput --> InputCheck
    PythonInput --> Claude[Claude generates one reply]
    Claude --> PythonOutput[Python handles reply]
    Claude -->|Replay| RustOutput[Rust handles reply]
    PythonOutput --> Customer[Customer receives reply]
    PythonOutput --> OutputCheck[Compare outputs]
    RustOutput --> OutputCheck
```

## A clue without the customer's prompt

To investigate a mismatch without reading the customer's request or reply, Anthropic recorded where the two versions first disagreed. A record could say which piece of the prompt differed, where the difference started and how long each version was. If the same mismatch appeared across thousands of requests, the team could group those records rather than investigate them one by one.

Claude agents used those clues to write their own requests or scripted model replies and try to reproduce the mismatch in a sandbox. Engineers reviewed the proposed fixes before Anthropic checked them again on live traffic. A fix could pass the local comparison and still leave the mismatch in production, where the requests and configuration could differ from the agent's test.

## The web search fix that didn't ship

Rust was missing the description of Claude's web search tool because it didn't yet call the internal service that supplied it. An agent copied the description into files Rust could read. The prompts matched. An engineer rejected the fix anyway: Rust still needed to call the service, and the copied text would have to be thrown out.

That's the part I'd keep in mind if an agent handed me a passing comparison. The agent had found a way to supply the right text that day. The reviewer wanted Rust to get future descriptions from the same service Python used. As I argued in [a piece on software design and AI-written code](https://markhuang.ai/news/ai-code-system-coherence), a patch can work on its own and still make the surrounding system harder to change.

## What the migration bought

[Anthropic reports](https://www.anthropic.com/research/migrating-api-to-rust#looking-ahead) about 70% less CPU use per API request in one region. It also reports about a 20% drop in median time to first token for customers' Claude Code requests over a shorter measurement period. That's the wait for a reply to start, not the time to finish it. These are measurements from one migration, not a general benchmark of Rust against Python.

For another team weighing a rewrite, I'd start with one behavior customers depend on and ask what can be run twice without changing their experience. Anthropic could run the reply through both APIs, but the model call and the customer's bill had to happen once. Draw that boundary before handing over the port, and you have a way to learn from live traffic before the new code serves it.
