AI
Bun Rewrites 535K Lines of Code from Zig to Rust Using AI in Record Four Months
JavaScript runtime Bun completed a massive language migration in a fraction of expected time by orchestrating 64 parallel Claude instances, cutting memory leaks and reducing bugs.
InfoQ
Bun creator Jarred Sumner announced that the JavaScript/TypeScript runtime, bundler, and package manager has been migrated from Zig to Rust—a 535,000-line rewrite that finished in just four months instead of the estimated year-long timeline. The effort tapped AI assistance to address persistent memory safety issues that plagued the original codebase.
Why Rewrite?#
Sumner identified a troubling pattern in Bun's bug history: a significant proportion of defects stemmed from use-after-free errors, double-free vulnerabilities, and resource leaks in error-handling paths. Rust's compiler-enforced memory safety model treats these as compile-time failures rather than runtime surprises, making it a natural target. Traditional rewrites of this scale typically demand freezing all other development for months—an unacceptable cost. However, Bun's existing test suite was written in TypeScript and thus language-agnostic, making automated validation feasible.
The AI-Orchestrated Port#
Rather than assemble a large team to manually recode the system, Sumner proposed a experiment: testing whether Anthropic's then-unreleased Claude Fable 5 model could handle an automated port. The approach succeeded well enough that he decided to merge it.
The process ran 64 Claude instances in parallel across four workspace shards, each hosting 16 agents. At peak throughput, the system generated roughly 1,300 lines of code per minute and committed up to 695 times per hour.
The strategy relied on several key mechanisms:
- Porting guides: A
PORTING.mddocument mapping Zig idioms and types to Rust equivalents, and aLIFETIMES.tsvfile cataloging the lifetime requirements of every struct field. - Separation of concerns: Implementer agents built code while isolated reviewer agents audited diffs and flagged bugs—never the other way around.
- Adversarial review: Two competing reviewer agents checked each file independently, ensuring bugs surfaced before final integration.
- Continuous optimization: The system refined its own process after each error, improving methodology rather than patching individual artifacts.
The bill totaled $165,000 in API costs (5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached reads). By comparison, Sumner estimated that three engineers with full context would have needed a year to accomplish the same task.

