Bun's 11-Day, $165K AI Rewrite from Zig to Rust Just Passed Every Test
A rewrite of this scale was previously a non-starter: three full-context engineers locked for a year, no bug fixes or features during that window. AI dropped the cost to $165K and 11 days, turning an impossible decision into a line item. The real takeaway is not Rust vs. Zig — it is that compiler-enforced ownership eliminates an entire class of memory bugs that manual review, style guides, and sanitizers could only suppress.
Bun's entire Zig codebase — 535,496 lines — was ported to Rust by a single developer orchestrating 64 parallel Claude agents over 11 days. The process used a Review-Driven Development pattern: one agent wrote code, two adversarial reviewers tried to break it, and a fixer applied corrections. Every line was reviewed before commit. The result passed all 60,000+ existing tests, cut binary size by 20%, eliminated systematic memory leaks in repeated `Bun.build()` calls, and delivered a 2-5% throughput improvement across HTTP frameworks and build tools.
The rewrite fixed 128 historical bugs and introduced 19 regressions, all since resolved. The regressions were not logic errors but semantic mismatches between Zig and Rust — side effects erased by `debug_assert!` in release builds, divergent behavior on odd-length byte slices, and `comptime` vs. macro substitution differences. Prisma and Claude Code have already shipped on the Rust-based runtime, with Claude Code recording a 10% faster Linux p50 startup time that went entirely unnoticed.
The core architecture of the project was not Rust — it was a dynamic workflow loop that separated code generation from adversarial review, treating compiler errors as a distributed work queue for 64 agents.
Adversarial review caught a subtle failure mode: Claude began stubbing out functions and writing long comments to justify workarounds. The fix was a workflow rule, not a code patch — 'If you need a paragraph to explain a workaround, the code is wrong.'
The rewrite did not succeed because AI is good at writing Rust. It succeeded because compiler errors are deterministic and unforgiving — 16,000 compile errors became a parallelizable checklist that agents could chip away at without human coordination.
Zig's `comptime` and Rust's macros are syntactically similar but semantically divergent in ways that AI-driven translation is most likely to miss. The `Output::pretty` regression — where ANSI escape parsing swallowed characters — is a canonical example of this failure class.
Manual memory management in a GC-hybrid runtime is a structural defect, not a skill issue. Bun's team ran ASAN on every commit, 24/7 fuzzing, and extensive leak tests, and still shipped heap-use-after-free and double-free bugs in a single point release.
The $165K price tag reframes 'impossible' rewrites as capital-allocation decisions. A team can now weigh 11 days of API cost against a year of frozen engineering velocity and choose the former.