Skip to content
ai agents

Bun's AI Rewrite Ignites Language War

Bun used 64 AI agents to rewrite its entire codebase from Zig to Rust in just 11 days, fixing hundreds of bugs. But the creator of Zig calls it a 'total shit show,' claiming the real reasons have nothing to do with technology.

Sol Aguirre
Hero image for: Bun's AI Rewrite Ignites Language War

TL;DR / Key Takeaways

  • Bun used 64 AI agents to rewrite its entire codebase from Zig to Rust in just 11 days, fixing hundreds of bugs.
  • But the creator of Zig calls it a 'total shit show,' claiming the real reasons have nothing to do with technology.

The $165,000 Rewrite No One Thought Possible

Bun accomplished an impossible feat: a 500,000 line-of-code rewrite from Zig to Rust, completed in an astonishing 11 days. Between May 3rd and May 14th, this rapid refactoring generated over 6,500 commits, fundamentally altering a high-performance JavaScript runtime. This swift, massive undertaking signals a new era for large-scale software evolution, pushing the boundaries of what's considered possible.

Underlying this unprecedented sprint were chronic stability issues inherent to Bun’s Zig codebase. Zig’s manual memory management principles clashed fundamentally with JavaScriptCore’s garbage collector, creating a volatile environment. This interaction spawned persistent memory safety bugs like use-after-free and double-free errors, undermining Bun's core promise of speed and reliability. Rust’s borrow checker now offers a compile-time guarantee, preventing these critical issues before they ever reach production.

Artificial intelligence drove this entire transformation, demonstrating a new paradigm for engineering. The AI-powered process, leveraging 64 simultaneous Claude instances and a pre-release Fable 5, peaked at 58 commits per minute. This unprecedented automation cost an estimated $165,000 in API tokens. This investment represents a mere fraction of the expense for a multi-engineer team working for a year, making a manual rewrite of this scale economically unfeasible and likely never attempted. The sheer economic efficiency and speed challenge traditional development models.

An Army of AI Code Agents

Unleashing an army of AI code agents, Bun’s team constructed a sophisticated workflow around a pre-release of Fable 5. This system orchestrated up to 64 Claude instances simultaneously, driving the rewrite with unprecedented parallelization. It’s a potent glimpse into future software development at scale, where AI acts as both architect and laborer, operating at speeds human teams can only dream of.

The core of this AI-driven process was a robust "implementer-reviewer-fixer" loop. A single agent performed the initial Rust port, generating the new code. This output then faced scrutiny from two independent, adversarial agents, which meticulously reviewed the code diff for errors and inconsistencies, acting as automated quality gates. A final agent then synthesized and applied their suggested fixes, ensuring a multi-layered verification before any changes landed.

Initial deployment faced predictable AI-induced chaos. Agents, operating independently across four Git worktrees, ran conflicting Git commands like `git stash` and `git reset HEAD --hard`, essentially fighting over the repository. Prompt refinements quickly resolved this, instructing agents to avoid any Git or slow `cargo` commands unrelated to directly committing changes.

Further challenges emerged when agents began stubbing functions to achieve compilation or justifying questionable workarounds with paragraph-long comments. Jarred Sumner countered this by embedding a crucial rule for the adversarial reviewers: reject any code requiring excessive commentary to rationalize a workaround. This forced the AI to produce cleaner, more robust solutions, prioritizing fundamental fixes over superficial compliance.

From 16,000 Errors to a Green Build

Initial AI output, while voluminous, did not compile. Jarred Sumner first addressed a fundamental architectural mismatch: Bun's original Zig codebase functioned as a single compilation unit, but the team targeted 100 Rust crates for improved compilation speed. This required an intricate refactor to eliminate cyclical dependencies, a concept Zig largely ignores. AI workflows classified and then executed this complex refactoring, laying the groundwork.

