Author’s note: This article is about how to verify migration code written by AI. All tests passing is just the starting point—the truly reliable oracle is the legacy system already running in production.
Let’s start with the conclusion: you can’t evaluate AI-written migration code by test pass rate alone. Anthropic reported on its official engineering blog that, by April 2026, the Rust version of the Messages API was already passing about 98% of its tests. But when compared against production traffic, only about a quarter of inputs matched the old Python version exactly. These figures are self-reported by Anthropic’s official blog, not our own retest, but the problem they illustrate applies to any team doing a migration.
This isn’t an Anthropic press release, and it isn’t a Rust vs. Python performance benchmark. This article breaks the verification method from the official blog into steps you can follow: treat the old system as the oracle (ground truth) for shadow comparison, call the model only once and replay its outputs to the new version, record only the shape of the differences and group them by fingerprint, then use three loops—the inner loop, outer loop, and memory loop—to eliminate the differences one by one.
What you’ll gain: After reading this, you’ll be able to build a verification pipeline that’s more trustworthy than all-green tests in your own API migration, language switch, or legacy-code rewrite projects—and you’ll know exactly where a human has to sign off.

Core Validation Takeaways for AI Code Migration
The table below sums up the facts from this migration most worth remembering, with sources noted for each claim.
| Takeaway | What it means | Source |
|---|---|---|
| Test scale | About 700 existing integration tests | Self-reported by Anthropic’s official blog |
| Tests were loosened | Auditing the tests Claude helped port found more than 100 weakened assertions | Self-reported by Anthropic’s official blog |
| Combinatorial explosion | 20 binary switches map to more than 1 million combinations; at 1 second each, that’s 12 days—and that’s only for one model | Self-reported by Anthropic’s official blog |
| Tests and production were out of sync | When about 98% of tests passed, only about a quarter of inputs in production traffic matched | Self-reported by Anthropic’s official blog |
| Final gains | About 70% less CPU per request, about 20% lower median time to first token, and the service stayed online during migration | Self-reported by Anthropic’s official blog; not independently retested by a third party |
| Share of code manually reviewed | Engineers closely reviewed only about 20% of Claude-generated code | From a Pragmatic Engineer interview; the official blog does not give this figure |
Why All-Green Tests Aren’t Enough for AI Code Migration
The first reason is that tests are coupled to the old implementation. Anthropic’s original integration tests ran in the Python process, with billing and rate limiting mocked directly in memory. When migrating to Rust, the tests themselves had to change—and Claude was the one changing them too. As a result, passing tests might only mean the assertions had been loosened. A later audit did find more than 100 weakened assertions, and this kind of issue is very hard to catch by eye in a PR.
The second reason is that coverage is inherently insufficient. Once there are many feature flags, the number of combinations grows exponentially, and with all the variations inside prompts added on top, no test suite can exhaust them. The typical difference cited by Anthropic is telling: when Python writes JSON tool calls, it escapes characters such as emoji into text code points; Rust outputs them as-is. The prompts on the two sides differ by just a few bytes; the request still succeeds, the model still answers, but the answer may be slightly different. Tests can almost never cover this kind of difference, yet it happens in production every day.

