How to Ship Millions of Lines of Agent-Written Code with Jarred Sumner, Anthropic

Shipping a multi-million-line, agent-written ahead-of-time (AOT) compiler for Bun is fundamentally a testability problem: the approach and architecture you c

By Sean Weldon

Abstract

This synthesis examines the development of an ahead-of-time (AOT) compiler added to the Bun JavaScript runtime, a multi-million-line, predominantly agent-written contribution produced through Claude Code. The central thesis is that at this scale, architectural choice is governed primarily by verifiability: the viable design is the one whose correctness can be most confidently demonstrated, not the one that is most technically elegant. The methodology combined three-way differential testing across just-in-time (JIT), AOT, and untyped execution paths; extensive fuzzing of generated and real-world code; and reliance on pre-existing, independently authored test suites. Five complete rewrites preceded a shippable result. Measured outcomes include roughly 4x lower memory use and 2x faster startup relative to the JIT baseline. Implications concern test-suite independence, measurement discipline, and workflow patterns for orchestrating many agents on a single large codebase.

1. Introduction

JavaScript engines conventionally rely on just-in-time (JIT) compilation, translating source code to machine code incrementally as execution proceeds, which allows optimization decisions to be deferred until runtime behavior is observed. The cost of this flexibility is recurring: in a typical JavaScript application, roughly half of total CPU time is spent on JIT compilation itself rather than on executing the compiled result. This overhead is paid on every process start, which is structurally significant for an application such as Claude Code, built on Bun, particularly in its iOS deployment where each session begins compilation anew.

Ahead-of-time (AOT) compilation, by contrast, compiles code to machine instructions before execution begins, trading the ability to specialize on observed runtime behavior for the elimination of repeated compilation cost. The project discussed here began from an open-ended prompt to reduce Claude Code's memory footprint and improve its speed by modifying either Bun or JavaScriptCore (WebKit), the engine Bun embeds. The result was an AOT compiler integrated directly into Bun.

The central question this analysis addresses is not whether AOT compilation of JavaScript is achievable, but how a project of this magnitude - ultimately requiring five complete rewrites - can be executed largely by language models while preserving justified confidence in correctness. This synthesis first establishes the decision context that shaped the project's scope (Section 2), then analyzes the verification strategy, rewrite history, and agent-orchestration workflow in detail (Section 3), extracts transferable technical findings (Section 4), and discusses broader implications (Section 5).

2. Background and Related Work

The project's framing was shaped directly by a prior effort: Bun's own runtime had already been rewritten from Zig into Rust. That rewrite was tractable for a structural reason specific to Bun: its test suite is authored in TypeScript, a language independent of the runtime's implementation language. The same unmodified tests could therefore be run against both the Zig and Rust builds, producing a differential oracle that was not itself altered by the rewrite under test.

Applying identical reasoning to Claude Code produced the opposite conclusion. Because Claude Code is written in TypeScript and its own test suite is also TypeScript, a Rust port would require porting the tests as well. Once both implementation and tests change together, the tests can no longer be trusted as an independent check, since a defect could be reproduced identically in both the rewritten code and the rewritten assertions. This risk was judged unacceptable, and the team instead chose to accelerate the JavaScript execution substrate rather than change Claude Code's implementation language - a decision derived directly from test-suite topology rather than from performance considerations alone.

Verification throughout the project drew on several independently authored corpora predating the compiler: Bun's own test suite, WebKit's tests, Test262 (the ECMAScript conformance suite), and Cloudflare Workers' tests. Their evidentiary value lies specifically in provenance - because they predate the AOT compiler, they could not have been shaped, consciously or otherwise, to accommodate its particular defects.

3. Core Analysis

3.1 Types as Predictions, Not Guarantees

A defining architectural decision was to treat TypeScript's type annotations as predictions rather than trusted facts. The compiler does not require type correctness to function; when types can be statically proven monomorphic, a property access compiles directly to a field access, and when they cannot, the compiler falls back to a runtime type check. This design choice is explicitly described as well-suited to current language models, which are reported to be comparatively strong at writing compilers but not reliably precise about maintaining fully sound type systems.

