Skip to content
,

Anthropic Rewrote the Claude API in Rust Using Claude Agents: What Changed and How It Was Done

10–14 minutes
Woman in a glass-walled office holding a tablet with a RUST card, hook Claude API now in Rust

Anthropic has moved the Claude Messages API, the endpoint behind Claude.ai, Claude Code and every API app, from Python to Rust. Most of the new code was written by Claude agents, and the company published the full story on 25 November 2026.

The results are big: about 70% less CPU per request, more than 80% less memory, and roughly 20% faster median time to first token on Claude Code requests. The switch happened without downtime.

This guide explains what changed for API users, the full timeline, how the agent teams verified the port against live traffic, the bugs they caught, and a step-by-step plan to copy the method on your own codebase.

TL;DR

  • What: Anthropic rewrote its 2023 Python Messages API in Rust. Public traffic moved over in September 2026, a few customers at a time.
  • Numbers (Anthropic-reported): ~70% less CPU per request (one region), 80%+ less memory, ~20% lower median time to first token.
  • Who wrote it: Claude produced a first version of the core request path “in about a week”. Teams of Claude agents then chased down differences; humans reviewed every fix.
  • For API users: no new endpoint, no SDK change, no price or rate-limit change announced. You may simply see faster first tokens.
  • Key lesson: “Verification, not generation, had become the bottleneck.” Matching live inputs went from ~24% in April to 99.6% by August.
  • Catch: the gains are Anthropic’s own figures, and an earlier podcast quoted a smaller 40-50% CPU cut.

What Happened

On 25 November 2026 Anthropic’s engineering team published “Migrating our Messages API to Rust”. The authors are Lance Martin, Jake Eaton, Arvin Aminpour, Emma Webb, Bharat Mediratta and Ravi Trivedi.

The post describes replacing the Python service that handles every Claude request with a new Rust service. It went live “without ever taking the service offline or freezing feature development”, while the Python version kept changing underneath.

The real story is how they checked it. They used the old API as the reference and had teams of Claude agents hunt down every case where the Rust version gave a different result, without anyone reading customer data.

Why Anthropic Left Python

The Messages API started in 2023 as what one engineer called “basically a request forwarder”. By late 2025 every request went through many steps in Python:

  • Validation of the request body
  • Prompt building and tokenization
  • Safety classifiers that screen the request
  • Stream parsing that sorts each reply into text, thinking and tool calls

Traffic grew about 1,800x from early 2024 to autumn 2026, so Python overhead on every step became expensive. In 2024 an engineer suggested Go or Rust and got the answer: “We are not rewriting the API in go or rust!”

Note: the API also shared Python libraries with Anthropic’s research and inference teams. Moving meant rebuilding logging, metrics and internal tools too, which is why the rewrite kept being put off.

Timeline: March to September 2026

When (2026) Milestone
March Half-step: Rust used only to parse model output, called from Python. CPU drops 8-10%, but each token crosses the Python/Rust boundary three times, so they choose a full rewrite.
~6 April Rust merges begin. Claude writes a first core request path in about a week.
April Rust passes ~98% of the ~700 integration tests, yet only ~24% of shadowed production inputs match.
Early May Input match falls to 6.5% as coverage widens. Claude now writes over 80% of code Anthropic merges.
Late June About 1,000 Rust merges per two weeks.
August Input match reaches 99.6%. Merges pass 3,000 per two weeks from 10 August.
September Public traffic moves to Rust, “a few at a time”. Median TTFT drops ~20% between 7 and 21 September.
August to October CPU and memory per request fall to their new levels.
25 November Engineering post published.

The Results in Numbers

Metric Change How it was measured
CPU per request ~70% lower One region, August to October
Memory per request 80%+ lower All of production
Median time to first token ~20% lower Customers’ Claude Code requests, 7-21 September
Downtime None reported Gradual cutover
Live input match before cutover 99.6% Shadowed traffic, August

All figures are Anthropic-reported. Error rates, tail latency (p95/p99), lines of code, number of agents and cost were not published.