Quick Start for AI Migration Code Verification
Here’s how to break it down into five steps, in order. You don’t have to build all of it at once — get the first two steps right, and you’re already far more reliable than relying on tests alone.
Step 1: Treat the Live Legacy System as the Ground Truth for AI-Migrated Code
The goal of migration is to keep behavior identical to the original, so the most authoritative judge isn’t your test cases — it’s the legacy system that’s still serving real users. The practical approach: feed both the old and new versions the same inputs, then compare intermediate artifacts and final outputs at the key checkpoints. As long as the legacy system is still online, it’s a free, real-time oracle that covers the real distribution.
Conventional shadow-traffic tools assume two things: requests can be safely executed twice, and the service is deterministic. Neither holds in Anthropic’s case, because each request can only be billed once and consumes rate limit only once, and a Large Language Model may give different answers to the same input. If your business involves payments, sending messages, writing to a database, or calling a Large Language Model, you’ll run into these same two problems.
Step 2: Call the model once, then replay the output to the new version
The fix is to let only the old system actually invoke the model and trigger external side effects, then replay the model’s response to the new version so both sides compare downward from the same model output. That eliminates the noise from model randomness: any difference you see must come from different code behavior, not from the model phrasing things differently this time.
In your own project, you can split external dependencies into two categories. Calls that produce side effects or nondeterministic results (billing, rate limiting, models, third-party APIs) run only once, on the old path, and their results get recorded. Purely computational parts (validation, prompt assembly, tokenization, output parsing) run on both sides and are compared checkpoint by checkpoint.
Step 3: Record only the shape of the diff, and group by fingerprint
Privacy and data volume are where shadow comparison most often gets stuck. Anthropic’s approach never reads the raw user request or response at all — it records only the shape of the diff.
| Field | Meaning | Question it answers |
|---|---|---|
step |
Which processing stage, e.g. build prompt | Which part of the code the diff is in |
piece |
Which segment of the prompt | Pinpoints the specific fragment |
first diff |
Position of the first differing byte | Where the diff starts |
python / rust length |
Byte length of the output on each side | Added, removed, or changed |
| fingerprint | Start position plus length difference | Is it the same bug |
A checkpoint answers “where in the code,” and a fingerprint answers “is it the same bug.” The same bug leaves the same fingerprint on every request it affects. Once you group by fingerprint, hundreds of thousands of diff records may map to only a few dozen problem categories — and the investigation workload drops to something you can actually handle.
Step 4: Eliminate Every Category of AI Migration Code Diff with Three Nested Loops
Anthropic runs the script every 10 to 30 minutes, grouping by diff field and notifying a coordinator agent only when a new type appears. The coordinator agent assigns a worker agent to each category of problem and opens a thread in a shared Slack channel, so engineers can follow along and intervene at any time.
| Loop | Where it runs | What it does | Exit condition |
|---|---|---|---|
| Inner loop | Cloud sandbox, two codebases side by side | The agent sees only the fingerprint, constructs its own request that reproduces the diff, fixes Rust, and adds a test that fails on the old code and passes on the new | Local input check and output check both match |
| Outer loop | Real shadow traffic | After the fix passes PR review and is deployed, group by model, prompt cache, tools, extended thinking, and other characteristics, then compare builds with and without the fix | The fingerprint disappears in production |
| Memory loop | Rules and engineering configuration | Distill review conclusions into memories, general rules, CLAUDE.md, lint, and tests |
The same class of problem no longer needs a human reminder |
The input check in the inner loop only constructs the prompt without calling the model, so it returns a result in under a second. An output check was added later, using a fake model to feed a scripted response (say, a single tool call) to both versions at once for comparison. One example of the memory loop: in June, an agent went through about 60 of the team’s review comments and distilled a set of rules, which engineers revised and put into CLAUDE.md. The team later added one more merge check: any Python change must come with a matching Rust change, or you have to request an exemption.
Step 5: A human has to be the gate at the PR stage
The validator can only tell whether the output is consistent — it can’t tell whether the fix should ship. There was a textbook counterexample in mid-May: the web search tool’s description had to come from an undisclosed internal service, and at that point Rust wasn’t wired up to that service yet. An agent proposed copying the description text straight into the file so the prompt would line up, and local verification passed too. The engineer rejected the approach: before shipping, Rust would have to call that service no matter what — copying the text was just temporary code that would get thrown away.
The rejection was written down as a memory covering the decision, the reasoning, and the correct approach. The correct approach took a few weeks to implement, and during that stretch the same bug kept reappearing under a new fingerprint. When the agent checked the memory, it recognized this as a known issue, linked the record, and didn’t write yet another workaround. Another example: the team laid down a rule to “port it exactly as Python does it,” and when the agent went back and audited against that rule, it found 7 more places where the implementation had been guesswork.

How to Set Up Your Own AI Code-Migration Verification Loop
In this loop, every time the agent guesses a cause, builds a reproduction request, or derives rules from review comments, it has to call a model. And it’ll do that many times a day. So before you start building, make sure model access can be called repeatedly and reliably, then assign each type of call to the right model.
It’s easier to manage a single API key for access. Here are a few things you’ll need to configure in Claude Code or a self-built agent:
- Anthropic native format: Set the Base URL to
https://api.apiyi.com; requests will go to/v1/messages. Don’t add/v1to the end of the Base URL, or it’ll become/v1/v1/messagesand return a 404. - OpenAI-compatible format: If your self-built agent uses the OpenAI SDK, the request endpoint is
https://api.apiyi.com/v1/chat/completions. - Claude Code: Point
ANTHROPIC_BASE_URLto the Base URL above, and put the API key in the corresponding authentication environment variable. For the exact variable name, follow the platform’s Claude Code setup instructions. - Model division of labor: Use
claude-opus-5-5for the coordinator agent and rule induction,claude-sonnet-5-5for the worker agent to fix code, andclaude-haiku-5-5for batch-building reproduction requests and doing the initial screening of diff records.
🚀 Quick-start tip: You can apply for free trial credits at APIYI apiyi.com. Pick one of the most common fingerprints and run only the inner loop once to validate the whole chain. Once you’ve confirmed that both the reproduction request and the fix workflow work end to end, connect the outer loop and memory loop. The platform’s Claude uses AWS Bedrock official access by default, with a direct Anthropic official key as a fallback; both routes are official forwarding.
How to calculate token costs for AI-based migration code validation
The cost mainly comes from three places: repeatedly guessing and reproducing inside the inner loop, analyzing grouped results in the outer loop, and reading a large number of review comments in the memory loop to summarize rules. Below is the price table; the data date is 2026-11-25, and the unit is USD per million tokens.
| Model | Input | Output | Cache read | Suitable loop stage |
|---|---|---|---|---|
claude-opus-5-5 |
$4 | $20 | $0.2 | Coordinating agents, summarizing rules, locating complex differences |
claude-sonnet-5-5 |
$2 | $10 | $0.1 | Worker agents writing fixes, adding tests |
claude-haiku-5-5 |
$0.1 | $0.5 | $0.01 | Batch reproduction requests, fingerprint initial screening; after a single input exceeds 100K tokens, input is billed at $0.5 |
When estimating, you can calculate it as “cost per call × number of calls per round × number of rounds per day.” Here’s a hypothetical example: a worker agent’s single fix call has 20K input tokens and 2K output tokens, costing about $0.06 with claude-sonnet-5-5. The same volume with claude-haiku-5-5 costs less than $0.01. In the inner loop, the same code context is read repeatedly; after enabling prompt caching, the cache read price is only one-twentieth of the input price, and the savings are considerable. One thing to note: claude-haiku-5-5 moves to a higher pricing tier once a single input exceeds 100K tokens, so large-file contexts either need to be split or handed to a larger model.
💰 Cost tip: For models and prices, refer to the model list on the APIYI apiyi.com platform. The overall cost is about 85% of the official website price, making it suitable for validation loops that require long-running, high-frequency model invocation.
FAQ
Q1: What’s shadow comparison for AI-migrated code?
Shadow comparison feeds the same real inputs through both the old and new versions and compares results at key checkpoints, with the production old system acting as the ground-truth answer. It doesn’t replace testing — it covers the real-traffic distribution that tests can’t reach.
Q2: The AI-migrated code passes 98% of tests, so why is only a quarter of it consistent in production?
Per Anthropic’s official blog post, there are two reasons: the tests were coupled to the old implementation, so when the AI rewrote the tests it weakened more than 100 assertions; and the sheer number of feature combinations means test coverage is incomplete. Differences as small as a few bytes — emoji escaping, for instance — are hard for tests to catch, yet very common in production.
Q3: Calls are billed and model answers are nondeterministic — how do you do shadow comparison?
Calls with side effects and nondeterminism are executed only once, on the old path; record the results and replay them to the new version, so both sides compare starting from the same model output. That way billing isn’t duplicated, and model randomness doesn’t interfere.
Q4: Does AI migration code comparison leak user data?
You can do it without reading the raw text. Record only the checkpoint (stage, fragment, position of the first differing byte, lengths on both sides) and the fingerprint (start plus length difference). The agent never sees the original request — it can only construct its own reproduction request from the fingerprint.
Q5: How do I get Claude Code or a self-built agent to run this verification loop?
Start by connecting a model endpoint that can be called at high frequency. On APIYI apiyi.com, a single key lets you call `claude-opus-5-5`, `claude-sonnet-5-5`, and `claude-haiku-5-5`; put the Base URL in Anthropic’s native format as `https://api.apiyi.com`, without adding `/v1`. I’d suggest running just the inner loop on the free quota first, then scaling out once the pipeline works.
Q6: Once all the validators agree, can I just ship it?
No. Validators can only tell you the outputs match; they can’t judge whether the fix is reasonable. In the web search counterexample, the approach of copying the text so the prompt matched passed local verification, but it was throwaway code destined for the bin — in the end, an engineer stopped it at the PR stage.
Q7: What are the limitations of this approach?
It requires the old system to stay online and to support recording and replaying external calls, and setting it up has its own engineering cost. It also only proves “same as before” — bugs in the original system get preserved as-is. Token consumption grows linearly with the number of loops, so you can pick different model sizes per stage on APIYI apiyi.com to control cost. Also, the interview mentions that engineers only read about 20% of the code carefully — that’s just what the interview said, and it shouldn’t be taken as a reason to review less code.
AI Migration Code Verification: Key Takeaways
- All tests green doesn’t mean the migration is correct: When the official self-report claimed a 98% pass rate, only about a quarter matched in production.
- Audit AI-modified tests separately: More than 100 weakened assertions turned up in the ported tests.
- The old system is the ground truth: Shadow comparison covers real traffic, filling in the blind spots left by combinatorial explosion.
- Run the model only once: Record the outputs and replay them to the new version, which also rules out randomness and duplicate billing.
- Fingerprints determine triage efficiency: Checkpoints pinpoint the code location, fingerprints merge the same bug.
- Humans are the gate at the PR and rule layer: The verifier handles consistency; engineers decide whether it should ship.
- Get the inner loop working first: With a single APIYI key, allocate Opus, Sonnet, and Haiku by stage.
Summary
The key to verifying AI-migrated code is swapping out the judging standard:
- From tests to real traffic: Tests are a necessary condition; the old system in production is the more complete oracle.
- From reading the text to reading the shape: Checkpoint plus fingerprint solves both the privacy problem and the triage-scale problem at once.
- From humans chasing diffs to humans setting rules: The three-layer loop hands repetitive work to the agent, while humans hold the line on the PR and on “what counts as correct.”
One line from the Anthropic blog sums it up: writing code is no longer the bottleneck — how fast you can verify the results is. I’d suggest starting with the module in your own project that has the most diffs, and getting the inner loop working first. Try validating the pipeline through APIYI at apiyi.com with the free quota, then pick the right model mix based on your call volume.
📚 References
-
Anthropic Official Engineering Blog: Migrating our Messages API to Rust
- Link:
anthropic.com/research/migrating-api-to-rust - Note: The primary source for all the official figures and verification methods in this article
- Link:
-
The Next Web: Anthropic Messages API Rust Migration Coverage
- Link:
thenextweb.com/news/anthropic-claude-messages-api-rust-migration - Note: Secondary reporting on the 98% test pass rate and the one-quarter consistency
- Link:
-
The Pragmatic Engineer Interview
- Link:
newsletter.pragmaticengineer.com/p/how-anthropic-builds-software-in - Note: The figure of roughly 20% of code being carefully reviewed comes from the interview; the official blog doesn’t include this number
- Link:
Author: APIYI Technical Team
Technical exchange: Feel free to reach out to us through the APIYI homepage — we’d love to swap notes on practical experience validating code during AI migrations