Anthropic Uses AI to Refactor Its Core System: CPU Usage Drops 70%, Memory Usage Plummets 80%, and Response Speed Soars!
In the tech world, a “complete rewrite” of a massive, fast-moving production system is often considered technical “suicide” by engineers.
But on November 25, leading AI company Anthropic announced that it had pulled off an engineering feat bordering on miraculous: it had Claude, its own large language model, take the lead in migrating the core Messages API from Python to Rust.
The results were striking: with not a minute of downtime and no freeze on new feature development, the new system cut CPU usage per request by about 70%, reduced memory usage by more than 80%, and shortened median time to first token (TTFT) by about 20%!
How did Anthropic use AI to pull off this feat of “changing an airplane’s engine in mid-flight”? And what does this epic migration mean for the future of software engineering?
Traffic Surges 1,800-Fold, and Python Struggles to Keep Up
Back in 2023, Anthropic’s Messages API was originally written in Python.
The logic was extremely simple. As one engineer put it, it was “basically a request forwarder”—passing user requests to the model and returning the model’s generated responses as they were.
But by the fall of 2026, API traffic had surged approximately 1,800-fold compared with early 2024!

As features grew more complex, every request had to go through laborious steps such as validation, prompt construction, tokenization, and safety classification. The overhead Python incurred when creating objects, freeing memory, and handing off tasks strained the original architecture.
The engineers initially tried an “incremental rewrite,” using Rust only for the part that parsed model output. But it backfired: every token had to cross between Python and Rust three times, adding complexity and overhead instead.

A complete switch to Rust became the only way forward. By then, Claude had become powerful enough that, by May 2026, it was writing more than 80% of the code Anthropic merged.
In fact, Claude produced a first draft of the API’s core request path in Rust in just one week.
But then came the real question: writing the code was easy—how could they prove it was correct?
The “Generator-Verifier Gap”: AI Writes Code Easily, but Finding Errors Is Hard
Software engineering has a well-known “generator-verifier gap.”
Take Sudoku: checking an answer is easy, but finding one is hard. In a live production system, however, the opposite is true: getting Claude to generate code is easy, but verifying that the code is 100% correct is extraordinarily difficult.
Anthropic faced several exceptionally thorny challenges:
- Unreliable test cases: The existing 700-plus integration tests were tightly coupled to Python. When Claude ported the tests to Rust, many assertions were inadvertently “weakened,” allowing faulty code to pass.
- Incomplete testing: The API had dozens of feature configurations. Just 20 binary options could produce more than a million combinations. Testing alone could not cover every edge case in a real production environment.
- AI nondeterminism: Claude’s response to the same request varies from one run to the next. If outputs differ, it is hard to tell whether the cause is a system bug or normal variation in the model’s responses.
- Privacy restrictions: Engineers were strictly prohibited from viewing customers’ actual requests and model responses, meaning they could not find bugs by “eyeballing the text.”
To break the deadlock, Anthropic decided to introduce a shadowing system, using the live Python production system as the “gold standard” for determining correctness.
But shadow testing a large language model API has two critical complications that traditional software does not:
- Model output is random: Ask Claude the same question twice, and the wording may differ each time. If traditional comparison tools compare the final responses directly, they will filter out all normal variation as noise and may miss real bugs.
- No duplicate charges or usage counts: The model must never run twice for the same real request; otherwise, it would consume the user’s quota twice and generate a double charge.
Anthropic therefore designed an ingenious “single inference, two-sided comparison” architecture: for each request, the model runs only once, and the system replays the same stream of tokens from the model to the Rust version. It then rigorously compares every intermediate step before the model call (input construction) and after it (output parsing and usage accounting), requiring the results from both versions to match exactly at the byte level.
At the same time, to uphold strict user privacy boundaries, the system never logs or views the original text of any user request or model response during comparison. So how could engineers and Claude agents pinpoint bugs while working blind?
The answer was to extract the “structural shape” of differences and use checkpointing and fingerprinting to locate the source:
- Checkpointing: Compare every step the two versions take when processing a request, such as validation and prompt construction. The first step where a difference appears is where the bug is hiding.
- Fingerprinting: Record the location and length of each difference. They found that the same bug often leaves the same “fingerprint” across different requests
In this way, the system generated “difference records” containing no private user text and automatically assigned them to Claude agents for fixes.
A Three-Loop Validation Cycle: AI and Humans Working in Harmony
Faced with a vast number of difference records, Anthropic designed an AI-led, human-supervised “three-loop validation cycle”:
- Fast Inner Loop: An AI sandbox playground. Agents run in a cloud sandbox. After receiving a “fingerprint,” the AI guesses the cause of the bug, writes its own test requests, and compares the Python and Rust results in less than a second. If its guess is wrong, it tries again; if it reproduces the bug, it modifies the Rust code until the two versions match exactly, then submits a PR (pull request).
- Slow Outer Loop: The real-traffic proving ground. Fixes from the inner loop must be reviewed by human engineers. After being merged, the code is deployed to the shadow production environment and tested against real traffic. If the “fingerprint” disappears, the fix has worked; if it remains, the task is sent back to the inner loop.
- Memory Loop: Preventing AI from making the same mistakes again. Corrections made by human engineers during review—for example, rejecting temporary code the AI wrote to take a shortcut—are recorded in the AI’s “memory,” such as a CLAUDE.md file. Future agents read these rules before starting work and may even search the entire codebase to find and fix similar mistakes elsewhere.
A Paradigm Shift in Software Engineering
Anthropic compared the migration to the famous philosophical paradox of the “Ship of Theseus.”
Traditional refactoring often requires stopping the ship in port and replacing its planks one by one. Claude’s capabilities, however, allowed the team to build a functionally identical new ship alongside the old one while it continued sailing at full speed. Agents continuously adjusted the new ship until its course matched the old ship’s exactly. Once everything was verified, passengers were smoothly transferred to the faster, more efficient new Rust ship.
This epic refactoring offered the tech industry some extremely valuable lessons:
- Verification is the new bottleneck: When writing code with AI is no longer the hard part, the ceiling on a team’s ambitions depends on how quickly it can “verify” the AI’s results.
- Humans move to the “edges”: Early in the refactoring, human engineers hunted bugs alongside AI. As the system matured, humans gradually moved to the edges of the validation cycle, focusing on setting rules and making high-leverage judgments so Claude could drive the work itself.
Using its own core system, Anthropic demonstrated that, with AI’s help, high-risk, low-level refactoring is not only feasible but can also be remarkably elegant. The future of software engineering is opening a new chapter led by “AI generation + systematic verification”!














