---
title: "Rewriting Bun in Rust"
description: "Bun, a 535k-line Zig JavaScript runtime, was mechanically ported to Rust over 11 days using about 50 continuously running Claude Code workflows."
url: "https://swe.quest/articles/rewriting-bun-in-rust-9aa67adf0dcbde60"
canonical: "https://bun.com/blog/bun-in-rust"
source: "Bun"
published: "2026-07-08"
difficulty: "medium"
kind: "Case study"
reading_minutes: 29
tags: ["rust","zig","ai-coding","refactoring","memory-safety"]
---

# Rewriting Bun in Rust

A post on [Bun](https://swe.quest/sources/bun.md), published 2026-07-08, 29 min read, Case study. Original: [https://bun.com/blog/bun-in-rust](https://bun.com/blog/bun-in-rust)

## Summary

Bun, a 535k-line Zig JavaScript runtime, was mechanically ported to Rust over 11 days using about 50 continuously running Claude Code workflows. The motivation was a steady stream of use-after-free, double-free and leak bugs that came from mixing JavaScriptCore's garbage-collected values with manually managed Zig memory. The port was done all at once in a deliberately Zig-shaped style, guided by a porting guide and a lifetimes map, and validated against Bun's language-independent TypeScript test suite. Adversarial review in separate context windows caught bugs such as Box drops before async uv\_close, negative-time timespec errors, and eager unwrap\_or evaluation; cleanup toward idiomatic, less-unsafe Rust is planned after v1.4.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Zig](https://swe.quest/tags/zig.md) (Languages)
- [AI for coding](https://swe.quest/tags/ai-coding.md) (AI & ML)
- [Refactoring & migrations](https://swe.quest/tags/refactoring.md) (Engineering practices)
- [Memory safety](https://swe.quest/tags/memory-safety.md) (Security)

## Prerequisites

- manual memory management ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))
- Rust ownership and Drop ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- garbage-collected runtimes ([easy posts on Runtimes & VMs](https://swe.quest/tags/runtimes.md?difficulty=easy))

## Keywords

Bun, Zig, Rust, Claude Code, JavaScriptCore, libuv, AddressSanitizer, Fuzzilli

## Related posts

- [Bun 1.4](https://swe.quest/articles/bun-1-4-fea28913dacb5d89.md): Bun · 2026-08-20 · Medium · 217 min read · Runtimes & VMs, JavaScript, Performance engineering, Memory management, Rust
  Bun 1.4 adds 1,517 newly passing Node.js test-suite tests, fixes over 2,900 issues, and rewrites Bun from Zig to Rust.
- [Bun v1.1.7](https://swe.quest/articles/bun-v1-1-7-443b16215b4eb538.md): Bun · 2024-05-03 · Medium · 7 min read · JavaScript, Runtimes & VMs, Debugging
  Bun v1.1.7 fixes 28 bugs and adds glob patterns in package.json workspaces (via Bun.Glob), asymmetric matcher support in expect.extend's this.equals, and a working bunx --version.
- [Bun v1.2.1](https://swe.quest/articles/bun-v1-2-1-aab3e8d9e0004536.md): Bun · 2025-01-27 · Medium · 7 min read · JavaScript, Runtimes & VMs, Memory management, Zig
  Bun v1.2.1 fixes 32 bugs and adds S3 storage class support, X25519 key generation in crypto.generateKeyPair, Node's --zero-fill-buffers flag, indented inline snapshots in bun test, and a bunfig option to disable minification for HTML imports.
- [Bun v1.3.10](https://swe.quest/articles/bun-v1-3-10-809e937e8a78ed82.md): Bun · 2026-02-26 · Medium · 19 min read · JavaScript, Runtimes & VMs, Performance engineering, Build systems, TypeScript
  Bun v1.3.10 replaces its npm-based REPL with a native Zig REPL that supports top-level await, imports, history and tab completion.
- [Bun v0.1.9](https://swe.quest/articles/bun-v0-1-9-4ecfe167e5b29929.md): Bun · 2022-08-18 · Medium · 3 min read · Runtimes & VMs, JavaScript, Zig, Performance engineering, Compilers
  Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making \`ptr()\` in \`bun:ffi\` 6-10x faster and \`TextEncoder.encodeInto\` 1.5-5x faster.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
