How Anthropic Migrated Millions of Lines in Two Weeks Using a Six‑Step AI Process

Anthropic engineers used Claude Fable 5 and Claude Opus 4.8 to migrate massive codebases—Bun from Zig to Rust and a Python project to TypeScript—in under two weeks, cutting memory usage by 91%, reducing binary size by 19% and boosting performance by up to 5% while outlining a reusable six‑step workflow‑centric methodology.

TonyBai
TonyBai
TonyBai
How Anthropic Migrated Millions of Lines in Two Weeks Using a Six‑Step AI Process

Overview

Anthropic engineers used Claude Fable 5 and Claude Opus 4.8 to migrate ten code packages ranging from tens of thousands to hundreds of thousands of lines in about a month.

Why language migration is now feasible

Traditional migrations cost millions of dollars and take years. AI models parallelize work, use existing test suites as objective judges, and generate task queues automatically, reducing time and risk. The Bun migration consumed 5.9 billion uncached input tokens and about 6.9 billion output tokens, costing roughly $165 K.

Why AI fits the task

Parallelizable work : Thousands of independent units (files, crates) can be processed concurrently.

Clear context : The original codebase serves as a perfect specification for translation rules.

Built‑in judge : Test suites provide objective verification, allowing models to iterate against a fixed answer.

Self‑generating task queue : Compilation or test failures automatically become the next tasks.

Consistency handling : Every deviation is captured as a task, ensuring systematic rule updates.

Core methodology: fix the production loop

You are not fixing the code; you are fixing the loop that produces the code.

Six‑step migration blueprint

Step 1 – Rulebook, dependency map, gap list

Identify code that needs restructuring, create a translation rulebook, and map dependencies to schedule parallel migration work. The rulebook’s shape depends on whether the target retains the original structure (type‑mapping) or is a redesign (design document).

Step 2 – Stress‑test rules

Run a mini‑migration on a few files. For structure‑preserving migrations compare line‑by‑line outputs; for redesigns use adversarial reviewers to attack the design document.

Step 3 – Full‑scale translation

Deploy multiple agents: smaller models handle bulk implementation, larger models perform review. A task queue monitors the presence of output files on disk to mark completion, enabling checkpointable, resumable execution.

Step 4 – Compile

Optionally invoke the compiler after each batch (Jarred runs it after the entire workspace, Mike runs it after each round) to surface hidden errors such as unsafe Rust modules that appear only after “lazy compilation” issues are resolved.

Step 5 – Run & align behavior

Execute smoke tests, classify failures, and feed errors back into the rulebook so that systematic rule updates replace manual per‑file patches.

Step 6 – Final consistency check

Run the full test suite on both codebases, use repair agents to fix mismatches, and employ a build daemon to batch‑apply patches and rebuild binaries, serializing the most expensive operations.

Key technical details from case studies

Bun migration (Zig → Rust) completed in under two weeks. CI tests passed 100 % before merge; 19 regressions were discovered and fixed post‑merge. Memory consumption dropped from 6745 MB to 609 MB (‑91 %). Binary size decreased by 19 %. Real‑world workloads showed 2‑5 % performance improvement. Compilation time for an internal Python‑based tool dropped from ~8 minutes per platform to ~2 seconds, a six‑fold speed‑up.

Python → TypeScript migration processed 165 k lines over a weekend using hundreds of agents, eight stages, and three rounds of adversarial review. The migration consumed roughly 27 million tokens.

Implementation examples

Rulebook form varies by architectural decision:

If preserving structure (e.g., Jarred), the rulebook is a type‑mapping table; gaps are recorded in a gap list.

If redesigning (e.g., Mike), the rulebook becomes a design document.

Example of Zig memory management versus Rust ownership:

fn readConfig(allocator: std.mem.Allocator) ![]u8 {
    const buf = try allocator.alloc(u8, 1024);
    // ...fill buf...
    return buf; // caller must free this — comment only
}
// Caller may forget defer allocator.free(buf) and still compile
fn read_config() -> Vec<u8> {
    let buf = vec![0u8; 1024];
    // ...fill buf...
    buf // ownership transferred, memory freed automatically
}

Python function without static types versus TypeScript interface:

def register(handler):
    handler.setup()
    return handler.run({"retries": 3})
interface RunResult { ok: boolean }
interface Handler {
    setup(): void;
    run(opts: { retries: number }): Promise<RunResult>;
}
function register(handler: Handler): Promise<RunResult> {
    handler.setup();
    return handler.run({ retries: 3 });
}

Best‑practice principles derived from the projects

Customize the workflow with Claude before execution; front‑load human effort in rulebook creation and stress testing.

Focus on patterns of failure; let repair agents handle individual errors.

Use adversarial reviewers and automated scripts as judges.

Reserve the strongest model for review and rule generation; use smaller models for bulk translation.

Define task completion as the presence of output files on disk to enable mechanical, resumable queues.

Resources

Migration starter kit: github.com/anthropics/code-migration-kit-with-claude-code Code modernization plugin:

github.com/anthropics/claude-plugins-official/tree/main/plugins/code-modernization

Dynamic workflows overview:

https://claude.com/blog/introducing-dynamic-workflows-in-claude-code
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TypeScriptRustworkflow automationBunClaudeAI code migrationsix-step method
TonyBai
Written by

TonyBai

Tony Bai's tech world (tonybai.com). Not satisfied with just "knowing how", we strive for mastery. Focused on Go language internals, high-quality engineering practices, and cloud‑native architecture, exploring cutting‑edge intersections of Go and AI. Gophers who pursue technology are welcome—follow me and evolve with Go.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.