Bun, the JavaScript and TypeScript runtime, has been rewritten from Zig to Rust in four months using an AI-assisted pipeline that cost $165,000 in API tokens. The rewrite eliminated 128 longstanding bugs, stopped native memory leaks, and delivered a 2% to 5% increase in HTTP throughput. The project, which involved porting 535,000 lines of Zig code, was released as Bun v1.4.0 in August 2026.

Why the rewrite happened

Jarred Sumner, Bun's creator, said the motivation was straightforward. A large percentage of Bun's bugs were use-after-free, double-free, and missing frees in error paths. In Zig, these are logic errors caught by testing or code review. In Rust, the borrow checker turns them into compile-time errors, and Drop provides automatic cleanup. Sumner framed the choice as compiler errors being a better feedback loop than a style guide.

He acknowledged that rewrites are historically a terrible idea. The Zig codebase was 535,496 lines. A manual rewrite by a small team would have taken about a year, during which bugfixes, security patches, and feature development would freeze. The test suite, written in TypeScript, was the key enabler: it does not depend on the runtime's implementation language, so it could validate a Rust implementation without modification.

The AI-assisted pipeline

Sumner tested whether Anthropic's Claude Fable 5, a pre-release model at the time, could handle the port. The approach was an automated all-at-once transpilation orchestrated across approximately 50 dynamic workflows. The Zig code was translated into Rust, including unsafe Rust where necessary for later refactoring, and validated against the existing test suite of more than one million assertions.

The pipeline used a porting guide called PORTING.md that described how Zig patterns and types map to Rust. A LIFETIMES.tsv file cataloged the lifetimes of every struct field in the codebase. These two files were the critical planning artifacts. Sumner said the planning phase is where success or failure is determined, and the porting guide and lifetime map let the system anticipate and handle the hardest problems before they became bugs.

The architecture separated implementation from review. An implementer agent translated Zig files into Rust. Two adversarial reviewer agents, each running in isolated context windows with access only to file diffs, searched for bugs and behavioral divergences. A fixer agent handled issues the reviewers found. The implementer did not review. The reviewer did not implement. This separation prevented the kind of feedback loops where an agent reinforces its own mistakes.

Scale and cost

The system ran across four workspace shards, each hosting 16 agents, for a total of 64 Claude instances operating in parallel. At peak velocity, the pipeline generated roughly 1,300 lines of code per minute and logged up to 695 commits per hour. Pre-merge, the work 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.

Sumner's estimate for the manual equivalent: three engineers with full context on the codebase, working for about a year. The AI pipeline completed the port in four months, though the process improvement loop was itself iterative. Each error led to changes in the implementation process rather than manual fixes to the code. The system learned how to do the port, not just to produce the output.

What the numbers show

Bun v1.4.0 resolved 128 bugs present in v1.3.14. Native memory leaks were eliminated. A bundling test running 2,000 consecutive Bun.build() operations plateaued at 609 MB in Rust, compared to climbing past 6.7 GB in Zig. HTTP throughput increased 2% to 5%. The test suite, all one million assertions, passes.

The port was not clean. The mechanical nature of the transpilation introduced 19 subtle semantic regressions rooted in syntactic similarities between Zig and Rust. Eleven rounds of security review from Claude Code Security fixed additional security issues. Twenty-four-seven coverage-guided fuzzing of every parser in Bun produced 15 pull requests addressing edge cases the test suite did not cover.

The criticism

Andrew Kelley, the creator of Zig, published a response arguing that the framing presents a false choice between a style guide and a language feature for avoiding bugs. His central point: the main way bugs are eliminated is by dedicating engineering resources to it, not by choosing a language. He also challenged the logic of the test suite argument. If the test suite is sufficient to catch bugs in a million lines of unreviewed machine-generated Rust, why was it insufficient to prevent the bugs in the Zig codebase that motivated the rewrite in the first place?

The question is not rhetorical. It points at a real tension. The test suite caught enough to ship, but the 19 semantic regressions and the 15 fuzzing pull requests suggest that passing tests and correctness are not the same thing. The mechanical port introduced bugs that look correct to a test suite but are not. Those are exactly the kind of bugs that compound over time.

What this means for large-scale AI-assisted development

Bun's rewrite is a test case for whether massive, AI-generated codebases can remain maintainable. The $165,000 cost is low relative to a year of three engineer salaries, but the ongoing maintenance cost is the open question. The 19 semantic regressions were found by humans and AI review. The fuzzing issues were found by automated testing. What happens when the next batch of contributors does not have the porting guide, the lifetime map, or the context to understand why a particular piece of Rust looks the way it does?

The patterns Sumner described, adversarial review agents, process improvement over artifact fixing, explicit lifetime catalogs, are transferable. The planning phase, where PORTING.md and LIFETIMES.tsv were written, is where the real engineering happened. The transpilation was mechanical. The decisions about how to represent Zig's memory model in Rust's type system were not. That part required humans who understood both languages deeply enough to write the mapping rules.

The industry will watch whether Bun's Rust codebase stays clean or accumulates the kind of technical debt that large machine-generated codebases tend to produce. The answer will shape whether this approach becomes a template or a cautionary tale.