Skip to content
AI Primer
workflow

Bun Rust rewrite becomes AI-assisted coding case study with estimated $165k API cost

Simon Willison highlighted Jarred Sumner’s Bun rewrite from Zig to Rust as an AI-assisted workflow using trial runs, dynamic planning, adversarial review, and verification. One estimate put API token cost near $165k.

5 min read
Bun Rust rewrite becomes AI-assisted coding case study with estimated $165k API cost
Bun Rust rewrite becomes AI-assisted coding case study with estimated $165k API cost

TL;DR

  • Bun's Rust rewrite cleared a big verification bar: theo's screenshot lists 0 skipped or deleted tests, 6,778 commits, and Linux, macOS, and Windows runs above 57K tests.
  • The token bill was not theoretical: the same screenshot puts pre-merge work at 5.9B uncached input tokens, 690M output tokens, 72B cached input reads, and about $165K at API pricing.
  • The workflow was agentic engineering, not a prompt demo: Simon Willison's RSS item names dynamic workflows, trial runs, and adversarial review.
  • The generalization limit was testability: dexhorthy's warning says many projects lack Bun's architecture and comprehensive tests, while trq212's caveat says most apps are not as verifiable as Bun.

Jarred Sumner's post, as summarized by Simon Willison's RSS item, praises Zig before narrowing the Rust rationale to memory-management bugs. A screenshot shared by akbirkhan says the run was one engineer using Fable and closely monitoring Claude Code. Joel Spolsky's old rewrite warning is the background noise; the new datum is 6,778 commits under a cross-platform runtime test suite.

Rewrite ledger

The useful accounting is unusually concrete:

  • 0 tests skipped or deleted.
  • 11 days from May 3 to merge on May 14.
  • 6,778 commits.
  • Debian 13 x64: 1,386,826 expect() calls, 60,624 tests, 4,174 files.
  • macOS 14 arm64: 1,259,953 expect() calls, 58,850 tests, 4,175 files.
  • Windows 2019 x64: 1,007,544 expect() calls, 57,337 tests, 4,173 files.
  • Pre-merge token use: 5.9B uncached input tokens, 690M output tokens, and 72B cached input token reads.
  • Estimated API price: about $165K.

The same screenshot says the hand-written counterfactual was three engineers with full codebase context for about a year. theo's follow-up compressed that into the labor comparison: cheaper than three engineers costing more than $250K a year.

The price line also became a model-market argument. dwarkesh_sp read the $165K estimate as evidence that the best model provider could charge much more if frontier competition stopped compressing margins.

Agentic workflow

Rewriting Bun in Rust

Rewriting Bun in Rust Jarred Sumner has been promising this blog post (since May 9th) about his Zig to Rust rewrite of Bun for significantly longer than it took him to finish the rewrite. Honestly, it was worth the wait. This is a detailed description of an extremely sophisticated piece of agentic engineering, featuring dynamic workflows, trial runs, adversarial review and all sorts of other interesting tricks. Jarred spends the first half of the post praising Zig for getting Bun this far. Then we get to a core idea in the piece, emphasis mine: Our bugfix list felt bad and I was tired of going to sleep worrying about crashes in Bun. I don't blame Zig for that - other users of Zig don't have the bugs we had, and mixing GC with manually-managed memory is an uncommon enough thing for software to need that no language really designs for it. We wouldn't have gotten this far if not for Zig, and I'll always be grateful. Until very recently, programming language choice was a one-way decision for a project like Bun. Everyone knows you should never stop the world and rewrite a large piece of software from the ground up. Joel Spolsky highlighted that in Things You Should Never Do, Part I back in April 2000! Coding agents powered by today's frontier models change that equation. Why pick Rust? It all came down to those challenges with memory management: A large percentage of bugs from that list are use-after-free, double-free, and "forgot to free" in an error path. In safe Rust, these are

Willison described Sumner's post as an "extremely sophisticated piece of agentic engineering." His summary names three mechanics that matter more than the headline language switch:

  • Dynamic workflows.
  • Trial runs.
  • Adversarial review.

The operating mode in akbirkhan's screenshot was one engineer using Fable while closely monitoring Claude Code, moving from start to 100 percent of the test suite passing on all platforms in 11 days.

