Tooling · XiaoHu Explains

Anthropic opens up its six-step code migration playbook: a million lines of Bun moved from Zig to Rust in two weeks

The templates and prompts are open source. The Bun job burned 5.9 billion uncached input tokens — roughly $165,000 at API list prices
The one-minute version
  • Rewriting a production codebase in another language is supposed to take four years, three to four million dollars, and a good chance of stalling halfway. Anthropic's engineers shipped 10 packages in the past month; the Bun job was a million lines, done in under two weeks, with the entire existing test suite green before merge
  • The whole method rests on one line: don't fix the code, fix the loop that produced it. When the same mistake shows up across dozens of files, the correct move is to add a line to the rulebook and regenerate the batch — not to patch file by file
  • Before you translate anything, build an oracle. Pull the existing tests that can run against both the old and new code, rewrite them as assertions, then check the oracle against deliberately broken code. An oracle that can't catch damage isn't an oracle, and without one you have no definition of "done"
  • The engineering details are worth copying outright: the work queue recomputes from disk every time, so an interrupted run resumes; implementation runs on a small model and review on a large one; two reviewers work in separate contexts and a third agent breaks ties; anything untranslatable gets a uniform // TODO(port) and waits
  • Both the bill and the payoff are on the record. Bun: 5.9 billion uncached input tokens plus 690 million output tokens, about $165,000 at API list prices. Mike Krieger's project: compiles dropped from 8 minutes to roughly 2 seconds, binary startup got 6× faster, and an entire deployment pipeline went away
This is Anthropic writing about its own models. Both case studies star Anthropic employees, and every number comes from Anthropic. Read the figures below with that in mind — we won't flag it again in the text.
1Opening

Ten packages in a month

A million lines of code moved to a new language in two weeks, with the full existing test suite passing in CI before the merge.

That's from a hands-on writeup posted by ClaudeDevs, Anthropic's official account, covering how the company spent the past month using Claude Code to migrate production codebases from one language to another. The post lays out the entire process, templates included, for anyone to copy. The tools: Claude Fable 5, Claude Opus 4.8, and Claude Code's dynamic workflows.

Over the past month Anthropic's developers finished 10 packages, ranging from tens of thousands to hundreds of thousands of lines. The post details two of them.

Bun · Zig → Rust
1M linesof code produced, in under two weeks
100%pass rate for Bun's existing test suite in CI, before merge
19regressionsSomething that used to work broke after the code changed. Different from a bug in a new feature. surfaced after merge, all since fixed
Junethe Rust build has been shipping inside Claude Code
Mike Krieger · Python → TypeScript
One weekendto produce 165,000 lines of TypeScript
Hundredsof agents used across the migration
8phase gatesCut the process into stages and put a check at the end of each one. Fail it and you don't advance., plus 3 rounds of adversarial review
Command by commanda final diff of every command's output, old side against new

The Bun migration was done by Jarred Sumner, Bun's co-founder, now a member of technical staff at Anthropic. The Python one was Mike Krieger, Instagram co-founder, now co-lead of Anthropic Labs.

The GitHub page for Jarred Sumner's million-line PR
The GitHub page for Jarred's million-line PR. Image: ClaudeDevs
2What changed

Why nobody used to attempt this

Jarred picked Zig originally because it delivered C-level performance while staying simple enough — in his words, that simplicity is what let one person write Bun in a year, from a cramped Oakland apartment, before large models existed. Simplicity has a price, and the price never went away. Bun's CLI now clears ten million downloads a month, and Claude Code leans on it heavily internally.

As recently as last quarter, that price still wasn't enough to justify freezing a roadmap and committing resources to a multi-quarter project.

Before last quarter
  • Four years and $3–4M in engineering resources
  • Roadmap frozen for the duration
  • Two codebases maintained in parallel for quarters, sometimes years
  • Worst case: 90% parity, and more trouble than before you started
Now
  • Tens to hundreds of thousands of dollars — still real money
  • Worst case: delete the branch and try again
  • The justification no longer has to be "migrate or die"
  • A memory-bug patch that's been sitting in the changelog for a year, or one long-standing bottleneck, is enough

A bottleneck is exactly what pushed Mike's project over the line. His team's internal tool had to ship as a single executable, and the Python toolchain took about eight minutes to compile per platform — thirty minutes of waiting for the full build matrix on every release. In TypeScript the same compile takes about two seconds, the executable starts 6× faster, and the team retired an entire standalone deployment pipeline while they were at it.

3Core principle

When the same mistake keeps appearing, change the rule

The most valuable sentence in the whole piece:

The core insight is that you don't fix the code. You fix the process (loop) that produced the code.— ClaudeDevs

In practice: a review agent catches the same mistake across dozens of files, and your hands stay off those files. You add a line to the rulebook and regenerate the affected batch. The rulebook only grows over the course of the project, and the code is never hand-patched to satisfy it.