TLDRocket
Sign in

Rewriting Bun in Rust

Simon Willison's Weblog Simon Willison Covered by 2 sources

Bun's creator Jarred Sumner rewrote its Zig core into Rust using coordinated coding agents, not humans. It fixed a class of nasty memory bugs and cost roughly $165,000 in API tokens to pull off.

Based on reporting by Simon Willison's Weblog, Simon Willison — 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 just published the long-awaited account of how Bun, the JavaScript runtime he built in Zig, quietly became a Rust project. He'd been teasing the post since May 9th, and the wait turned out to be worth it, because what he describes isn't a typical rewrite. It's an agentic engineering project: dynamic workflows, trial runs, adversarial code review, and a coding agent doing the bulk of the porting work while Sumner supervised.

The motivation wasn't dissatisfaction with Zig. Sumner is careful to say Zig got Bun this far and he's grateful for it. The real problem was mixing garbage collection with manually managed memory, a combination that produced a steady drip of use-after-free, double-free, and forgot-to-free bugs. Rust's borrow checker turns those into compile-time errors, and its Drop trait handles cleanup automatically. That's the whole pitch: not a better language in the abstract, just one better suited to a specific class of bugs that were keeping Sumner up at night.

What made the rewrite feasible at all was that Bun's test suite lived in TypeScript, separate from the implementation language. That let it double as a conformance suite for an agent harness built on an early version of what Anthropic now calls Mythos/Fable. Sumner didn't expect much from the experiment at first. A few days in, though, a large chunk of the suite was passing and the generated Rust was tracking the original Zig code closely enough that he decided to actually merge it. For eleven days he mostly watched the workflows run, reading output for bugs and telling Claude to adjust the process itself rather than hand-patching broken code.

Reviewing a pull request with over a million lines added obviously breaks normal code review. Sumner's answer was a huge language-independent assertion suite, adversarial review passes, and a rule that when something broke, you fixed the pipeline generating the code instead of fixing the output by hand. The Rust version of Bun has been running inside Claude Code since version 2.1.181 on June 17th, and Linux startup got about 10% faster. Almost nobody noticed, which Sumner treats as the actual win.

The number that will stick with people is the price tag: roughly $165,000 in token costs to get to the pre-merge state, built from 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached reads. Sumner works at Anthropic, so he wasn't billed for it directly, but the figure is a real signal of what large-scale agentic rewrites currently cost when you actually tally the compute.

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

I'll say the obvious thing nobody wants to say: this only worked because Bun already had a strong TypeScript test suite acting as a language-agnostic spec, and because someone at Anthropic didn't have to look at a $165k invoice. Rewrite-by-agent is real, but right now it's a luxury good for well-tested codebases with free tokens, not a template the rest of us can just copy.

Read more about this at: Simon Willison's Weblog

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.