Agent-watchers immediately wanted the harness. jediahkatz's reply asked for the custom setup with "64 claudes" that wrote the blog post.

Rust motive

Rewriting Bun in Rust

Rewriting Bun in Rust Jarred Sumner has been promising this blog post (since May 9th) about his Zig to Rust rewrite of Bun for significantly longer than it took him to finish the rewrite. Honestly, it was worth the wait. This is a detailed description of an extremely sophisticated piece of agentic engineering, featuring dynamic workflows, trial runs, adversarial review and all sorts of other interesting tricks. Jarred spends the first half of the post praising Zig for getting Bun this far. Then we get to a core idea in the piece, emphasis mine: Our bugfix list felt bad and I was tired of going to sleep worrying about crashes in Bun. I don't blame Zig for that - other users of Zig don't have the bugs we had, and mixing GC with manually-managed memory is an uncommon enough thing for software to need that no language really designs for it. We wouldn't have gotten this far if not for Zig, and I'll always be grateful. Until very recently, programming language choice was a one-way decision for a project like Bun. Everyone knows you should never stop the world and rewrite a large piece of software from the ground up. Joel Spolsky highlighted that in Things You Should Never Do, Part I back in April 2000! Coding agents powered by today's frontier models change that equation. Why pick Rust? It all came down to those challenges with memory management: A large percentage of bugs from that list are use-after-free, double-free, and "forgot to free" in an error path. In safe Rust, these are

Willison's excerpt says Sumner did not frame Zig as the villain. Bun got as far as it did because of Zig, but the bug list concentrated in memory-management failures:

  • Use-after-free.
  • Double-free.
  • Forgotten free in an error path.
  • Crashes around mixing garbage collection with manually managed memory.

Safe Rust changes that error surface. trq212's reply put the operational version more bluntly: the rewrite was "incredibly cheap and worthwhile" because it reduced memory burden and removed a class of segfault errors.

Verification boundary

The strongest caution was not anti-agent. It was about which codebases can absorb a rewrite at Bun's scale.

Two conditions from dexhorthy's warning define the boundary:

  1. The system is already designed and architected.
  2. The system has a comprehensive test suite and is highly verifiable.

trq212's caveat made the same point from the pro-rewrite side: most apps are not as testable and verifiable as Bun. NickADobos's post split the debate by job layer, with low-level platform work and hard CS research needing more detailed code scrutiny than high-level product work.

Review granularity

The review debate moved from whether agents can produce code to which granularity deserves human attention. mattlam_'s question asked whether reviewing each line still makes sense when agent output volume jumps, then named system design, reliability, and idempotency as higher-level review targets.

mattpocockuk framed the new role as lead developer, not mid-level implementer. mattpocockuk's delegation reply called strategic programming and delegation essential in the AI age.

dejavucoder gave the shortest version: do not read all the code, but keep an embedding of the code in your mind.

Two link-only posts from jxnlco and jxnlco's follow-up sat in the same discussion packet; the concrete review claims in the evidence came from the threads above.

Post-agent quality gates

mattrickard described Corigin's post-agent gates as so strict that they are "not really a linter anymore." The stack he listed is closer to a deterministic harness around agent output:

  • Every agent code smell becomes a regression AST rule.
  • Some rules are autofixed deterministically; others require an agent.
  • Valid code patterns can still be banned as policy.
  • TypeScript any and unknown are banned.
  • Rust unsafe is banned by default and isolated when needed.
  • Custom styles, CSS files, barrel files, and dynamic imports are banned.
  • process.env is allowed only in a special file.
  • OpenAPI clients, data-table objects, and React helpers are generated.
  • Unused code, duplicated code, and useless abstractions are scanned.
  • AGENTS.md files are synced from specs at granular folder levels, while the root file stays small.
  • Agents are forced into spec mode or code mode, with no spec changes during implementation and no code changes during spec writing.

A haider1 post quoting GitHub VP Scott Hanselman put the architecture concern plainly: AI does not generate architecture, and without a strong development lifecycle it creates large messy "God objects."

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 6 threads
TL;DR1 post
Rewrite ledger1 post
Agentic workflow1 post
Rust motive1 post
Verification boundary1 post
Review granularity3 posts
Share on X