The Information Machine

Rewriting Bun in Rust

Simon Willison · Simon Willison · 2026-07-08

Bun creator Jarred Sumner documents the AI-agent-assisted rewrite of the Bun JavaScript runtime from Zig to Rust, completing the million-line migration in roughly 11 days at an estimated $165,000 in Claude API costs.

Open original ↗

Appears in

Extraction

Topics: agentic-engineeringai-assisted-programmingbunrustzig

Claims

  • Bun's Zig codebase suffered from use-after-free, double-free, and memory-management bugs that Rust's type system and RAII semantics prevent at compile time.
  • An AI agent harness using Claude automated the initial Zig-to-Rust port, with Sumner manually monitoring and adjusting workflows for approximately 11 days.
  • The Bun TypeScript test suite acted as a language-independent conformance suite that enabled automated correctness verification of the generated Rust code.
  • The pre-merge process consumed 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached input token reads, totaling approximately $165,000 at API pricing.
  • Claude Code v2.1.181 (released June 17th) already ships the Rust port of Bun, delivering a 10% Linux startup improvement with no user-visible regressions.

Key quotes

Coding agents powered by today's frontier models change that equation.
A language-independent test suite with a million assertions, adversarial code review and when something does go wrong, fixing the process that generates the code instead of hand-fixing the code.
Pre-merge, this took 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached input token reads — around $165,000 at API pricing.