Anthropic Rewrote Bun in 11 Days. 13,365 Unsafe Blocks Came With It.

Anthropic Rewrote Bun in 11 Days. 13,365 Unsafe Blocks Came With It.

/ Maxim Starkweather / 8 min read

On May 14, 2026, Jarred Sumner merged a pull request into Bun’s main branch that has since been cited as a new benchmark for AI coding agents at scale: 535,496 lines of Zig code, rewritten as Rust, across 6,502 commits, in 11 days, by Claude Fable 5, at a cost of roughly $165,000 in API usage. The test suite — 1,386,826 assertions across 60,624 tests — passed without modification on all six platforms Bun targets. Not one test was deleted or skipped. Memory usage in two-thousand-build stress runs dropped from 6.7GB to 609MB. The binary shrank by 20%. The memory leaks that had accumulated in Bun’s build system for years were gone. Sumner described the result in the writeup as “the bleeding edge of what’s possible today.”

Two weeks later, Bun published a document on their own domain. It is titled “Bun’s unreleased Rust port has 13,365 unsafe blocks. Most can be removed.” The last four words are carrying most of the weight.

64 Claudes and an Adversarial Reviewer

The methodology behind the migration is not naive, and the coverage has mostly gotten this right. Before a single Zig file was touched, Sumner and his team spent three hours in conversation with Claude to produce two artifacts: PORTING.md, a translation guide encoding the conventions and structural decisions for the port, and LIFETIMES.tsv, a lifetime analysis that mapped Zig’s ownership semantics to their Rust equivalents before the translation began. These documents constrained what the translating instances could do — a pre-migration specification that the models had to operate within. The translation itself ran across roughly 50 dynamic workflows in parallel: implementer instances converted Zig files to Rust; adversarial reviewer instances received only the resulting diffs and the explicit instruction to assume the code was wrong; fixer instances handled the approximately 16,000 compiler errors generated by the initial passes. At peak, 64 Claude instances ran simultaneously across four worktrees, producing 695 commits in a single hour at 1,300 lines per minute.

Simon Willison described the approach as “a detailed description of an extremely sophisticated piece of agentic engineering,” and the description is accurate in a specific way. The adversarial reviewer pattern — pairing production agents with critique agents rather than using model output as the first and final draft — is an architecture decision with real engineering content behind it. Bun’s TypeScript conformance suite, which served as the ground truth for every commit throughout the migration, isn’t a purpose-built benchmark; it’s the actual test suite that ships to users, which means behavioral equivalence was enforced rather than approximated. The test suite passing on all six platforms simultaneously means something. The $165,000 purchased a system for doing the migration, not a lucky output from a single long context window.

Claude Code v2.1.181, released June 17, ships Bun’s Rust port as its runtime. The tool Anthropic used to write the migration is now running on the thing it wrote.

Server monitoring corridor: green-status units with scattered amber warnings — the visual ratio of sound code to unsafe assumptions in Bun’s AI-generated Rust port.

The Zig Conflict That Forced the Switch

The migration’s necessity was partly technical and partly organizational. Bun was written in Zig from its founding by Sumner. In December 2025, Anthropic acquired the company. Shortly after, Bun’s team attempted to contribute significant improvements upstream to the Zig compiler — parallelized semantic analysis, LLVM backend optimizations — and the Zig core team rejected them. The rejection was not primarily technical: the Zig project had adopted a strict no-AI-contributions policy, which put Bun’s team in a structural conflict with their upstream language. They were now part of an AI company where AI-generated code is standard production output, building a critical product on a language that prohibits it.

Sumner’s stated engineering case for moving to Rust is correct on the mechanics. Bun mixes garbage-collected JavaScript engine objects with manually managed memory while handling concurrent I/O at the throughput its users expect. In that environment, use-after-free, double-free, and memory-leak bugs are endemic to the architecture at scale — not occasional mistakes but a predictable consequence of the combination. Rust’s borrow checker converts that entire category of bug into a compile-time error. The two-thousand-build stress test result, memory usage dropping from 6.7GB to 609MB, is the proof of concept: those are real leaks, now gone. The migration delivered on its stated technical justification.

The case that Zig could have been sufficient with the right engineering discipline is Andrew Kelley’s, and Kelley is not arguing from abstraction. He points to TigerBeetle, the financial database written in Zig that has maintained memory safety through TigerStyle — a comprehensive set of architectural constraints that eliminate the dangerous allocation patterns before a language’s type system has anything to check. In his July 9 post on Ziggit, Kelley argues that Bun’s team never seriously pursued that path. His more specific claim: the $165,000 figure is misleading because what shipped is not an idiomatic rewrite but a translation that preserved Zig’s memory patterns inside Rust’s syntax. The actual full rewrite — the one that pays down the resulting debt — will cost substantially more and is not yet started.

What 13,365 Unsafe Blocks Mean

In Rust, the unsafe keyword tells the compiler to suspend its borrow-checker analysis for a section of code. Inside an unsafe block, the developer takes manual responsibility for the memory invariants the borrow checker would otherwise verify: that references don’t outlive what they point to, that there are no simultaneous mutable and immutable borrows, that raw pointers are valid before dereference. The compiler continues to check syntax. It no longer verifies soundness. Every memory safety guarantee that Rust is built on is, inside that block, the developer’s problem rather than the compiler’s constraint.

