Why Anthropic used Claude to replace its Python API with Rust
- Scaling past Python: Anthropic migrated its Messages API from Python to Rust after a 1,800x traffic surge overwhelmed per-request interpreter overhead.
- Massive efficiency gains: The zero-downtime Rust cutover slashed CPU usage by 70%, cut memory by 80%, and trimmed latency by 20%.
- Built by Claude: Claude agents wrote and debugged much of the new Rust codebase, producing an initial core version in a single week.
- Verification proved hardest: Engineers focused heavily on building a custom shadow traffic verifier and catching AI agents that accidentally weakened unit tests.
Why Python finally broke
- 1,800x traffic surge: Explosive usage growth since early 2024 pushed Anthropic's legacy Python monolith past its scaling limits.
- Heavy glue overhead: Python's object allocation, memory management, tokenization, and request validation created severe per-request CPU bottlenecks.
- Partial rewrites failed: Early attempts to port only hot paths to Rust backfired due to crossing overhead between the two languages.
Performance gains without downtime
- 70% less CPU: Stripping away Python's interpreter tax delivered a 70% drop in CPU consumption per request alongside an 80% memory reduction.
- Faster live responses: The Rust migration achieved a 20% latency reduction and improved time-to-first-token without taking the live service offline.
The hidden verification trap
- Weakened unit tests: While Claude agents quickly drafted the Rust port, engineers had to catch traps such as agents accidentally weakening unit tests.
- Non-deterministic outputs: Validating probabilistic LLM responses required specialized byte-fingerprinting to separate actual porting bugs from normal output variation.
- Privacy-preserving shadow traffic: Anthropic built a custom shadow traffic verifier to prove output parity without ever inspecting live user prompt data.
A blueprint for agentic engineering
- Supervising over typing: The rewrite highlights an industry shift where human engineers pivot from writing boilerplate syntax to designing validation frameworks.
- Self-hosted AI migration: Deploying Claude agents to rebuild the Messages API serving Claude Code and customers sets a high-profile blueprint for AI-driven system rewrites.
💬 Notable Signals
“Anthropic's Rust Rewrite is a Masterclass in Agentic Engineering.”
“Claude helped rewrite Anthropic's API in Rust. Checking it was harder”
“Claude rewrote the API that serves Claude: Anthropic says it moved its Messages API (how customers and Claude Code reach the model) from Python to Rust”