AIToday

Bun rewrites 535K lines from Zig to Rust in 11 days using Claude, cuts memory leaks

Publickey3h ago
Bun rewrites 535K lines from Zig to Rust in 11 days using Claude, cuts memory leaks

Key takeaway

Bun's creator completed a full rewrite of the JavaScript runtime from Zig to Rust in 11 days using Claude, Anthropic's AI agent tool. The migration eliminated memory leaks, shrank the binary by roughly 20%, and improved performance by 2–5%, demonstrating a new workflow for large-scale code migration driven by AI agents and automated testing rather than manual review.

Summaries like this, in your inbox every morning.

Sign up free →

3 Key Points

  • What happened

    Jarred Sumner, creator of the Bun JavaScript runtime, used Claude (Anthropic's AI agent tool) to port approximately 535,000 lines of code from Zig to Rust over 11 days. The rewritten Bun 1.4 (Canary) now runs on Rust instead of Zig and passed the full test suite.

  • Why it matters

    The migration eliminates memory leaks, reduces binary size by approximately 20%, and improves performance by 2–5%. Sumner chose Rust for its memory safety guarantees—preventing crashes from memory errors that were harder to catch in Zig—making Bun more stable for users relying on it (including Anthropic, which acquired Bun in December 2025).

  • What to watch

    The work cost approximately $165,000 in Claude API usage and involved dynamic workflows running continuously for 11 days, generating 6,778 commits and peaking at approximately 1,300 lines of Rust code per minute. Sumner used multi-agent adversarial code review and test-driven iteration rather than manual verification, establishing a pattern for large-scale AI-assisted refactoring.

Context & Analysis

Bun, a Node.js-compatible JavaScript runtime, was acquired by Anthropic in December 2025 and serves as the runtime for Claude Code. In May 2026, Sumner began experimenting with migrating the codebase from Zig to Rust; by July 2026, he had completed the full rewrite using Claude as an AI agent orchestrator.

The approach was methodical: Sumner first established porting rules and lifetime annotations by discussing patterns with Claude and creating reference documents. He then deployed dynamic, multi-agent workflows that ran for 11 continuous days, generating code, running tests, and receiving corrections in tight feedback loops. Critically, Sumner used adversarial review agents (at least two per implementation agent) to catch bugs and enforce correctness, treating the test suite and automated review as the source of truth rather than manual code inspection. At peak, the system generated approximately 1,300 lines of Rust per minute across parallel agents, producing 6,778 commits.

The results—elimination of memory leaks, 20% smaller binary, and 2–5% performance gain—suggest that large-scale refactoring can be completed via AI-assisted workflow iteration without traditional line-by-line human review, provided test coverage and adversarial automation are sufficiently robust. For businesses considering large code migrations, this demonstrates a potential cost-benefit: $165,000 in API usage versus the equivalent of three engineers for one year.

FAQ

What was the cost of using Claude for this migration?
The Claude API usage cost approximately $165,000. Sumner noted this is equivalent to three experienced engineers working full-time on the port for one year while putting all other feature work and bug fixes on hold.
How did Claude actually do the work—did it write all the code at once?
No. Sumner first spent about three hours with Claude discussing how to map Zig patterns to Rust, then created a porting guide and a lifetime-analysis document (LIFETIMES.tsv). He then ran dynamic workflows continuously for 11 days, each loop generating a porting guide, converting all 1,448 Zig files, fixing compiler errors per crate, running tests, and performing refactoring. Most of the 11 days was Sumner monitoring output, identifying problems, and feeding corrections back into the workflow.
Why switch from Zig to Rust?
Sumner stated that while Zig was necessary to develop Bun initially, Rust's memory-safety guarantees prevent crashes from memory leaks and misuse—making Bun more stable and reliable. This was a priority for a production runtime used by Anthropic and others.

Discussion

No comments yet. Be the first to share your thoughts!

Log in to join the discussion

Related Articles

Stay ahead with AI news

Get curated AI news from 200+ sources delivered daily to your inbox. Free to use.

Get Started Free

Free · takes 30 seconds · unsubscribe anytime

1 minute a day. The AI essentials.

200+ sources · Email / LINE / Slack

Get it free →