« All posts

AI Agents Powered Bun's Rewrite from Zig to Rust

Bun creator Jarred Sumner used AI coding agents to rewrite Bun from Zig to Rust, fixing memory bugs. Details on the process, cost, and results.

Bun creator Jarred Sumner detailed a large-scale rewrite of the JavaScript runtime from Zig to Rust, driven by persistent memory-safety bugs—use-after-free, double-free, and missed frees in error paths—that stemmed from mixing garbage collection with manual memory management. Rust's compiler catches these classes of errors at compile time, with Drop providing automatic RAII-style cleanup.

While rewriting large systems from scratch is traditionally considered risky, Sumner argues that coding agents backed by frontier models change that calculus. Because Bun's test suite was already written in TypeScript, it doubled as a language-independent conformance suite, letting an agent harness automate much of the initial Zig-to-Rust port. Sumner spent roughly 11 days monitoring the agent workflows, prompting Claude to fix the underlying generation process rather than hand-patching bugs in the resulting code—a strategy for reviewing a change spanning over a million lines.

The Rust-based Bun has been running in production inside Claude Code since version 2.1.181, delivering a 10% faster startup on Linux with little user-visible disruption, which the author frames as a sign of success. The estimated token cost of the rewrite—around $165,000 at API pricing—offers a concrete data point on the economics of using AI agents for ambitious, large-scale software migrations.