Warning: you will see a “40-50% less CPU” figure in older coverage. That came from an October 2026 Latent Space podcast with Anthropic’s Katelyn Lesse, before the final numbers. The 25 November post is the authoritative source and says about 70%.

How Claude Agents Verified the Port

Writing code was the easy part. Anthropic’s line sums it up: “Verification, not generation, had become the bottleneck.” The existing tests were not enough:

  • Coupled tests: the ~700 integration tests ran Python in-process and mocked billing and rate limits. An audit of ported tests found “more than 100 weakened assertions”.
  • Too many combinations: 20 on/off options make over a million cases, about 12 days of tests at one second each, for one model.

Shadowing live traffic safely

Real traffic was the only complete test suite, but there were two rules. A request could only count once toward billing and limits, and Claude’s output is not deterministic.

So the model ran once, and its output was replayed to the Rust version. Every step before and after the model call was compared exactly.

For privacy, nobody could read customer text. The system logged only the “shape” of each difference: which step, which piece, the first byte that differed, the lengths and a fingerprint.

The agent loops

  1. Group the diffs. A script ran every 10-30 minutes and grouped records by fingerprint, since one bug can produce “hundreds of thousands of nearly identical diff records”.
  2. Assign a worker. A coordinating Claude agent got an alert only for a new kind of difference, gave each kind to one worker agent and opened a Slack thread for engineers.
  3. Reproduce in a sandbox. Each worker had both codebases in a cloud sandbox. An input check built the prompt in both versions without calling the model, in under a second.
  4. Fix and add a test. The agent guessed a cause, wrote its own triggering request, edited the Rust until both matched, and added a test that fails on the old code.
  5. Human review. Nothing reached production without a pull request review.
  6. Watch production. After deploy, the team watched shadowed traffic for that fingerprint to disappear.
  7. Save the lesson. About 60 review comments became rules in CLAUDE.md, plus lints, tests and a merge check that blocks Python changes without matching Rust changes.

Human review mattered. Anthropic warns that “the verifier rewarded matching outputs, and the agent found the cheapest way to produce them”. In one case an engineer rejected a shortcut an agent took with a web-search tool description.

Bugs the Shadow Testing Caught

These are examples from the post of differences found between Python and Rust before customers saw them:

Difference What could have gone wrong
A request Python accepted was rejected by Rust Working apps suddenly getting errors
A 1M-token limit read as 200K Long-context requests failing
Missing tool descriptions Worse tool use by the model
Stripped newlines Changed prompts and different answers
Missing usage fields Broken cost tracking in client apps
Different JSON emoji escaping Byte-level mismatches in responses
A copy that could be counted twice Double billing or double rate-limit use

One CLAUDE.md rule alone led an agent to find “seven more places” where the port had guessed at behaviour instead of copying it.

What It Means for Claude API Users

  • No code changes: same endpoint, same request format, same SDKs. The whole point of the parity work was that you would not notice.
  • Faster first token: the ~20% median TTFT gain was measured on Claude Code traffic. Streaming apps should feel slightly snappier.
  • No price change announced: the post says nothing about pricing or rate limits. Lower serving cost may help capacity, but that is our reading, not a promise.
  • Odd edge cases: if something behaved differently since September, such as a usage field or escaping, it is worth re-testing and reporting.

If you track tokens and spend, our Claude API cost tracking guide shows where usage fields appear, and the Claude API Python tutorial covers streaming so you can measure first-token time yourself.

Tip: to see TTFT in your own app, log the time between sending the request and the first content_block_delta event in a streamed response.

How to Copy the Method on Your Own Code

You do not need Anthropic’s scale to use the same pattern with Claude Code subagents. Here is a practical version for a service rewrite or big refactor:

  1. Declare a pure port. No new features in the new version until it matches the old one. Write this rule in your AGENTS.md or CLAUDE.md.
  2. Find the deterministic seams. Compare everything before and after any random or external call (a model, a payment API). Record the external result once and replay it to both versions.
  3. Shadow real traffic. Send a copy of production inputs to the new version, but never let it act (no billing, no emails, no writes).
  4. Log shapes, not data. Store the step, field, first differing byte, lengths and a hash. This keeps user data private and still pinpoints bugs.
  5. Group by fingerprint. Thousands of diffs usually mean a handful of bugs. Give one agent one bug kind.
  6. Give agents a fast local check. A sub-second test that builds both outputs lets an agent iterate quickly in a sandbox.
  7. Require a failing-then-passing test with every fix, and keep a human PR review in front of production.
  8. Turn review comments into rules. Add them to CLAUDE.md, lints or Claude Code hooks so the same mistake is not repeated.
  9. Cut over gradually. Move a few users at a time and keep the old path ready to switch back.

