# sumner-bun-rewrite-rust-claude-2026-07-08

## Veille

First-rate technical account by **Jarred Sumner**, creator of **Bun** (JS/TS runtime, >22M downloads/month), on the **complete rewrite of Bun from Zig to Rust in 11 days** (May 3→14, 2026) driven by **Claude** — an exceptional case study in AI-assisted software engineering **at industrial scale**. Motivation: a recurring class of bugs (use-after-free, double-free, leaks) arising from the mix of GC-managed memory (JavaScriptCore) and manual memory (Zig); in **safe Rust**, these bugs become **compile errors** with automatic cleanup (`Drop`/RAII) — "a better feedback loop than a style guide." Rejecting the dogma that "a rewrite is always a bad idea" (a year of bugfix freeze for 3 engineers), Sumner chooses a **mechanical port** (preserve the architecture, minimal behavior change) validated by the **existing test suite, written in TypeScript and therefore language-independent** (60,624 tests, 1.39M `expect()` assertions, 0 tests removed, 6 platforms). The harness: **~50 dynamic workflows** in **Claude Code**, *write → 2+ adversarial reviewers → apply* loops, up to **64 Claude instances in parallel** (4 worktrees × 16), with **PORTING.md** + **LIFETIMES.tsv** generated in preparation. Numbers: **6,502 commits** (peak 695/h, 58/min, ~1,300 lines/min), final diff **+1,009,272 lines**, ~16,000 compile errors treated as a queue, **5.9B uncached input tokens + 690M output ≈ $165,000**. Key methodological levers: **adversarial review** (a second Claude, separate context, sees only the diff, tasked with finding why it's wrong — catches subtle bugs that are *semantically* different but *syntactically* identical) and the principle **"fix the process that generates the code, not the code by hand."** Model used: a pre-release of **Claude Fable 5** (Mythos class). Since the merge: **11 rounds of Claude Code security review**, 24/7 coverage-guided fuzzing (100B executions → ~15 PRs), **4% `unsafe` code** (78% on a single line), **19** known regressions fixed. In production: Claude Code v2.1.181, the first release on Bun-in-Rust, **+10% faster startup on Linux**. Disclosed upfront: **Bun was acquired by Anthropic in December 2025**.

## Titre Article

Rewriting Bun in Rust

## Date

2026-07-08

## URL

https://bun.com/blog/bun-in-rust

## Keywords

Bun, Jarred Sumner, Zig-to-Rust rewrite, mechanical port, JavaScript TypeScript runtime, esbuild, Anthropic acquisition, Claude Fable 5, Mythos class, Claude Code, dynamic workflows, harness engineering, 64 Claude instances in parallel, git worktrees, adversarial review, adversarial review, split context windows, 1 implementer 2 reviewers 1 fixer, write-review-apply loop, fix the process not the code, PORTING.md, LIFETIMES.tsv, safe Rust, Drop, RAII, use-after-free, double-free, memory leak, garbage collector, JavaScriptCore, manual memory management, defer errdefer, style guide, TigerStyle, smart pointers, ~100 crates, cyclic dependencies, 16000 compile errors, error queue, smoke tests, systemd-run cgroups, isolation, language-independent TypeScript test suite, 60624 tests, 1, 39M expect assertions, 0 tests removed, 6 platforms, Buildkite CI, 6502 commits, 1009272 lines, 5, 9 billion input tokens, 690M output tokens, 165000 dollars, 11 days, ReleaseSafe, Address Sanitizer, ASAN, Fuzzilli, coverage-guided fuzzing, 100 billion executions, 11 rounds security review, unsafe code 4%, 19 regressions, debug_assert macro, semantically different syntactically identical, Claude Code v2.1.181, 10% faster startup, cross-language LTO, binary 20% smaller, one engineer can do a lot more, graveyard of dead side projects

## Authors

Jarred Sumner (créateur de Bun ; travaille chez Anthropic depuis le rachat de Bun en décembre 2025)

## Ton

**Profile**: first-person technical engineering post (official Bun blog), long-form (~5000 words), aimed at systems/runtime engineers and the AI-assisted software engineering community. **Upfront disclosure** ("Bun was acquired by Anthropic in December 2025; I used a pre-release of Claude Fable 5"), which defuses the conflict of interest without hiding it. Very high technicality (lifetimes, `Drop` vs `defer`, cyclic crate dependencies, negative timespec, eager `unwrap_or` vs lazy `unwrap_or_else`) but pedagogical: every decision is motivated by the reasoning "how would a human do this?"

**Style**: avowed methodological honesty — the author recounts his **false starts** (Claude doing `git stash`/`reset` and colliding between instances; Claude "stubbing" functions instead of fixing them; debug timeouts; disk saturated from insufficient IOPS) as much as his successes. Explicit rejection of the magic prompt ("Rewrite Bun in Rust. Don't make any mistakes." is *not* what he did). Sincere acknowledgment of the tool he's leaving behind ("Zig made Bun possible… I'll always be grateful"). Notable verbatim quotes: *"The default outcome for ambitiously-scoped projects like Bun is joining the graveyard of dead side projects"*, *"One engineer can do a lot more today than a year ago"*, *"If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code"*, *"This is the bleeding edge of what's possible today"*. Rich in data visualizations (commits per hour, the race to green by platform, an 11-day replay). Sourced with real commit numbers (review attribution in the commit subject).

## Pense-betes

- **Key idea: language rewrites are no longer a one-way decision.** Historically, changing the language of a project like Bun (535,496 lines of Zig) = ~1 year for a small team, with **a freeze on bugfixes, security, and features** — therefore unrealistic, therefore "you never do it." Agentic AI transforms this trade-off: *"What if I spend a week testing if Anthropic's new model can rewrite Bun in Rust?"* Result: **11 days**.
- **The "why Rust" argument is about feedback loops, not taste.** The dominant bug class (use-after-free, double-free, missed `free` calls on error paths) comes from mixing **GC memory (JavaScriptCore) × manual memory (Zig)** — a case few languages are designed for. In **safe Rust**, these become **compile errors** + automatic cleanup (`Drop`, RAII). "Compiler errors are a better feedback loop than a style guide." Zig favors explicit `defer` (no hidden control flow); the alternative — homegrown smart pointers — offered "worse ergonomics than Rust, without the guarantees."
- **The constraint that makes the bet feasible: a language-independent test suite.** Bun's tests are **written in TypeScript** → they don't depend on the implementation language. The port aims for **minimal behavior change**, validated by this suite (60,624 tests, 1.39M `expect()` calls, **0 tests removed or skipped**, verified by hand). This is the safety net that allows merging 1M lines generated by an LLM.
- **Mechanical port > redesign.** Explicit choice: preserve the Zig architecture, minimize changes, leave **idiomatic** Rust for *after* the v1.4 ship. "Incremental vs all-at-once?" → all at once (as with his original esbuild Go→Zig port, without an LLM). Everything else "is just tactics."
- **The harness: ~50 dynamic workflows in Claude Code, looping for 11 days.** Pseudocode as stated: `while (task = todo.pop()) { result = task(); feedback = await [review(result), review(result)]; apply(feedback) }`. Dedicated workflows: generate the porting guide → mechanically port each `.zig` file to `.rs` → fix compile errors per crate → get the subcommands passing (`bun test`, `bun build`) → get the whole suite passing → refactors/cleanup.
- **Adversarial review, the core of reliability.** A **second Claude, in a separate context, that sees ONLY the diff** (none of the implementer's reasoning), tasked with "finding why it's wrong." Ratio of **1 implementer / 2+ adversarial reviewers / 1 fixer**; the implementer doesn't review, the reviewer doesn't implement (as with humans, the person who writes the code is biased toward merging). Catches bugs that are **syntactically identical but semantically different**: a `Box` dropped before an asynchronous `uv_close` (UAF + double-free); a negative timespec via `trunc` vs `floor`; an **eager** `unwrap_or` that panics where a **lazy** `unwrap_or_else` would not have.
- **"Fix the process that generates the code, not the code by hand."** Guiding principle: when a bug or an anti-pattern appears, the **workflow/prompt gets edited**, not the file. E.g.: when Claude adds long comments to justify workarounds, a rule is added for reviewers → *"If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code."* One prompt edit, a few hours, the behavior disappears.
- **Preparation (de-risking) before writing a single line.** ~3 hours of discussion with Claude → **PORTING.md** (Zig→Rust pattern/type mapping). Then a workflow analyzing **the lifetime of every struct field** (reading + control-flow tracing, 2 adversarial reviewers), serialized into **LIFETIMES.tsv** for the other Claude instances. Then a **trial run on 3 files** before launching on the 1,448.
- **Parallelism and its false starts.** Launching all 1,448 files at once → the Claude instances collide (`git stash`/`stash pop`/`reset --hard`). Fix: **ban any git operation that doesn't commit a specific file**, no `cargo`, no slow commands. Then **4 shards / 4 worktrees × 16 Claude** = **~64 Claude instances** simultaneously. Peak: **1,300 lines/min**, **695 commits/h**, 58 commits/min. A slow `grep` froze the disk due to insufficient IOPS on the EC2 instance.
- **~16,000 compile errors treated as a queue.** Split into **~100 crates** (faster compilation) → reveals **cyclic dependencies** (the Zig codebase was a single compilation unit) → classification workflows followed by refactor workflows. `cargo check` writes errors to a file grouped by crate → distributed across 64 Claude instances. Isolation strengthened via **systemd-run (cgroups)** for memory-leak/stress tests (10k processes, gigabytes of disk fill, saturated TCP sockets).
- **The road to green (Buildkite CI, 6 platforms).** From 972 failing test files to 23 in 2 days; Linux fully green ~1 day before Windows; build #54202 = **6/6 platforms green** → merge. Merging ≠ releasing: enough confidence to commit, not yet to ship.
- **Cost, quantified and owned.** Pre-merge: **5.9B uncached input tokens + 690M output + 72B cache reads ≈ $165,000** at API pricing. Realistic human alternative: **3 engineers, ~1 year**, during which "we wouldn't have improved Node.js compat, fixed bugs/vulnerabilities, or shipped features" — therefore **never done**. "The realistic alternative was to do nothing and keep fixing the bugs forever."
- **After the merge, the work continues.** **11 rounds** of **Claude Code Security** review; **24/7 coverage-guided fuzzing** of all parsers (JS/TS/JSX/CSS/JSON5/TOML/YAML/Markdown/INI/Bun Shell/semver/.patch), **100B executions → ~15 PRs** (the fuzzer sends the repro to Claude, which submits the PR, followed by human review). **~4% `unsafe` code** (~13,000 `unsafe` blocks / ~780,000 lines), of which **78% on a single line** (a pointer coming from C++ or a C call) — expected to decrease toward idiomatic Rust. **19** known regressions, all fixed (e.g., the `debug_assert!` macro stripped in release builds → broken HMR).
- **The model and production.** A pre-release of **Claude Fable 5** ("a Mythos-class model"); Claude Code's dynamic workflows sustained **64 Claude instances for 11 days** ("otherwise I would have had to write my own harness"). First release on Bun-in-Rust: **Claude Code v2.1.181**, **+10% faster startup on Linux**, minimal user-facing changes → proof of production maturity.
- **Related**: agent-based code review / adversarial verification and consensus (Monperrus's "The End of Code Review," Kent Beck-style ADLC series "prosecution not code review" / "tests are the spec"); **Loop/Harness Engineering** (Lushbinary, Osmani, OpenAI Codex agent-first, the Ralph technique, git worktrees); Claude Code skills & dynamic workflows; Zig already in the corpus (ZML/LLMD, silicon sovereignty); token FinOps / cost per outcome.

## RésuméDe400mots

Jarred Sumner, creator of **Bun** (JS/TS runtime, >22M downloads/month, acquired by **Anthropic** in December 2025), recounts the **complete rewrite of Bun from Zig to Rust in 11 days** (May 3→14, 2026), driven by Claude. The motivation is a recurring class of bugs — use-after-free, double-free, leaks — arising from the mix of GC-managed memory (JavaScriptCore) and manual memory (Zig). In **safe Rust**, these bugs become **compile errors** with automatic cleanup (`Drop`/RAII): "a better feedback loop than a style guide."

Against the dogma that "a rewrite is always a bad idea" (a year of bugfix freeze for 3 engineers across 535,496 lines of Zig), Sumner opts for a **mechanical port**: preserve the architecture, minimize behavior changes, validate against the **existing test suite — written in TypeScript, and therefore language-independent** (60,624 tests, 1.39M assertions, 0 tests removed, 6 platforms).

The harness: **~50 dynamic workflows** in **Claude Code**, in *write → review → apply* loops, running continuously. The reliability building block is **adversarial review**: a second Claude, in a **separate context that sees only the diff**, tasked with "finding why it's wrong." Ratio of **1 implementer / 2+ reviewers / 1 fixer**; the implementer doesn't review their own work. It catches subtle bugs that are syntactically identical but semantically different (a `Box` dropped before an asynchronous `uv_close`; an eager `unwrap_or` that panics). Cardinal principle: **"fix the process that generates the code, not the code by hand"** — when an anti-pattern appears, the prompt/workflow gets edited.

Careful preparation: **PORTING.md** (Zig→Rust mapping) and **LIFETIMES.tsv** (lifetime of each struct field), a trial run on 3 files before the 1,448. Then **4 worktrees × 16 = ~64 Claude instances** in parallel, after banning all non-atomic git operations. Peak: **1,300 lines/min**, **695 commits/h**; **6,502 commits**, diff **+1,009,272 lines**, ~16,000 compile errors treated as a queue (split into ~100 crates, resolving cyclic dependencies).

Cost disclosed: **5.9B uncached input tokens + 690M output ≈ $165,000**, versus ~3 engineers for a year — "which we would never have done." Model: a pre-release of **Claude Fable 5** (Mythos class). Since the merge: **11 rounds** of Claude Code security review, 24/7 fuzzing (100B executions → ~15 PRs), **4% `unsafe` code**, **19 regressions** fixed. First release: Claude Code v2.1.181, **+10% faster startup on Linux**. "This is the bleeding edge of what's possible today."

## GrapheDeConnaissance

- Jarred Sumner —a_créé→ Bun (TECHNOLOGIE, 0.98)
- Bun —fait_partie_de→ Anthropic (ORGANISATION, 0.95)
- Jarred Sumner —travaille_chez→ Anthropic (ORGANISATION, 0.95)
- Jarred Sumner —utilise→ Claude Fable 5 (TECHNOLOGIE, 0.95)
- Bun —utilise→ Rust (TECHNOLOGIE, 0.97)
- Rust —remplace→ Zig (TECHNOLOGIE, 0.9)
- Rust —réduit→ use-after-free, double-free et fuites mémoire (erreurs de compilation en safe Rust) (AFFIRMATION, 0.9)
- Claude Fable 5 —permet→ réécriture mécanique de Bun de Zig vers Rust en 11 jours (AFFIRMATION, 0.9)
- réécriture de Bun en Rust —utilise→ dynamic workflows (METHODOLOGIE, 0.95)
- dynamic workflows —utilise→ revue adversariale (METHODOLOGIE, 0.92)
- revue adversariale —réduit→ régressions du code généré par LLM (CONCEPT, 0.88)
- Claude Code —permet→ ~64 Claude en parallèle pendant 11 jours (4 worktrees × 16) (AFFIRMATION, 0.9)
- réécriture de Bun en Rust —utilise→ suite de tests TypeScript indépendante du langage (CONCEPT, 0.92)
- Jarred Sumner —mesure→ ~165 000 $ (5,9 Md tokens d'entrée non cachés, 690 M en sortie) pour la réécriture (MESURE, 0.9)
- Jarred Sumner —recommande→ corriger le processus qui génère le code plutôt que le code à la main (AFFIRMATION, 0.9)
- Bun —utilise→ JavaScriptCore (TECHNOLOGIE, 0.9)
- Claude Code —utilise→ Bun (TECHNOLOGIE, 0.9)
- Bun (réécrit en Rust) —améliore→ démarrage de Claude Code de ~10 % sur Linux (MESURE, 0.85)
- coverage-guided fuzzing —résout→ bugs de parsers de Bun (100 Md exécutions → ~15 PRs) (AFFIRMATION, 0.85)
- Jarred Sumner —affirme_que→ one engineer can do a lot more today than a year ago (CITATION, 0.9)

---
Canonical: https://www.thekb.eu/en/fiches/sumner-bun-rewrite-rust-claude-2026-07-08/
