Edited by humans. Written by AI. How our editing works
All articles

Bun Rewrote Its Codebase from Zig to Rust in 11 Days

Bun used 64 parallel Claude agents to port 535,000 lines of Zig to Rust in 11 days. The results were real. The fallout with Zig's creator was realer.

Dev Kapoor

Written by AI. Dev Kapoor

July 16, 20267 min read
Share:
Man in brown suit eating popcorn with surprised expression next to "Bun Beef" text and cute bun emoji on dark background

Photo: AI. Marco Velez

Joel Spolsky's 2000 essay "Things You Should Never Do" opens with a verdict that has haunted startup engineering teams for a quarter century: rewriting your codebase from scratch is the single worst strategic mistake a software company can make. His cautionary tale was Netscape, which spent three years on a ground-up rewrite while Internet Explorer quietly ate its lunch. The essay became gospel. "Don't rewrite" is practically a bumper sticker in senior engineering circles.

Bun just did it anyway. In 11 days.

Last week, Bun—the all-in-one JavaScript toolkit now under Anthropic's umbrella after being acquired late last year—announced it had ported its entire codebase from Zig to Rust using 64 parallel Claude agents running across four Git worktrees simultaneously. The project touched 1,448 files, produced 652 commits, and at peak throughput was generating 1,300 lines of Rust per minute. The equivalent compute cost, had Bun not been part of the company that runs the token casino, would have been $165,000. The result: 128 long-standing bugs fixed, binaries 20% smaller, performance marginally faster across the board, and—perhaps most tellingly—the rewritten codebase had already been quietly powering Claude Code since June without anyone noticing.

That last detail is either a strong vote of confidence in the methodology or a very convenient piece of post-hoc validation. Probably some of both.

Why Zig, and Why Not Anymore

To understand why Bun made this call, you have to understand what made their Zig codebase genuinely painful to maintain—and it wasn't Zig's fault, exactly.

Bun embeds JavaScriptCore, which is Safari's garbage-collected JavaScript engine. That means half of Bun's objects at any given time were owned by a garbage collector, while the other half lived in manually managed Zig memory. The two worlds had to constantly exchange pointers, and Zig—by design—gives you minimal compiler help with that kind of cross-boundary memory ownership. The predictable result was a changelog full of use-after-free bugs, double-frees, and memory that simply never got released. At one point, Bun's dev server was leaking three megabytes of memory on every rebuild, traced back to a single error path that forgot to clean up after itself.

Memory mismanagement bugs in a mixed-ownership environment aren't a Zig indictment so much as a fundamental impedance mismatch between the language's manual memory model and JavaScriptCore's GC world. Rust's borrow checker doesn't eliminate this complexity, but it does push most of the violations into compile-time errors rather than runtime surprises—which is a meaningful shift when you're trying to ship reliably.

But the memory problems alone probably didn't tip the decision. What did was Anthropic.

Once Bun became part of an AI company, the working assumption became that a large fraction of future code would be written by Claude. And Zig has made its position on AI-generated code unmistakably clear: the project refuses LLM-generated pull requests and will close security reports if the submitter admits an AI found the vulnerability. Beyond the policy stance, there's a practical training-data problem: Zig hasn't reached 1.0 yet, keeps introducing breaking changes, and there's relatively little of it on the internet for models to learn from. Claude writes bad Zig. Rust, by contrast, is one of the better-represented systems languages in training data, and the borrow checker's strictness actually plays to an LLM's strengths—the compiler catches what the model misses.

So Bun's founder Jared made the call in early May: port all 535,000 lines of Zig to Rust.

How You Actually Do This With AI

The methodology here is worth examining on its own terms, because "we used AI to do a big rewrite" is a claim that covers everything from thoughtful orchestration to spectacular disaster.

Bun's approach had a few features that distinguish it from cargo-cult AI usage. Before any agents wrote a line of code, Claude spent hours studying the existing codebase and produced a porting guide—essentially a translation spec. Then they ran a workflow that traced the lifetime of every struct field into a spreadsheet, documenting what Fireship's video describes as "years of tribal knowledge about who frees what and when." That kind of explicit knowledge capture is the thing most teams skip and then regret.

The review structure is also worth noting. Every agent doing implementation work was paired with two adversarial reviewer agents running in separate context windows, whose explicit instruction was to assume the code was wrong and find out why. That's not a foolproof quality gate, but it's a real one—it bakes skepticism into the pipeline rather than assuming the implementer got it right.

Whether this methodology is reproducible at other organizations, with different codebases and different resource profiles, is a genuinely open question. Bun had the advantage of owning the compute, a founder who understood the codebase deeply enough to specify the porting guide, and a tight feedback loop from Claude Code's production usage. Those aren't conditions you can assume.

The Zig Response, and What's Actually Buried in It

Andrew Kelley, Zig's creator, responded publicly—and Fireship's coverage is fair in noting that the response contained both legitimate technical criticism and some personal heat that muddied the former.

The technical points deserve to stand on their own: Kelley argues that the performance improvements Bun claimed largely came from enabling link-time optimization, which Zig has supported all along. The binary size reduction, he contends, was unrelated to the language switch. And he flags that Bun's benchmarks notably omit compile times—a category where Zig has a significant advantage over Rust. These are specific, falsifiable claims, and they haven't been conclusively rebutted in public as of this writing.

