Search site

    needhelp
    ← Back to blog

    Bun Rewrites 960K Lines from Zig to Rust in 6 Days — AI Did the Heavy Lifting

    by needhelp
    bunrustzigai-codegenjavascript-runtime

    Bun Zig to Rust rewrite

    On May 14, 2026, Bun creator Jarred Sumner merged PR #30412 — a sprawling 6755-commit branch that rewrites Bun’s core from Zig to Rust. The branch, claude/phase-a-p..., was almost entirely generated by Anthropic’s Claude AI agents.

    The numbers are staggering:

    Metric Value
    Commits 6,755
    Code translated ~960K lines of Zig → Rust
    Timeline 6 days
    Test compatibility 99.8% (Linux x64 glibc)
    Source branch claude/phase-a-p...

    What Actually Happened

    Bun was originally written in Zig, a systems programming language designed by Andrew Kelley. Zig gave Bun its speed — but it also limited the contributor pool. Rust, by contrast, has a massive ecosystem, mature tooling, and deep LLVM integration.

    After Anthropic’s acquisition of Bun, the team experimented with using Claude agents to translate the entire Zig codebase to Rust. The experiment ran for 6 days on a cluster of high-memory nodes, producing 6755 commits.

    The result: a Rust codebase that passes 99.8% of Bun’s existing test suite on Linux x64 glibc.

    AI-Driven Migration at Scale

    This is among the first large-scale demonstrations of AI-driven codebase migration. The approach:

    1. Source analysis: Claude analyzed Zig code patterns, memory management idioms, and the public API surface
    2. Incremental translation: Each Zig file was translated to Rust incrementally, preserving behavior through property-based testing
    3. Parallel execution: Multiple Claude agent instances worked in parallel across the codebase
    4. CI validation: Each translated module was validated against Bun’s existing test suite

    AI migration pipeline

    The Controversy

    The merge has sparked intense debate across the developer community:

    Zig Community

    Bun was Zig’s flagship project — the largest and most visible production deployment of the language. Loris Cro, a Zig Software Foundation member, has previously described LLM contributions to Zig as “mostly negative.” The migration is seen by some as a betrayal of the language that made Bun possible.

    “Vibe Porting” Critiques

    On Lobste.rs, developers coined the term “vibe porting” — AI-driven translation that works statistically but lacks deep understanding. Critics argue that Rust code generated by AI follows superficial patterns and misses the idiomatic Rust way.

    Jarred’s Cautious Take

    In earlier HN comments, Sumner emphasized: “We haven’t committed to rewriting. There’s a very high chance all this code gets thrown out completely.” Yet the merge to main suggests the experiment exceeded expectations — or that the strategy shifted.

    What This Means

    For Bun Users

    Short-term: nothing changes. The Rust port maintains API compatibility. Long-term: a larger contributor pool, better integration with the Rust ecosystem (crates like tokio, hyper, reqwest), and potentially faster iteration.

    For Zig

    Zig loses its flagship project. But the language continues to evolve — and the Bun port may attract developers who want to work on a Rust-based runtime.

    For AI Code Migration

    This is a watershed moment. If a 960K-line systems-level runtime can be ported in 6 days by AI, the economics of software rewrites change fundamentally. Maintenance, legacy migration, and language porting — historically expensive and risky — become tractable.

    Community Reactions

    Source Sentiment
    Hacker News Split — impressed by AI capability, skeptical of code quality
    Lobste.rs Critical — “vibe porting” discussion, concerns about idiomatic Rust
    Stork.ai analysis Strategic analysis of Zig vs Rust dynamics
    DevClass Neutral reporting, notes port is still “half-baked”
    CosmicJS Reports 99.8% test compatibility

    Looking Forward

    The Bun Rust rewrite isn’t finished — 99.8% is not 100%, and reviewers have flagged areas where the AI translation fell short. But the fact that this experiment reached main at all signals a new chapter not just for Bun, but for how we think about software rewrites.

    As one commenter on HN put it: “The old question was ‘should we rewrite it in Rust?’ The new question is ‘should we let AI rewrite it in Rust for us?’”

    References

    Share this page