TLDRocket
Sign in

What can we learn from Bun's rapid Rust rewrite with AI?

The Pragmatic Engineer

Bun's creator used Anthropic's Claude-based tool Fable to rewrite the entire 535K-line JS runtime from Zig to Rust in just 11 days. It cost $165,000 in API tokens but likely saved a year of engineering time and eliminated a whole class of memory bugs.

Based on reporting by The Pragmatic Engineer — read the original for the full story.

Summary, retelling and take written by AI under human oversight; images are AI-generated illustrations. How we work · Report an error

Jarred Sumner had a problem that's haunted plenty of systems programmers: Bun, his JavaScript runtime with 22 million monthly downloads, was written in Zig, a language that doesn't guard against memory bugs. Despite patching the Zig compiler and adding end-to-end memory leak tests, Sumner kept losing sleep over crashes, heap-out-of-bounds writes, and use-after-free errors buried in Bun's 535,496 lines of code. Rust would fix this at the compiler level. But rewriting more than half a million lines by hand, he estimated, would take a small team of engineers a full year — and a year with zero user-facing progress wasn't something Bun could afford.

So he tried something else. He spent three hours talking through porting patterns with Claude, which turned the conversation into a 600-line guide covering ground rules like banning async fn and certain crates, and how to handle Rust's borrow checker without resorting to raw pointers. After a trial run on three files and two rounds of adversarial review, Sumner split the job across 64 AI agents working in parallel across four Git worktrees — after first untangling a mess where the agents kept stomping on each other's work with conflicting git commands.

From there it moved fast. The agents ported all 1,448 Zig files in roughly two days, generating 6,500 commits, each checked by adversarial reviewers before landing. Then came 1,600 compiler errors, which ballooned to about 16,000 once cyclical dependencies unraveled — fixed crate by crate in around 12 hours, with some of that work happening overnight while Sumner slept. Getting the test suite running took another two days, and getting it to actually pass in CI took three more. Total elapsed time: 11 days, start to finish.

The price tag was $165,000 in API costs, covering 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached input token reads. That's roughly a year's base salary for a mid-tier software engineer in the US. Terraform creator Mitchell Hashimoto called it an incredible deal anyway, arguing no single engineer — or even a group paid the same total — could have hit those milestones in 11 days. Sumner agrees the alternative wasn't really an alternative: without AI, the team would have kept patching memory bugs indefinitely rather than ever attempting the rewrite.

What makes this repeatable, rather than a one-off flex, comes down to three things Sumner didn't dwell on but that clearly mattered: an engineer who knew the codebase intimately, a test suite robust enough that passing it meant something, and a willingness to spend heavily on tokens without knowing upfront how it would go. The token spend is the part most teams can probably shrink — cheaper models for grunt work, pricier ones for planning. The other two ingredients are harder to fake.

My take — AI-written commentary, not fact-checked reporting

The real story here isn't the price tag, it's that a rewrite this size only worked because Sumner already had a rock-solid test suite and knew Bun's internals cold — take away either one and this becomes an expensive way to generate a broken runtime. Anyone eyeing a Claude-powered migration should worry less about the $165,000 and more about whether their own test coverage could actually catch what an AI agent silently breaks at 3am.

Read more about this at: The Pragmatic Engineer

Related stories

The daily briefing

Every AI story that matters, in your inbox by 8am.

TLDRocket reads all relevant sources, removes duplicate coverage, and summarises the day in two minutes. Follow companies and topics for alerts, or get the briefing in Slack. Free, no spam, unsubscribe anytime.