AI

Bun Migrates 530,000 Lines of Code from Zig to Rust in 11 Days Using Claude Fable 5

Jarred Sumner, creator of Bun, used Claude Fable 5 to migrate 530,000 lines of Zig code to Rust in 11 days. The upcoming Bun 1.4 will feature Rust. Major results include eliminating memory leaks and reducing binary size by around 20%.

7 min read Reviewed & edited by the SINGULISM Editorial Team

Bun Migrates 530,000 Lines of Code from Zig to Rust in 11 Days Using Claude Fable 5
Photo by Cesar Carlevarino Aragon on Unsplash

Jarred Sumner, the creator of the JavaScript runtime “Bun,” announced on July 8, 2026, via the official blog that he had successfully migrated approximately 530,000 lines of Zig code to Rust using Anthropic’s AI agent “Claude Fable 5” in just 11 days. The next version, Bun 1.4 (Canary), will be this Rust-based version.

The migration achieved the complete elimination of memory leaks. Binary size was reduced by approximately 20%, and performance improvements of 2% to 5% were observed. According to a report by Publickey’s jniino, Sumner remarked, “Without Zig, we wouldn’t have advanced Bun’s development this far.” However, he explained that the decision to migrate to Rust was driven by the need to create stable software that can be used without worrying about crashes, emphasizing Rust’s memory safety features.

Bun is a high-performance JavaScript runtime compatible with Node.js. It was adopted as the runtime for Anthropic’s AI tool “Claude Code,” and Anthropic announced its acquisition of Bun in December 2025. The large-scale code migration is viewed as a strategic move to enhance product quality following the acquisition, rather than merely a technical refresh.

The 11-Day Large-Scale Migration

According to Sumner, the pre-migration version of Bun was built on approximately 530,000 lines of Zig code, supplemented with C++ and related libraries to operate SQLite and JavaScript Core. For the migration, Sumner utilized the previously unreleased “Claude Fable 5” AI tool, a foundation of Claude Code.

Initially, Sumner spent about three hours discussing with Claude how to map Zig code patterns closely to Rust. The results of these discussions were documented in “PORTING.md.” To address the transition from Zig’s manual memory management to Rust, which uses lifetimes to manage memory, Sumner provided the following instructions to Claude Code:

Me: Let’s kick off a dynamic workflow to analyze the proper lifetimes of every struct field in the codebase. This workflow should read every struct field within every single file and trace the control flow. First, look for struct fields with complex lifetimes to express in Rust, then propose a lifetime for that field, then use 2 adversarial review agents to review that lifetime, then apply any feedback and serialize into a LIFETIMES.tsv for other claudes to look at.

These instructions guided the AI to read all structure fields in the codebase, trace their behavior, propose lifetimes for Rust, and validate the proposals using two adversarial review agents. The outcomes were serialized into a file named “LIFETIMES.tsv,” which Sumner personally reviewed.

Why Migrate from Zig to Rust

Bun was originally developed in Zig. While Sumner appreciated Zig’s expressiveness and performance, he ultimately prioritized memory safety for production-quality software. Since Zig relies on manual memory management similar to C, it carries risks of memory leaks, double frees, and crashes caused by invalid pointer operations.

Rust, on the other hand, addresses such memory-related bugs at compile time through its ownership system and lifetimes. Sumner aimed to make Bun a “stable software that works without worrying about crashes,” leading to the decision to migrate to Rust. Although Sumner had already been experimenting with the transition since May 2026, the full migration was realized through the use of Claude Fable 5.

As reported in a previous article (Bun Completes Full Rewrite from Zig to Rust), Claude Fable had already proven its utility in identifying critical bugs in sqlite-utils 4.0rc2 (Claude Fable Discovers Critical Bug in sqlite-utils 4.0rc2). However, the migration of Bun represents an even larger-scale application of this AI tool.

Designing a Dynamic Workflow

To automate the generation and review of Rust code, Sumner designed a dynamic workflow that coordinated numerous sub-agents. This workflow operated continuously for 11 days and followed a loop structure:

First, a migration guide was generated to map Zig patterns and types to their Rust equivalents. Next, all 1,448 Zig code files were mechanically converted to Rust code. After ensuring alignment with the guidelines in PORTING.md and LIFETIMES.tsv, all compile errors arising within Rust crates were resolved. Subsequently, Bun subcommands such as bun test and bun build were made executable, and the entire Bun test suite was run. Finally, extensive refactoring and cleanup were conducted.

According to Sumner, the bulk of the 11-day effort was spent monitoring the workflow, reviewing outputs, identifying problems or bugs, and iteratively refining the workflow and its instructions. Rather than personally reviewing the code, Sumner relied on test suites, assertions, and adversarial review agents within Claude to ensure the generation of correct code.

Adversarial Review Agents

Sumner expressed particular interest in the configuration of adversarial review agents. For each implementation agent, at least two review agents were deployed to thoroughly investigate why bugs occurred or why the code might not work as intended.

This method aims to achieve higher quality assurance compared to self-verification by a single AI. By having independent agents analyze the code and identify inconsistencies or issues, the system could uncover implementation errors and ensure consistency. This approach effectively mimics human code review “peer reviews” within an AI context.

6778 Commits and a $165,000 Cost

Thanks to parallelization within Claude Code, up to 1,300 lines of Rust code were generated per minute at peak performance, resulting in 6,778 commits throughout the process.

Sumner estimated that the usage of Claude amounted to roughly $165,000 (approximately ¥26.4 million at a conversion rate of 160 yen to the dollar). He noted that the work completed in 11 days would have taken three engineers a year to accomplish manually.

This cost structure demonstrates the economic efficiency of using AI agents for code migration compared to traditional manual efforts. Employing three senior engineers for a year would cost between ¥30 million and ¥50 million in Japan, making the ¥26.4 million spent on AI an economically viable alternative. However, it’s worth noting that this estimate does not account for post-migration maintenance costs or Sumner’s time spent designing the workflow for the AI agents.

Elimination of Memory Leaks and Performance

Improvements

The most significant achievement of the Rust migration was the eradication of memory leaks. With Zig’s manual memory management, developer errors in deallocation could lead to memory leaks. Rust’s ownership model determines memory deallocation at compile time, effectively eliminating such risks.

The approximately 20% reduction in binary size is attributed to the efficiency of Rust’s compiler in eliminating dead code and optimizing performance. The 2% to 5% performance improvement indicates that the overhead from translating Zig to Rust was minimized, while some optimizations further enhanced performance.

However, whether Rust’s type system can fully replace the low-level control flexibility offered by Zig will require further evaluation during long-term operations. This is particularly true for interfacing with C++ components like JavaScript Core, where the extent of Rust’s dependency on unsafe code could impact overall safety.

Editorial Opinion

In the short term, the release of Bun 1.4 (Canary) is likely to significantly impact the competitive landscape of the JavaScript runtime market. While Bun has so far outperformed Node.js and Deno in terms of startup speed and script execution speed, concerns over memory safety have been a barrier to its adoption in enterprise environments. By addressing this concern through the Rust migration, Bun may see accelerated adoption in CI/CD pipelines and server-side environments.

Considering Anthropic’s use of Bun as the runtime for its Claude Code tool, the improved stability of Bun directly enhances the quality of Anthropic’s products. Users of Claude Code stand to benefit from the stability improvements brought by the upgraded Bun runtime.

From a long-term perspective, this case represents a significant milestone, demonstrating that large-scale legacy code migration by AI agents has entered a practical phase. Historically, migrating an entire codebase to a new programming language has been a multi-year endeavor, often abandoned due to high risks and costs.

References

Frequently Asked Questions

Why was Bun migrated from Zig to Rust?
The primary reason was to enhance memory safety. Zig's manual memory management posed risks of memory leaks and crashes due to forgotten deallocations or invalid pointer operations. Rust's ownership system and lifetimes detect memory-related bugs at compile time, ensuring that Bun can become a robust and crash-free software.
How was the migration using Claude Fable 5 carried out?
Sumner first spent three hours discussing migration strategies with Claude, creating a migration guide (PORTING.md). He then designed a dynamic workflow to convert 1,448 Zig files into Rust. The process involved combining one implementation agent with at least two adversarial review agents, iterating through compile errors and tests until the code passed all test suites. At its peak, the workflow generated 1,300 lines of Rust code per minute.
What was the cost of the migration?
The API usage cost of Claude was approximately $165,000 (converted to ¥26.4 million at an exchange rate of 160 yen to the dollar). In comparison, Sumner noted that this work would have taken three experienced engineers a year to complete manually, making the cost of using AI economically competitive.
Source: Publickey

Comments

← Back to Home