3.2 Differential and Fuzz-Based Verification

Correctness confidence rested on running three variants of a given application - JIT, AOT-compiled, and untyped - and checking that all three produced identical behavior. Agreement across all three paths served as evidence of correctness for that specific application; disagreement flagged a defect in one of the paths. This differential check was then scaled through fuzzing: Claude-generated code generators produced large volumes of test programs to exercise the comparison at scale, and V8Zilly, originally a fuzzer for the V8 engine, was extended to additionally fuzz TypeScript types rather than only JavaScript values.

A methodological caution surfaced repeatedly: it is reported to be "really easy to convince yourself that your measurements are good when they're not good," underscoring the need to actively verify that a test or fuzzer is catching real bugs rather than merely appearing to provide coverage.

3.3 Five Rewrites: Architecture Driven by Testability and Quality

The project went through five complete rewrites before a shippable version emerged, each failing for a distinct, diagnosable reason:

A further rewrite remains conceivable, but the fifth version was the one taken to release. This trajectory supports the stated principle that "it's easier for large projects that haven't shipped yet to rewrite than it is to refactor."

3.4 Orchestration Workflow at Scale

Managing a codebase of this volume - the largest the author reports having worked on, composed substantially of tests and the residue of five rewrites - required a deliberate two-phase rhythm. A batch-writing phase, in which large volumes of code are produced while deliberately avoiding builds (to prevent time loss to compile errors), was followed by a longer stabilization phase focused on achieving compilation, passing tests, and confirming true correctness. The two phases favored different infrastructure: a single running build during batch writing, and many long-lived agents during stabilization. Orchestration itself shifted over time, from Claude Code-driven workflows toward long-lived sub-agents that retain relevant code context directly, reducing redundant re-establishment of context. An hourly automated Slack scorecard tracked prioritized metrics against prior values to surface regressions. A recurring failure mode was agents settling for marginal gains (e.g., 0.1% improvements) absent explicit pressure toward more ambitious targets (e.g., 10%), alongside a tendency for agents to invent justifying rules for self-imposed limitations.

4. Technical Insights

5. Discussion

The project's recurring decision rule - rewrite rather than refactor a large, pre-shipment agentic codebase - generalizes beyond this specific compiler. It suggests that for projects still in the development phase, the cost of discarding accumulated code is frequently lower than the cost of untangling agent-written structures whose rationale is not fully legible to the humans supervising them, particularly once defect patterns (such as the archive property heuristic) are systemic rather than local.

A second implication concerns test-suite provenance as a design constraint rather than an afterthought. The decision not to rewrite Claude Code in Rust, and to instead accelerate JavaScript itself, was driven entirely by whether an independent test oracle existed. This suggests that, for agentic development broadly, the language or framework of a test suite relative to the implementation under change may be as consequential a planning input as performance targets or team expertise.

Open questions remain around measurement reliability: the explicit caution that it is easy to mistake superficial fuzzing or testing activity for genuine bug-catching coverage is not resolved within this account, and would benefit from more systematic methods for validating that a verification pipeline is actually discriminating between correct and incorrect implementations, rather than merely producing passing runs.

6. Conclusion

This analysis demonstrates that shipping a multi-million-line, largely agent-written AOT compiler was fundamentally governed by testability rather than by compiler-design elegance alone: the project succeeded only once an architecture emerged for which differential testing, fuzzing, and trustworthy pre-existing suites could jointly establish correctness, and once code quality and compile time both fell within acceptable bounds. The practical takeaways are that test-suite independence should inform language and architecture decisions before implementation begins, that large pre-shipment agentic codebases often warrant rewriting over refactoring, and that sustained human pressure toward ambitious performance targets remains necessary to counteract agents' tendency toward marginal, easily-justified improvements.


Sources


About the Author

Sean Weldon is an AI engineer and systems architect specializing in autonomous systems, agentic workflows, and applied machine learning. He builds production AI systems that automate complex business operations.

LinkedIn | Website | GitHub

At 22Atlas, the studio I run, we set Claude up for teams like this one: here is the Claude work we do.

Sean Weldon builds apps and custom software at 22Atlas.

Start your build

More about Sean