Sumner’s writeup acknowledges approximately 13,000 such blocks, placing them at roughly 4% of the 780,000-line Rust codebase. His position is that 78% are single-liners — a pointer passed from the C++ JavaScriptCore engine, one call into a C library — and that this reflects Bun’s architecture rather than carelessness. Bun keeps its JavaScript engine bindings and runtime logic in one workspace, whereas projects like Deno separate the two; that separation shifts the unsafe boundary into a different component, making comparisons against the primary repository look favorable. This architectural argument has merit for a portion of the count. The official unsafe audit reinforces it: roughly 70% of the blocks are theoretically convertible to safe Rust, and roughly 30% must remain unsafe due to FFI requirements. Eight remediation steps are outlined, prioritizing soundness first.

The comparison the audit doesn’t volunteer is to comparable Rust projects outside Bun’s own repository. The byteiota technical review ran that number: uv, a systems Rust project of comparable complexity, has 73 unsafe blocks in total. Bun has 13,365. The ratio is 181 to 1. Sumner’s architectural defense closes some of that gap — FFI-heavy codebases with embedded C++ engines accumulate unsafe in ways pure-Rust projects don’t — but the difference is not architectural all the way down. The byteiota review’s conclusion is direct: the high count reflects a design philosophy of shipping working code under time pressure, not a technical necessity.

Engineering cross-section: load-bearing structure with specification-grade connections and scattered field-repair work — analogous to idiomatic Rust with 13,365 unsafe exceptions.

The specific number that matters most in the audit is not 13,365. It is five. The audit found five functions containing reachable undefined behavior accessible from safe Rust — not edge cases that require unsafe code to trigger, but places where a caller writing only idiomatic, safe Rust can cause the called function to exhibit undefined behavior because the unsafe assumption inside that function is wrong. These are actual bugs, found before the port shipped, flagged by Bun’s own review. Presumably they will be fixed. The question the test suite cannot answer is how many of the other 13,360 unsafe blocks contain incorrect assumptions that weren’t exposed by the 1,386,826 assertions — assumptions that will hold under every load pattern tested and fail under the first production edge case that wasn’t in the suite.

What the Marketing Claims and What the Audit Shows

Ray Myers’ analysis of the controversy, which drove the Hacker News thread to 640 points Monday morning, adds a dimension Kelley’s critique doesn’t directly address: the conflict of interest embedded in the narrative. Myers notes that Anthropic owns Bun and makes Claude Code, which means the migration was simultaneously a real engineering project and a product demonstration. The writeup has since been used as evidence that Claude agents can perform large-scale systems-code work that professional developers previously considered manual and irreplaceable. Myers identifies a specific internal contradiction in the text: the team states it has not been typing code itself for many months, while also expressing concern about code ergonomics — a concern that only makes sense if humans are still making design decisions in the loop. The narrative of AI as primary author is partial.

What the migration actually demonstrates is more limited and also more interesting than either framing. A coordinated fleet of AI instances can translate a large codebase while preserving external behavior, under a narrow time constraint, at a cost that beats equivalent manual effort by a wide margin. The adversarial reviewer pattern — pairing each implementer instance with a dedicated critic rather than using model output as first and final draft — is a genuine engineering contribution. PORTING.md and LIFETIMES.tsv as pre-migration knowledge artifacts are practical templates for future work at this scale. “One engineer can do a lot more today than a year ago,” Sumner writes in the blog post, and that is true.

What the migration cannot demonstrate — and what this specific evidence set shows — is that AI coordination maintains the internal invariants of unsafe code when the time pressure is high and the compiler can be silenced with a keyword. When a borrow checker error was expensive to reason through across 64 simultaneous instances over 11 days, unsafe was the mechanism that let the code move forward. The test suite validated external behavior. The assumptions inside the blocks went unvalidated. Andrew Kelley’s characterization — slop produced without the engineering oversight that would have caught these patterns — is too strong for a migration that had genuine architecture behind it. It is not too strong for the specific finding that five unsafe functions are actively unsound in the port.

Anthropic will fix those five functions. The remediation plan in the audit will convert a portion of the theoretically-safe 70% into idiomatic Rust over coming months. The memory leaks are already gone and that is real. The binary is already smaller and that is real. What should persist from this episode is a more precise accounting of what AI-driven code migration actually delivers: behavioral correctness confirmed by a comprehensive test suite, performance improvements delivered at a cost that makes the migration economically rational, and internal soundness unverified by default. Not a finished artifact — a starting point. The next time an AI-powered migration ships a test suite passing on six platforms, the question worth asking before the celebration is how many unsafe blocks came with it, and how many of them are wrong.

AI-generated editorial image

AI-generated editorial illustration · TemperatureZero · July 13, 2026

Keep reading the signal

Get the Daily Signal — a concise briefing on what actually matters in AI and the systems around it.

Subscribe Free

Continue the archive

Latest BriefingsArticlesAbout Temperature Zero