Claude Rewrites 1 Million Bun Lines in 6 Days: Zig to Rust and AI‑Driven Refactoring

In just six days, Anthropic's Claude AI translated roughly one million lines of Bun from Zig to Rust, preserving the original architecture, achieving 99.8% test pass rate, reducing binary size, and sparking debate over unsafe code usage and the broader impact of AI‑powered large‑scale code migrations.

AI Architecture Path
AI Architecture Path
AI Architecture Path
Claude Rewrites 1 Million Bun Lines in 6 Days: Zig to Rust and AI‑Driven Refactoring

Bun is an all‑in‑one JavaScript/TypeScript toolchain built on Zig and JavaScriptCore, offering fast startup (3 ms), high performance, and zero‑config development. After Anthropic acquired Bun, it became the core runtime for Claude Code.

The migration began in early May 2026 with a new claude/phase-a-port branch and a 576‑line PORTING.md guide that mandated faithful file‑by‑file translation, retention of the original architecture, avoidance of complex Rust features, and mandatory comments for any unsafe code.

Claude completed the semantic conversion of 960 k lines from Zig to Rust in three days, leaving only three compilation errors; the resulting Rust build passed 99.8% of Bun's existing test suite within two additional days. The PR #30412 was merged on May 14, finalizing the switch.

The rewrite kept the original architecture and data structures, resulting in 100% test case success, a binary size reduction of 3–8 MB, and performance that was at least on par with the Zig version, all without using advanced Rust async features.

Key motivations for abandoning Zig included severe memory‑leak issues that caused Claude Code processes to grow from 1.7 GB to 14 GB in three hours, Zig's lack of a borrow checker leading to 4 700 unresolved issues, and a policy clash because the Zig community forbids AI contributions.

Community backlash focused on the high number of unsafe calls (over 13 000 in the 680 k‑line Rust code versus 73 in a comparable pure‑Rust project), accusations that the code was generated, reviewed, and merged entirely by AI, and speculation that Anthropic forced the language change to solve Claude Code's problems. Jarred Sumner refuted coercion claims, explaining that extensive C/C++ bindings naturally require many unsafe blocks and that the team will continue to reduce this count to around 10 000.

The six‑day rewrite is presented as a precedent: Cloudflare achieved a core Next.js API rewrite in a week using AI, and the Ladybird browser migrated its JavaScript engine from C++ to Rust in two weeks. These examples illustrate that AI can compress traditional month‑long migrations into days, accelerate the Rust adoption of JavaScript toolchains, and shift software engineering practices toward human‑defined goals with AI‑generated implementation.

In conclusion, Bun's transition from Zig to Rust demonstrates that AI can resolve long‑standing memory and safety challenges while opening the door to rapid, large‑scale code refactoring, though it also raises questions about code quality, review rigor, and the evolving role of developers.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

RustZigSoftware EngineeringBuncode migrationClaude AIAI-driven refactoring
AI Architecture Path
Written by

AI Architecture Path

Focused on AI open-source practice, sharing AI news, tools, technologies, learning resources, and GitHub projects.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.