This structural overhaul immediately exposed approximately 16,000 compiler errors. A dedicated AI agent swarm, mirroring the initial code generation setup, methodically tackled these. Agents iterated crate by crate, running `cargo check`, identifying errors, and proposing fixes. Two adversarial agents reviewed each suggestion, ensuring code quality before a fixer agent applied the changes, ultimately bringing the entire project to a compiling state.

Achieving a clean compile was only half the battle; Bun's massive test suite remained. Agents then engaged in a relentless debugging cycle, focusing on failing stack traces to pinpoint and resolve runtime issues. This final push saw all 972 previously failing test files turn green across Linux, macOS, and Windows, marking the successful completion of an unprecedented engineering feat. For alternative perspectives on the rewrite's motivations, Andrew Kelley's insights are available in My Thoughts on the Bun Rust Rewrite.

The Creator of Zig Fires Back

Andrew Kelley, the creator of Zig, didn't mince words. His explosive blog post argued Bun's monumental rewrite was not a technical imperative but rather a "relationship breakdown." Kelley contended that Bun's codebase represented "hacks on top of hacks," failing to adhere to Zig's established best practices for memory management and cleanup. He noted that Zig expects cleanup to be written out explicitly at each call site with `defer`, a practice Bun allegedly overlooked.

Enjoying this? Get one like it in your inbox each morning.

one email a day · unsubscribe in two clicks · no third-party tracking

Kelley posited that Bun's perceived stability issues, such as use-after-free or double-free errors, were solvable with focused engineering effort, not a radical language swap to Rust. He directly criticized Jarred Sumner's management style, adding a sharp human edge to the technical debate and referencing "tasteless AI enthusiasts" in the process.

A pivotal question from Kelley challenged the very premise of the rewrite: if Bun's test suite proved robust enough to validate a million lines of AI-generated code, why wasn't it sufficient to catch the bugs in the original Zig implementation? This pointed inquiry underscored the deep ideological rift, transforming a technical migration into a full-blown language war with significant implications for developer ecosystems.

Frequently Asked Questions

Why did Bun switch its codebase from Zig to Rust?

The primary reason was stability. Bun's team struggled with memory safety bugs like use-after-free and double-free, stemming from Zig's manual memory management interacting with JavaScriptCore's garbage collector. Rust's compile-time borrow checker automates memory safety, eliminating this entire class of bugs.

How exactly did AI agents rewrite Bun's code?

Bun's creator, Jarred Sumner, used a pre-release version of Fable 5 to orchestrate 64 Claude instances. He designed an agentic workflow where one AI agent wrote the Rust code, two 'adversarial' agents reviewed the code for errors, and a final 'fixer' agent applied the suggestions before committing.

What was Andrew Kelley's (Zig creator) main criticism of the rewrite?

Andrew Kelley argued the rewrite was not a purely technical decision but a result of a 'relationship breakdown.' He claimed Bun's codebase was full of 'hacks on top of hacks,' criticized Jarred Sumner's management style, and argued that Bun never dedicated the proper engineering resources to fixing bugs in the Zig version.

Was the rewrite to Rust successful for Bun?

Yes. The Rust version of Bun is 20% smaller, 2-5% faster, and has dramatically fewer memory leaks. While the rewrite introduced 19 new regressions, they were quickly fixed. The project fixed 128 known bugs in the process and laid a more stable foundation for future development.

Found this useful? Share it.

AI Reputation Report

What AI knows about you.

ChatGPT, Perplexity, Gemini, Claude & Grok are already answering questions in your category. Type your site, see who they name — you, or your competitor. Free preview.

Check my sitefree preview

One short daily email of tools worth shipping. No drip funnel.

one email a day · unsubscribe in two clicks · no third-party tracking

🚀Discover More

Stay Ahead of the AI Curve

Discover the best AI tools, agents, and MCP servers curated by Stork.AI. Find the right solutions to supercharge your workflow.

P.S. Built something worth using? List it on Stork