English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Anthropic Migrates Bun's Million Lines of Zig to Rust with Claude Code in Under Two Weeks

Forum topic · 小凯 · 2026-07-19

Summary

A Chinese tech forum post details Anthropic's engineering case study (published July 16) describing how Jarred Sumner—Bun co-founder and Anthropic MTS—migrated roughly 1 million lines of Bun's Zig code to Rust using Claude Code in under two weeks. The effort consumed 5.9 billion input tokens and 690 million output tokens, at an estimated API cost of about $165,000. Before merge, the existing third-party TypeScript test suite passed 100% in CI; 19 regressions surfaced afterward and were all fixed. Memory usage for 2,000 repeated builds dropped from 6,745 MB to 609 MB (~91% reduction), binaries shrank 19% on Linux/Windows, and HTTP serving improved 2–5%. The post also covers a companion case: Anthropic Labs' Mike Krieger migrating 165,000 lines of Python to TypeScript over a weekend. Key methodology takeaways include a six-step structure-preserving migration loop, the principle of fixing the process rather than the code, disk-based resumable work queues, large models for review and smaller models for translation, and mechanical verification via compilers, diffs, and test suites. Anthropic open-sourced its migration toolkit. The author argues this collapses traditional migration costs (est. $3–4M over years) by an order of magnitude, while noting risks: untested scenarios, hidden engineering costs, and non-universal model-role division.

Anthropic Migrates Bun's Million Lines of Zig to Rust with Claude Code in Under Two Weeks

> Today in AI: On July 16, Anthropic published a post disclosing that it used Claude Code to migrate Bun's 1 million lines of Zig code to Rust. Jarred Sumner (Bun co-founder and Anthropic MTS) completed it in under two weeks, consuming 5.9 billion input tokens + 690 million output tokens at an estimated API cost of ~$165,000. Post-migration, 100% of the existing test suite passed CI; 19 regressions surfaced after merging and were all fixed. Memory usage dropped from 6,745 MB to 609 MB, binaries shrank 19%, and HTTP serving sped up 2–5%. This is the first public engineering write-up of a million-line-scale migration framed as 'a few hundred thousand dollars + under two weeks.'

The Project

| Dimension | Figure | |------|------| | Lead | Jarred Sumner (Bun co-founder + Anthropic MTS) | | Source language | Zig | | Target language | Rust | | Code size | ~1 million lines | | Toolchain | Claude Code + Claude Fable 5 + Opus 4.8 + Dynamic Workflows | | Execution time | Under 2 weeks | | Timeline | June 2026; methodology published July 16 |

Testing and Quality Data

| Dimension | Figure | |------|------| | CI pass rate (pre-merge) | 100% (suite written in third-party TypeScript) | | Post-merge regressions | 19, all fixed | | Code inside unsafe blocks | ~4% | | Memory for 2,000 repeated builds | 6,745 MB → 609 MB (~91% drop) | | 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 |

Tokens and Cost

| Item | Amount | |------|------| | Uncached input tokens | 5.9 B | | Output tokens | 690 M | | API cost (at Anthropic's then-current pricing) | ~$165,000 |

Companion 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 took only 27 million input tokens. The supporting process: hundreds of agents, 8 stage gates, 3 rounds of adversarial review, finishing with parity checks that byte-diffed every command's output against the original Python version.

Post-migration side benefits: single-platform compilation went from 8 minutes to 2 seconds, binary startup is 6x faster, and a separate deployment pipeline could be retired.

Deep Dive

The Six-Step Process: Fix the Process, Not the Code

Anthropic's structure-preserving migration method has six steps:

1. Build the rulebook + dependency graph + diff checklist 2. Stress-test the rules (small-scale dry runs, discard outputs) 3. Translate everything (implement + review + fix loop) 4. Compile (fix compile errors) 5. Run (fix smoke-test crashes) 6. Match behavior (compare test results against the original codebase)

Key design: the loop is the product; the code is a byproduct.

Step 3's work queue is mechanized: a batch script checks whether translated artifacts 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 keeps recurring, the rulebook gets fixed, not the code patched—this is the most important line in Anthropic's post: "You don't fix the code. You fix the process (loop) that produced the code."

Why Large-Scale Migration Is Uniquely Suited to AI

Anthropic lists five properties, all of which must hold:

1. Naturally parallelizable — files/crates are independent units 2. Complete context — the old code is itself the best spec 3. Built-in judge — the test suite provides objective validation 4. Self-generating queue — compile errors and test failures are the next work items 5. Strong consistency requirements — any violation becomes a queue item and cannot silently drift

Million-line migrations hit all five, which is why agents perform exceptionally well here and poorly on open-ended exploration.

What the $165,000 Figure Means

Traditional million-line migration cost: $3–4 million, a 4-year project.

What Anthropic ran with Claude Code: $165,000 + under two weeks.

At least an order-of-magnitude reduction in both cost and time.

More important than the single-project cost is that the project-approval threshold has collapsed—previously such a migration required a survival-level business driver; now a "memory bug we couldn't fix for a year" or "a chronic performance bottleneck" may suffice.

This is a tooling evolution that turns code modernization from a fundable project into a weekend-assignment-level task.

Adversarial Review, Mechanical Verification

A counterintuitive principle the post repeatedly emphasizes: 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—putting the large model in the "high-frequency but bounded unit cost" review slot and the small model in the "high-frequency, high-volume" implementation slot maximizes value per token.

Verification cannot rely on models—the compiler, diffs, and test suites are the judges. Any step where a model grades itself yields high failure probability, more token burn, and untrustworthy results.

Mechanized Work Queues Are the Key to Scale

A small detail in Step 3 determines whether this scales to a million lines: the backlog is read from disk and reduced from disk.

This makes the work queue recoverable—crash at any moment, and the next run picks up exactly where it left off, with no global coordination of any kind. The same design means scaling from 10 files to 1,000 requires no orchestration rewrite—as long as there's disk space, the loop keeps going.

Why This Matters

1. Million-line migrations went from years to weeks—legacy system 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; the approval threshold has collapsed, and many long-postponed modernization projects may now start. 3. Anthropic open-sourced the full toolchain—the migration starter kit (rulebook / dependency-graph generation prompts / diff checklist prompts / stress-test prompts / build daemon scripts) is at github.com/anthropics/code-migration-kit-with-claude-code, ready to fork. 4. "You fix the process, not the code"—this is the core methodology for 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 can do this. Code organization, quality, test coverage, and dependency complexity all affect outcomes.
  • 19 post-merge regressions despite 100% CI means the test suite's coverage of real-world usage itself needs expansion—this is migration's genuine risk.
  • $165k of API cost ≠ total build cost—enterprises adopting this process need upfront engineering investment; real total cost could be 2–3x higher.
  • Small models translate / large models review may not generalize: different language pairs, code organizations, and dependency shapes may demand entirely different splits.
  • ---

    Sources:

  • 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
  • Official Bun migration post: https://bun.com/blog/bun-in-rust

Tags

#anthropic#claude-code#bun#zig-to-rust#code-migration#ai-agents#software-modernization#engineering-costs

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/178442258