On July 16, Anthropic published an engineering write-up of an AI-driven code migration: moving Bun's ~1 million lines of Zig code to Rust using Claude Code, led by Jarred Sumner (Bun co-founder and Anthropic MTS). The migration took under two weeks, consumed 5.9 billion input tokens and 690 million output tokens, and cost roughly $165,000 in API fees. After the migration, the 100% existing test suite (written in third-party TypeScript) passed in CI; 19 regressions surfaced post-merge and were all fixed. Memory usage during repeated builds fell from 6,745 MB to 609 MB, binaries shrank 19%, and HTTP serving got 2-5% faster. This is the first time a million-line-scale migration has been publicly documented as an engineering case with a concrete cost and timeline.
Project Overview
| Dimension | Figure | |------|------| | Lead | Jarred Sumner (Bun co-founder + Anthropic MTS) | | Source language | Zig | | Target language | Rust | | Codebase size | ~1 million lines | | Toolchain | Claude Code + Claude Fable 5 + Opus 4.8 + Dynamic Workflows | | Duration | Under 2 weeks | | Timeline | June 2026 execution; methodology published July 16 |
Test and Quality Data
| Dimension | Figure |
|------|------|
| CI pass rate (pre-merge) | 100% (test suite written in third-party TypeScript) |
| Post-merge regressions | 19, all fixed |
| Code inside unsafe blocks | ~4% |
| Memory across 2,000 repeated builds | 6,745 MB → 609 MB (~91% reduction) |
| Binary size | 19% smaller on Linux / Windows |
| HTTP serving and real workloads | 2-5% faster (including next build, tsc) |
| Memory leaks detectable by built-in tools | All fixed |
Token and Cost Data
| Item | Amount | |------|------| | Uncached input tokens | 5.9 B | | Output tokens | 690 M | | API cost (at Anthropic's then-current pricing) | ~$165,000 |
Parallel Case: Mike Krieger's Python → TypeScript Migration
Mike Krieger, co-lead of Anthropic Labs, migrated 165,000 lines of Python to TypeScript over a weekend in June 2026. The bulk of the work used only 27 million input tokens. The supporting process involved hundreds of agents, 8 stage gates, and 3 rounds of adversarial review, finishing with parity checks that byte-for-byte diffed each command's output against the original Python version.
Side benefits: per-platform compilation dropped from 8 minutes to 2 seconds, binary startup got 6x faster, and a standalone deployment pipeline could be retired.
Deep Dive
The Six-Step Process: Fix the Process, Not the Code
Anthropic's structure-preserving six-step method:
1. Build the rules book + dependency graph + divergence checklist 2. Stress-test the rules (small-scale dry runs, discard artifacts) 3. Translate everything (implement + review + fix loops) 4. Compile (fix compilation errors) 5. Run (fix smoke-test crashes) 6. Behavior matching (compare test results against the original codebase)
Key design: the loop is the product; the code is a byproduct.
In Step 3, the work queue is mechanized: a batch script checks whether translation artifacts have landed on disk → slices the backlog → assigns it to implementation agents. Because the queue is rebuilt from disk, it is naturally resumable. When the same error recurs, what gets fixed is the rules book, not a code patch — per Anthropic's most important line: "You don't fix the code. You fix the process (loop) that produced the code."
Why Large-Scale Migrations Are Uniquely Suited to AI
Anthropic lists five required properties — remove any one and it fails:
1. Naturally parallelizable — files/crates are independent units 2. Complete context — the old code itself is the best specification 3. Built-in judge — a test suite provides objective verification 4. Self-generating queue — compile errors and test failures are the next tickets 5. Strong consistency requirements — any violation becomes a queue item; drift cannot hide
Million-line migrations hit all five, which is why agents excel here and underperform on open-ended exploration.
What the $165,000 Figure Means
Traditional million-line migration cost: $3-4 million over a 4-year project.
Anthropic's Claude Code run: $165,000 in under two weeks.
At least an order of magnitude cheaper and faster.
More important than the single-project cost is that the barrier to approval has collapsed — such migrations once required existential business justification; now a "memory bug unfixable for a year" or "a chronic performance bottleneck" may suffice.
This is an evolution that turns code modernization from a project worth approving into a weekend-assignment-scale task.
Adversarial Review, Mechanical Verification
A recurring counterintuitive principle: use large models (Fable 5) for review, small models (Sonnet 5) for translation.
Why not the biggest model everywhere? Token consumption concentrates in the loop, and loop frequency determines total cost — big models go where frequency is high but per-unit cost is controllable (review), small models where volume is high (implementation).
Verification must not rely on models — compilers, diffs, and test suites are the judges. Any step where a model grades its own work yields low reliability, high token burn, and untrustworthy results.
A Disk-Backed Work Queue Is the Key to Scale
A Step 3 detail determines whether this scales to a million lines: the backlog is read from disk and removed from disk when done.
This makes the work queue recoverable — a crash at any moment resumes on next startup with no global coordination required. The same design means scaling from 10 files to 1,000 needs no orchestration rewrite — as long as disk space exists, the loop continues.
Why This Matters
1. Million-line migrations went from years to weeks — legacy modernization projects no longer have the "we don't have time to rewrite" excuse.
2. At least an order-of-magnitude cost reduction — $165K vs $3-4M collapses the approval barrier; many long-postponed modernization projects may now start.
3. Anthropic open-sourced the full toolchain — the migration starter kit (rules book / dependency-graph prompts / divergence checklist prompts / stress-test prompts / build daemon scripts) is at github.com/anthropics/code-migration-kit-with-claude-code; teams can fork it directly.
4. "Fix the process, not the code" — this is the core methodology of AI coding product competition in H2 2026. Differentiation for AI IDEs / agents / harnesses will revolve around workflow design.
Risks and Open Questions
- Two successful million-line migrations ≠ every project will work this way. Code organization, quality, test coverage, and dependency complexity all matter.
- 19 post-merge regressions despite 100% CI pass: the uncovered real-world scenarios themselves need expansion — that is the real risk of such migrations.
- $165K in API cost ≠ total self-build cost — enterprises adopting this process need upfront engineering investment; real total cost may be 2-3x higher.
- The small-model-translates / big-model-reviews split may not generalize — other language pairs with different code organization and dependency shapes could differ completely.
- Anthropic Engineering, AI code migration blog: https://claude.com/blog/ai-code-migration
- Open-source toolkit: https://github.com/anthropics/code-migration-kit-with-claude-code
- Code modernization plugin: https://github.com/anthropics/claude-plugins-official/tree/main/plugins/code-modernization
- Dynamic Workflows introduction: https://claude.com/blog/introducing-dynamic-workflows-in-claude-code
- Bun's official migration post: https://bun.com/blog/bun-in-rust
---
Sources: