Inside Bun's 11-Day rewrite from Zig to Rust

Inside Bun's 11-Day rewrite from Zig to Rust

July 14, 2026


The biggest AI-assisted rewrite yet

Last week, Bun, the all-in-one JavaScript toolkit acquired by Anthropic late last year, announced that it spent the equivalent of $165,000 running 64 parallel Claude agents to refactor its entire codebase from Zig to Rust in just 11 days. A full rewrite in Rust is usually the last thing a startup does before the market catches up with it, but in this case it seems to have worked. The port fixed 128 long-standing bugs, shrank the binary by about 20%, made things modestly faster, and has quietly been powering Claude Code since June without anyone noticing.

Not everyone is celebrating. Andrew Kelley, the creator of Zig, pushed back hard, arguing the benchmarks are misleading and taking a few personal shots along the way. Here is how the rewrite actually happened, and what both sides get right.

Why rewrite at all?

Twenty-six years ago, Joel Spolsky wrote one of the most famous blog posts in software history, arguing that rewriting your codebase from scratch is the single worst strategic mistake a software company can make. His cautionary tale was Netscape, which burned three years rewriting its browser while Microsoft ran away with the market. So what pushed Bun toward the one mistake it supposedly should never make? Memory management.

Bun was originally written in Zig, where you manage memory manually with little help from the compiler. That is normally fine for a low-level language, but Bun embeds JavaScriptCore, Safari's garbage-collected JavaScript engine. So half of Bun's objects were owned by the garbage collector while the other half lived in manually managed Zig memory, and the two halves had to constantly track pointers into each other.

The result was a steady stream of memory bugs: reading memory that had already been freed, freeing the same memory twice, or never freeing it at all. At one point the dev server leaked three megabytes on every rebuild because a single error path forgot to clean up after itself.

The AI angle

Memory bugs alone might not have justified a rewrite. The bigger factor was that, after the Anthropic acquisition, most of Bun's future code was going to be written by Claude, and Zig is famously unfriendly to AI:

  • The Zig project refuses LLM-generated pull requests, and will close a security report if you admit an AI found the bug.

  • There is very little Zig code on the internet to train on.

  • Zig has not reached 1.0, so it keeps introducing breaking changes.

Together, that makes models noticeably worse at writing Zig than at more established languages. Rust solves both problems at once: its borrow checker moves memory management into the type system, turning most memory mistakes into compile-time errors instead of runtime crashes, and there is far more Rust for models to learn from.

How they did it

The method is the most interesting part. Rather than turning agents loose on the code, the Bun team front-loaded the knowledge:

  • Claude first spent hours studying the codebase to produce a detailed porting guide.

  • A workflow then traced the lifetime of every struct field into a giant spreadsheet, documenting years of tribal knowledge about who frees what and when.

  • From there, 64 parallel Claude agents worked across four git worktrees on 1,448 files, at peak producing around 1,300 lines of Rust per minute.

  • To keep them honest, every implementer agent was paired with two adversarial reviewer agents in separate context windows whose only job was to assume the code was wrong and prove it.

Eleven days and roughly 6,500 commits later, Bun's full test suite passed on every platform. The port fixed 128 long-standing bugs, resolved the dev server's memory leaks, and cut binary size by about 20%. Because Anthropic owns the tokens, the run was effectively free internally, but at retail it would have cost around $165,000.

The pushback

Andrew Kelley, Zig's creator, was not impressed, and made clear the split had been building for years. Beneath the personal jabs, though, are some legitimate technical objections worth taking seriously:

  • The performance gains, he argues, came mostly from link-time optimization, which Zig has supported all along.

  • The binary-size reduction had little to do with Rust specifically.

  • The announcement left out compile times, a benchmark Zig almost certainly wins.

The lesson is not that Rust beats Zig, but that you should always read a migration's benchmarks closely before drawing conclusions from them.

What it means for the rest of us

Whatever you think of the benchmark fight, this is a landmark: one of the largest AI-driven rewrites ever attempted, and it shipped. The takeaways are less about Rust and more about method: document the tribal knowledge first, parallelize aggressively, and pair every code-generating agent with adversarial reviewers whose job is to break its work.

It is also a reminder that Spolsky's warning still holds. A full rewrite remains risky, and AI does not make it free of judgment, just faster to execute. For teams building with AI, the real story here is a repeatable playbook for large-scale, agent-driven refactors, not a verdict on which language won.