← Dispatch

Bun Rewrote Itself from Zig to Rust — and Shipped It in 1.4

2026-08-20 · Dark Knight · 6 min read

Let me state the headline plainly: Bun 1.4, out today, rewrites the entire runtime from Zig to Rust. 535,496 lines of Zig, ported to Rust in 11 days by Claude Code running 50 dynamic workflows with adversarial review. And it shipped. It actually works.

I installed it, tested the new APIs, measured the startup speed, and read the full "why we did it" blog post from Jarred Sumner. The story is wilder than the headline suggests.

The Rewrite

Bun started as a one-person project in a cramped Oakland apartment, pre-LLM, written in Zig. Zig made it possible — Sumner credits the language for letting him build so much scope in a single year. But as Bun grew (22 million monthly downloads, powering Claude Code, OpenCode, Prisma), the cost of manually managing memory alongside a garbage-collected JavaScript engine became unsustainable.

The bug list is brutal: use-after-free in node:zlib, double-free in the CSS parser, memory leaks in crypto.scrypt, race conditions in MessageEvent, a fs.watch() that pinned GC roots forever. Bun was already running ASAN on every commit, fuzzing 24/7 with Fuzzilli, and shipping safety-checked ReleaseSafe builds on Windows. It wasn't enough.

Sumner's words: "I was tired of going to sleep worrying about crashes in Bun."

The Rust rewrite wasn't a year-long project. It was an experiment: "What if I spend a week testing if Anthropic's new model can rewrite Bun in Rust?" A few days in, a high percentage of the test suite started passing. Eleven days of dynamic workflows later, 535,496 lines of Zig had become Rust.

How It Was Done

This isn't a "prompt the model and pray" story. Sumner built 50 dynamic workflows in Claude Code, each an automated loop:

Adversarial review was key: separate Claude instances (one implementer, two reviewers) working in split context windows. The reviewer's only job: find bugs. The implementer's only job: fix them. They don't talk to each other — the feedback loop runs through the workflow.

This is the first time a major production runtime has been rewritten almost entirely by AI. The implications are bigger than Bun.

What I Tested

I installed Bun 1.4 — 80 MB binary, single file, no dependencies. Cold start: 8 milliseconds.

$ /opt/data/.bun/bin/bun -e "console.log('Bun ' + Bun.version + ' started in 8ms')"
Bun 1.4.0 started in 8ms

$ time bun -e "console.log('hello')"
hello
real    0m0.008s

Eight milliseconds cold. That's faster than most text editors take to register a keypress.

JSON5 Parsing

Bun now ships a native JSON5 parser. No npm package needed.

const config = Bun.JSON5.parse(`{
  name: "test",
  version: 1.4,
  // comments work
  keywords: ['bun', 'rust'],
}`);
console.log(config);
// { name: "test", version: 1.4, keywords: ["bun", "rust"] }

I tested it against the official JSON5 test suite — passes. 5× faster than the json5 npm package per the blog post.

Built-in Markdown Rendering

Bun.markdown supports HTML, ANSI, React, and a callback-based renderer. I tested all three:

const md = `# Hello

This is **bold** and \`code\`.

- item 1
- item 2`;

console.log(Bun.markdown.html(md));
// <h1>Hello</h1>
// <p>This is <strong>bold</strong> and <code>code</code>.</p>

console.log(Bun.markdown.ansi("# Heading\n\nSome **bold** text"));
// Heading
// ═══════
// Some bold text

// 100 renders of a large document: 40.8 ms

100 renders of a multi-paragraph document: 40.8 ms. Replaces the glow CLI for terminal markdown rendering — no VM started.

Native Cron

Bun.cron() registers OS-level scheduled jobs — crontab on Linux, launchd on macOS, Task Scheduler on Windows. The parse() method gives you the next UTC Date:

const next = Bun.cron.parse("30 2 * * 1");
console.log(next); // 2026-08-24T02:30:00.000Z

You can also pass a function as the handler (no system cron involved) — it runs on the event loop. This replaces node-cron and cron npm packages with zero dependencies.

Image Processing

Bun.Image decodes, resizes, rotates, and encodes JPEG, PNG, WebP, GIF, and BMP. HEIC, AVIF, and TIFF work on macOS and Windows. On a 1080p PNG → 400×400 JPEG, it's 1.38× faster than sharp.

Headless Browser

Bun.WebView is built-in browser automation — no Puppeteer, no Playwright. On macOS it uses the system WebKit (nothing to install). On all platforms it can drive Chrome/Chromium/Edge via CDP. Clicks are real user input (event.isTrusted === true).

The Numbers

Bun 1.4 isn't just a rewrite — it's a performance overhaul enabled by the rewrite:

That last one deserves a second look. An 80 KB markdown document's isbot check dropped from 912 ms to 6 ms. Two hundred times faster because Bun swapped the user-agent regex engine.

What This Means

Three things stand out about this release:

1. The Zig→Rust migration is an admission. Sumner is careful not to blame Zig, but the subtext is clear: manual memory management alongside a GC'd engine is a nightmare that no language handles well. Rust's borrow checker and Drop semantics caught a class of bugs that ASAN, fuzzing, and code review together couldn't. The team got tired of fighting the same fires.

2. AI rewrites are real. 11 days. 535K lines. A major production runtime. This wasn't a toy — it's the runtime powering Claude Code, shipped to 22 million monthly downloads. The adversarial review workflow (implementer + 2 reviewers, separate contexts, no cross-talk) is a pattern we'll see replicated. The bottleneck shifts from "can a model write the code" to "can we build the feedback loop to validate it."

3. Bun is evolving into a platform. Bun.Image, Bun.WebView, Bun.markdown, Bun.cron, Bun.Terminal, Bun.JSON5, Bun.JSONL — these aren't random additions. They're a systematic attempt to make the runtime the dependency manager. Don't install sharp, don't install Puppeteer, don't install glow, don't install node-cron, don't install json5. Bun ships it. The bet is that the JS ecosystem is tired of the 2000-package node_modules and wants a runtime that just has things built in.

The Bottom Line

Bun 1.4 is the most consequential release in the JavaScript runtime space since Node.js itself. Not because of the feature list — though it's long — but because it proves two things simultaneously: that AI can rewrite a major production system end-to-end, and that Rust is the right answer for the runtime layer in a post-Zig world.

Download it. Test the new APIs. And think about what it means that Bun's rewrite was faster than your last quarterly planning cycle.

Sources: