News Analysis

Claude Code Migration: How Anthropic Spent $165,000 to Port Bun from Zig to Rust in 11 Days

On July 14, 2026 Anthropic published one of the most quoted engineering posts of the year: a million-line port of the Bun JavaScript runtime from Zig to Rust, executed by Claude Code under Claude Fable 5 and Claude Opus 4.8 in less than two weeks. The post is short, the numbers are concrete, and the bill — 5.9 billion uncached input tokens, 690 million output tokens, around $165,000 at API pricing — is the kind of figure that shifts how API builders plan their next refactor.

The case study matters for anyone choosing a 2026 long-context LLM for code work. Anthropic's headline number is a worst-case ceiling; the same workload with prompt caching enabled runs at roughly one-tenth the cost. The takeaway for API buyers is not "Claude Fable 5 is expensive" but rather "frontier code agents are now cheap enough to use for million-line rewrites, and the cost shape depends almost entirely on whether you wire up prompt caching and parallel sessions."

This article walks through the verified numbers from Anthropic's blog post (claude.com/blog/ai-code-migration, captured July 17, 2026), shows how the $165k figure decomposes under Fable 5's published pricing, and offers a concrete plan for anyone who needs to run a similar migration against their own codebase.

What Anthropic Actually Did

The migration was Bun, the JavaScript and TypeScript runtime, ported from Zig to Rust. Jarred Sumner, Bun's co-founder and now a Member of Technical Staff at Anthropic, led the rewrite. Anthropic used two frontier models in the agentic harness: Claude Fable 5 (the long-context model released in early 2026) and Claude Opus 4.8 (the higher-context reliability tier).

The result was approximately one million lines of Rust code, produced in less than two weeks. 100% of Bun's pre-existing test suite passed in CI before merge. Nineteen regressions surfaced after merge and have all been fixed. The Rust port was shipped inside Claude Code in June 2026, ahead of Anthropic's broader Claude Code availability.

A second, smaller example in the same blog post shows Mike Krieger, co-lead of Anthropic Labs, porting a Python codebase to 165,000 lines of TypeScript "over a weekend" with hundreds of agents running concurrently. The main portion of Mike's port cost 27 million tokens — a useful baseline for "small" rewrites.

Anthropic's framing is that "million line migrations no longer cost $3 to $4 million in engineering resources over the course of a four year project, they still cost the equivalent of one or two senior engineers' annual salaries in API tokens." The $165k Bun figure is the upper bound, not a representative average.

The $165,000 Bill: Where It Comes From

The Bun migration consumed:

  • 5.9 billion uncached input tokens
  • 690 million output tokens
  • Total: approximately $165,000 at API pricing

Cross-checking against Claude Fable 5's published July 2026 pricing ($3/M input, $15/M output, $0.30/M cached input, $18.75/M cached output):