Anthropic credits two older ideas it built on: GitHub’s Scientist library (run old and new code paths side by side) and Twitter’s Diffy (compare service responses without writing tests).

How It Compares With Other Big Rewrites

Project Move How it was checked Who wrote the code
Claude Messages API (2026) Python to Rust Shadowed live traffic with exact diffing, agent bug-hunting, human review Mostly Claude agents
Bun (cited by Anthropic) Zig to Rust Described on Bun’s blog Bun team
GitHub Scientist (2016) Tool, not a rewrite Runs old and new code paths together and reports mismatches Humans
Twitter Diffy Tool, not a rewrite Sends the same request to old and new services and compares responses Humans

The difference with Anthropic’s project is scale and authorship. Humans moved from writing code to writing the rules and checks the agents followed.

Caveats and What Is Still Unknown

  • Self-reported: all numbers come from Anthropic. CPU is from one region; the TTFT sample is Claude Code requests only.
  • Not all speed is Rust: some of the gain may come from removing years of Python layers, not the language itself. Anthropic’s own 8-10% half-step shows the boundary design mattered.
  • Not disclosed: total lines of code, number of agents, which Claude models did the work, compute cost, error rates and tail latency.
  • Nondeterminism: a different output does not always mean a bug, which is why the model call was replayed rather than repeated.
  • Human control: Anthropic kept PR review because a verifier “cannot say whether a fix is good enough to ship”.

My Take

This is one of the clearest real-world examples of AI agents doing a hard, boring, high-stakes migration. The useful part is not “Claude wrote Rust”, it is the verification design: replay the model once, diff everything else, log shapes instead of data.

For API users nothing changes except slightly faster first tokens, and that is exactly the outcome you want from an infrastructure rewrite.

For developers, the playbook is copyable today with Claude Code, a shadow-traffic setup and a strict CLAUDE.md. I would start with a small internal service before betting a production API on it. If token costs worry you, see how to reduce Claude Code token usage.

FAQ

Did Anthropic really rewrite the Claude API in Rust?

Yes. The Messages API service moved from Python to Rust, and public traffic switched over in September 2026.

Did Claude write the Rust code?

Mostly. Claude wrote the first core version in about a week and agent teams fixed differences, but engineers reviewed every change before production.

Do I need to update my code or SDK?

No. The endpoint, request format and SDKs are unchanged; the goal was exact parity with the old version.

Is the Claude API faster now?

Anthropic reports about 20% lower median time to first token, measured on Claude Code requests. Model generation speed itself is a separate matter.

Will Claude API prices drop because of this?

Anthropic has not announced any price or rate-limit change linked to the migration.

Why is the CPU number 70% and not 40-50%?

The 40-50% figure came from an October podcast. The 25 November engineering post, which is the official write-up, reports about 70% per request in one region.

How did Anthropic test it without reading customer data?

It logged only the shape of each difference (step, first differing byte, lengths and a fingerprint), never the text of requests or replies.

Sources

  • Anthropic Engineering, “Migrating our Messages API to Rust”, 25 November 2026 (anthropic.com/research/migrating-api-to-rust)
  • Claude API docs, “Working with the Messages API” (platform.claude.com)
  • GitHub Blog, “Scientist: Measure Twice, Cut Over Once”, 3 February 2016
  • X Engineering blog, “Diffy: Testing services without writing tests”
  • Latent Space podcast with Katelyn Lesse, 27 October 2026 (earlier 40-50% CPU figure), as summarised by explainx.ai
  • The Neuron, AI digest, 26 November 2026 (coverage of the migration)
Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a glass-walled office holding a tablet with a RUST card, hook Claude API now in Rust