Kelley also acknowledged something that most language creators would quietly bury: the Zig team had apparently been using Bun's codebase internally as an example of how not to write Zig. That's a remarkable admission, and it cuts in two directions simultaneously. On one hand, it validates some of Kelley's technical criticism—if Bun was misusing Zig's idioms, the language's limitations may have been less of a factor than claimed. On the other hand, if your most famous user's codebase is your internal cautionary tale and you never said so publicly, the communication failure there belongs to more than one party.

The personal commentary—references to Jared's background, his "beginner energy," secondhand reports about his management style—is harder to evaluate and easier to dismiss. That kind of thing lands differently coming from a compiler engineer with institutional standing versus a random forum post, but it doesn't strengthen the technical case.

As Fireship put it: "Zig lost its most famous user. Andrew lost his cool. And Jared got publicly diagnosed with beginner energy by a compiler engineer." Nobody walks away from this with an unscuffed reputation.

The Bigger Question This Opens

The Bun rewrite is interesting on its technical merits. But the thing that's going to matter longer is the question it surfaces about AI-era language selection.

We're entering a period where AI tooling isn't just a workflow accelerator—it's becoming a genuine factor in the sustainability of a language ecosystem. Zig's principled stance against LLM-generated contributions is coherent and defensible on quality grounds. But it also means that any organization whose development increasingly runs on AI coding assistants faces a real friction cost with Zig that doesn't exist with Rust, Go, or Python. Whether that's a problem Zig should solve, or a constraint its users should accept, is a genuine values question about what kind of ecosystem you're building and for whom.

Bun's answer was to change languages. Other Zig users will answer differently. But the question isn't going away, and it's not unique to Zig—any language that's LLM-hostile, training-data-sparse, or rapidly pre-1.0 evolving is going to feel this gravity.

Spolsky's essay was right that rewrites are expensive and risky. It wasn't written for a world where 64 parallel agents can do in 11 days what used to take three years. What "the single worst strategic mistake" looks like in that world is still being worked out.


By Dev Kapoor, Open Source & Developer Communities Correspondent

From the BuzzRAG Team

We Watch Tech YouTube So You Don't Have To

Get the week's best tech insights, summarized and delivered to your inbox. No fluff, no spam.

Weekly digestNo spamUnsubscribe anytime

More Like This

Cloudflare logo displayed centrally against shelves of colorful lava lamps with purple lighting backdrop

How Cloudflare Uses Lava Lamps to Encrypt the Internet

Cloudflare's San Francisco office has a wall of 100 lava lamps generating entropy for SSL/TLS encryption. Here's why computers can't be truly random.

Dev Kapoor·5 months ago·5 min read
Retro-styled C++ Online Conference poster featuring instructor Amir Kirsh with workshop details and registration…

Bridging the Gap: C++ Workshop Tackles Industry Reality

Amir Kirsh's workshop addresses the persistent divide between academic C++ and production code—and questions whether one-day training can solve it.

Dev Kapoor·3 months ago·5 min read
A hand holds a Nest thermostat displaying 68 degrees heating in orange, with large yellow "NEST" text and "Version History"…

How the Nest Thermostat Launched the Smart Home Era

Tony Fadell's Nest Learning Thermostat didn't just fix an ugly device—it sparked the smart home era. A look at what it got right, wrong, and what Google killed.

Dev Kapoor·2 weeks ago·9 min read
Two pallbearers carry a golden casket against a dark background with "OPEN SOURCE FAILS" text and tech logos, illustrating…

Five Open Source Projects That Crashed After Success

From Faker.js to Firefox, explore why technically brilliant open source projects failed despite—or because of—their success.

Dev Kapoor·5 months ago·7 min read
A smiling person in a black shirt next to a Ponytail app icon with an orange background and white starburst design

Ponytail Cuts Claude Code Token Usage by 94%

Ponytail is a Claude Code plugin that enforces a seven-step minimalism checklist before writing code. Here's what it does, how it works, and what to watch for.

Bob Reynolds·3 weeks ago·6 min read
A lightning bolt logo with an X mark, happy bun character, checkmark, arrow, and R gear icon against a dark background…

Anthropic Owns Bun Now. That's the Story.

Anthropic's reported acquisition of Oven—and the AI-assisted Rust rewrite of Bun that followed—raises governance questions the dev community isn't asking.

Samira Barnes·2 months ago·6 min read
Three bearded men with confused expressions touch their heads against a purple-lit background with a social media post…

Matt Wolfe's YouTube Playbook: Money, AI & Workflow

Matt Wolfe opens the books on his YouTube AdSense, AI video workflow, and why he thinks faceless AI channels are mostly a losing bet.

Dev Kapoor·3 months ago·6 min read
Bearded man holding a damaged MacBook and Linux laptop with "I quit mac" text overlay

Framework 13 vs MacBook: 3-Month Linux Reality Check

DevOps engineer Mischa van den Burg ditched his MacBook for a Framework 13 running Fedora. Three months in, he's not looking back—but there are tradeoffs.

Dev Kapoor·3 months ago·6 min read

RAG·vector embedding

2026-07-16
1,774 tokens1536-dimmodel text-embedding-3-small

This article is indexed as a 1536-dimensional vector for semantic retrieval. Crawlers that parse structured data can use the embedded payload below.