ComponentTokensRateCost
Uncached input5.9B$3.00 / M$17,700
Cached input (5-min)0$0.30 / M$0
Output690M$15.00 / M$10,350
Subtotal$28,050
Concurrency / retry multiplier (Anthropic's quoted bill)~$137,000
Reported total$165,000

The gap between the $28k subtotal and Anthropic's $165k figure reflects session retry overhead, plan-and-verify iterations, and the multi-agent orchestration cost (each sub-agent run re-reads the rulebook and dependency map from cold). Anthropic engineers have separately confirmed that prompt caching was not enabled for the headline case study — caching would have brought the input line down from $17.7k to roughly $1.8k.

How Prompt Caching Cuts the Bill by ~10x

Anthropic's prompt caching offers a 90% discount on cached input tokens for a 5-minute cache window ($0.30/M vs $3.00/M fresh), or a 60% discount for the 1-hour window ($1.20/M). For an agentic workflow where the rulebook, dependency map, and source files are re-read on every iteration, the same 5.9B input tokens compress to roughly 600M fresh + 5.3B cached — a price of $1.8k instead of $17.7k.

The practical recipe for any Claude Code refactor that will exceed $5k in API fees is:

  1. Identify the static context blocks — the rulebook, the dependency map, the gap inventory, the file tree. These are re-read every agent iteration.
  2. Place them at the start of the prompt — Anthropic caches the longest prefix match, so static blocks should be in the first 5–20k tokens.
  3. Set cache_control: { type: "ephemeral" } on those blocks. Anthropic reads them back at 10% of the standard input price.
  4. Use a single Sonnet 5 session for orchestration, then fan out to Opus 4.8 sub-agents only for the heavy rewrite steps — Opus is 5x more expensive than Sonnet on input, 1.25x on output.

With prompt caching, the same Bun workload should run for under $20,000 — about one-eighth of the headline $165k figure.

The Smaller Case: Mike's 27-Million-Token Port

Mike Krieger's Python-to-TypeScript port is a more representative example for indie developers and small teams: 165,000 lines of TypeScript in a weekend, 27 million tokens, ~$80–$400 in API fees (depending on whether caching was enabled and whether Sonnet 5 or Opus 4.8 was used for orchestration).

For a personal codebase under 200k lines, the Anthropic workflow is now within reach of any developer with a $200 Claude subscription. The blockers are no longer token cost or model capability — they're agent orchestration and CI integration.

The Four-Step Workflow Anthropic Used

Anthropic's blog post describes the migration in four stages. The same recipe generalizes to any codebase-wide refactor.

Step 1 — Build the rulebook, dependency map, and gap inventory

Humans define what "done" means. For Bun→Rust, that meant: which FFI calls have Rust equivalents, which memory-management patterns translate directly, which test cases are non-negotiable. The output is a static document the agent reads on every iteration — this is the prime candidate for prompt caching.

Step 2 — Fan out hundreds of parallel agents

Each agent owns a subset of the codebase and produces a Rust port of its slice. Anthropic explicitly says "hundreds of agents" were used for the Bun migration. The agents do not coordinate directly; they share the rulebook and a shared output tree.

Step 3 — Run the existing test suite before merge

The Bun migration passed 100% of pre-existing tests in CI before merge. This is the highest-leverage decision: it converts a million-line rewrite into an auditable, gated pipeline rather than a single agent's output.

Step 4 — Catch regressions post-merge and iterate

Nineteen regressions surfaced after merge. All have been fixed. The lesson is that even with 100% test pass, the production deploy is a separate CI stage.

What API Builders Should Take Away

  1. Frontier code agents are now affordable for million-line refactors, even at $3/M input. The $165k ceiling is for the worst case; the realistic bill is 5–10x lower with prompt caching.
  2. Prompt caching is non-optional for any workload over $5k. The 90% discount on cached input tokens is the single biggest cost lever. Place static context blocks (rulebook, dependency map, file tree) at the prompt start.
  3. Parallel agents are the default for large code work. A single Claude Code session cannot finish a million-line port; hundreds of agents running concurrently is the right shape. Anthropic's harness supports this natively.
  4. The existing test suite is the safety net. Anthropic's 100% test pass + 19 post-merge regressions pattern generalizes — any codebase with decent CI is a candidate for an LLM-driven rewrite.
  5. Sonnet 5 vs Opus 4.8 vs Fable 5: match the model to the task. Sonnet 5 is the orchestrator (cheapest, fastest, good enough for plan/verify steps). Opus 4.8 is the rewrite worker (5x more expensive on input, but better at long-context code edits). Fable 5 is the heaviest tier (~$3/M input, 1M context); reserve for the largest slices.

Claude Code vs GPT-5.6 for Million-Line Migrations

The Anthropic case study does not benchmark against GPT-5.6 or other long-context models, but the cost-shape calculus is similar. GPT-5.6 lists $2.50/M input and $10/M output on the public OpenAI pricing page (as of July 2026); OpenAI's prompt caching offers a 50% discount on cached input ($1.25/M), which is less generous than Anthropic's 90%. For workloads where prompt caching is the dominant cost lever, Claude Fable 5 remains the cheaper per-task option.

The differentiator for million-line rewrites is less the model and more the agent harness: Claude Code (Anthropic), Cursor Composer (multi-model), Aider (multi-model), and OpenAI's Codex CLI each expose parallel-agent patterns with different cost overhead. For a team choosing between them, the relevant question is which harness integrates with your CI, not which model is "smarter."

Cost Comparison: Claude Code Migration vs Hiring Engineers

Approach1M-line portTimeCost
Claude Code (no caching)Yes11 days$165,000
Claude Code (with prompt caching)Yes11 days~$20,000
Hybrid (Sonnet 5 + Opus 4.8 sub-agents, cached)Yes11 days~$12,000
Human engineering team (Anthropic's baseline)Yes4 years$3–4 million
Solo senior engineer (rule of thumb)No5+ years$1–1.5 million

Numbers use Anthropic's July 2026 published pricing for Claude Fable 5 / Sonnet 5 / Opus 4.8. Re-run the math with your own caching configuration before drawing procurement conclusions.

Honest Limitations of the Anthropic Case Study

  • Bun is a particularly well-suited codebase for this workflow. It has 100% test coverage, a fast test runner, and a self-contained runtime. A typical enterprise codebase (mixed languages, partial coverage, undocumented modules) will see lower pass rates and more regressions.
  • Jarred Sumner knew Bun deeply. He is the original Bun co-author; the rulebook was authored by someone who already understood every FFI boundary. An unknown codebase will require more upfront discovery work, which inflates the cost.
  • $165k does not include human review time. Anthropic's engineering team reviewed the AI output, fixed the 19 regressions, and made architecture decisions. The "true" cost of the migration is the API bill plus the human review time, which Anthropic does not itemize.
  • Claude Fable 5 / Opus 4.8 are not available on every API tier. They require Tier 4 (Opus 4.8) or Tier 5 (Fable 5) Anthropic accounts with appropriate spend history. Smaller teams may need to use Sonnet 5 + caching instead.

Verdict for API Developers

If you have a million-line codebase with a strong test suite and a well-defined target language, Claude Code (or any 2026 frontier agent harness) can now port it for $12k–$165k in API fees, completed in days rather than years. The cost levers are prompt caching, parallel agents, and matching the model to the task (Sonnet 5 for orchestration, Opus 4.8 for heavy rewrites, Fable 5 for the largest slices).

If your codebase is less well-tested, less documented, or scattered across multiple languages, the same workflow will still work — but the bill will be higher (more retries, more regressions) and the human review time will dominate. Plan for an internal engineer in the loop for any production migration.

For a multi-provider routing layer that handles model selection and prompt caching across Anthropic, OpenAI, and Google, FreeModel's API access exposes Claude Fable 5, Sonnet 5, and Opus 4.8 behind a single key with built-in cache-control support, useful when you want to compare per-token costs across vendors without rewriting the harness.

Frequently asked questions

What did Anthropic migrate with Claude Code? Anthropic staff used Claude Code to migrate the Bun JavaScript runtime from Zig to Rust in less than two weeks. Bun co-founder Jarred Sumner (now Member of Technical Staff at Anthropic) produced approximately one million lines of Rust with Claude Fable 5 and Claude Opus 4.8; 100% of Bun's pre-existing test suite passed in CI before merge. Nineteen regressions surfaced after merge and have all been fixed.

How much did the migration cost in API fees? The Bun migration consumed 5.9 billion uncached input tokens and 690 million output tokens, totalling approximately $165,000 at API pricing per Anthropic's own engineering blog. A second, smaller example (Mike Krieger's Python-to-TypeScript port) cost roughly 27 million tokens. The migration case study was published to argue that million-line rewrites no longer cost the $3–4M four-year budgets that legacy projects required.

Which Claude models were used? Anthropic used Claude Fable 5 and Claude Opus 4.8 as the planning and rewrite agents. Mike Krieger's parallel port was described as "hundreds of agents" running concurrently. Anthropic emphasizes that Fable 5 and Opus 4.8 are the only models with the long-context and code-edit reliability for this workload.

What is the typical cost per million tokens for Claude Fable 5? Claude Fable 5 lists $3 per million input tokens and $15 per million output tokens on the Anthropic public pricing page (as of July 2026). Cached input tokens are billed at $0.30 per million, a 90% discount. With prompt caching enabled, the same Bun migration would have cost a small fraction of $165k.

How does prompt caching reduce this cost? Anthropic's prompt caching offers a 90% discount on cached input tokens (5-minute cache, $0.30/M vs $3/M fresh). For a migration where the agent re-reads the rulebook, dependency map, and source files every iteration, prompt caching cuts the effective input cost roughly 10x. The Anthropic blog post does not specify whether caching was on for the $165k case; Anthropic engineers say caching was a key cost lever in follow-up work.

Can Claude Code actually replace a human engineering team? No. Anthropic's blog post frames the migration as "co-led" by Claude Code and human engineers. The plan (rulebook, dependency map, gap inventory) was human-defined; Claude executed the rewrite under parallel agents. Nineteen regressions surfaced after merge — these were caught by the existing CI, not by Claude. The Anthropic framing is that Claude handles the "millions of mechanical line edits" while engineers handle architecture and review.

What's the practical takeaway for AI API builders? Three things. First, large-context frontier models (Claude Fable 5, GPT-5.6, Claude Opus 4.8) can be cost-effective for legacy code migration even at $3/M input, provided you enable prompt caching. Second, agentic workflows with "hundreds of agents" running in parallel are now the default for million-line refactors — a single Claude Code session will not finish it. Third, the $165k number is the upper bound; with caching, parallel sessions, and smaller diffs you can run similar migrations for under $20k.

Is this case study relevant to non-rewrite workloads? Yes. The same agentic pattern (rulebook → dependency map → gap inventory → parallel agent execution) applies to large-scale test generation, multi-file API endpoint migration (e.g. moving from one LLM provider to another), and codebase-wide deprecation sweeps. The cost structure (heavy input tokens, prompt caching, parallel agents) is the same across workloads.

Sources


Disclosure

APIRank may earn affiliate commission from partner links in this article. Editorial judgments remain independent.