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

Loading slides…

Read the talk

How to Ship Millions of Lines of Agent-Written Code

Bun moved JavaScript compilation out of Claude Code sessions and into the build. Existing tests gave Jarred Sumner a way to check five compiler rewrites against the same expectations. An overbroad API-detection rule and a 50-second build each gave him a reason to hold back a version.

From a talk by Jarred Sumner

At a glance

Ideas worth remembering

  • The test suite shaped what the team chose to rewrite. Bun could use the same TypeScript tests for its Zig and Rust implementations. Keeping Claude Code in JavaScript gave the compiler project the same advantage.

  • Moving work to build time makes build latency a release criterion. The fourth compiler kept the runtime gains and took about 50 seconds to compile Claude Code. The fifth brought the build under 20 seconds.

  • Remeasure while changes are still in flight. Bun’s hourly Slack scorecard put current and previous values side by side so regressions could come to light during development.

The cost of compiling in every session

The just-in-time timeline alternates compilation and execution, while the ahead-of-time timeline shows a single compile step before execution.Open full source frame
The JIT timeline alternates bursts of compilation with stretches of execution. The AOT timeline moves compilation into one step before the program starts.

Each new Claude Code session paid to compile JavaScript as it ran. Jarred Sumner, Bun’s creator, started with a brief to cut memory use and improve speed. The team could change Bun, the runtime behind Claude Code, or WebKit, whose JavaScriptCore engine Bun uses. By the time of the talk, Sumner had merged a several-million-line pull request adding an ahead-of-time compiler to Bun. 0:23

The compiler went through five rewrites in a little over a month. One version came close to shipping before the time it took to compile an application forced another pass. The freedom to start over depended on having a way to tell whether the next compiler still ran the same programs correctly.

A just-in-time compiler, or JIT, compiles code on demand as the application runs. An ahead-of-time compiler, or AOT compiler, does that work at build time. Sumner estimated that compiling on demand accounts for roughly half the CPU time of a typical JavaScript application. For Claude Code sessions launched through the iOS app, the cost mattered because every new session had to pay it again.

Why Claude Code stayed in JavaScript

A TypeScript test imports wrapText directly and checks that a sample wraps onto two lines. The slide explains that these tests cannot run on a Rust version and warns that rewriting the suite is risky.Open full source frame
Claude Code’s tests import TypeScript functions like wrapText directly. A Rust port would mean rewriting the test suite, which Sumner worried would make it harder to tell whether the port preserved behavior.

The Bun team had already rewritten Bun in Rust, so a Rust port of Claude Code was a serious option. Bun’s TypeScript tests were independent of the language used to implement the runtime. The same suite could run against the Zig and Rust versions and hold both to the same expectations. 4:00

The team expected a Claude Code port to require rewriting its TypeScript tests. A passing test could then conceal a regression if the port also changed what the test exercised or expected. Keeping Claude Code in JavaScript let the team change how the application ran while preserving the suite that defined its expected behavior.

The AOT build of Claude Code used about a quarter as much memory and started about twice as fast, Sumner reported. He gave those headline figures without specifying the workload or measurement setup. The team was using the build internally and expected a wider release soon. 5:14

The TypeScript compiler offered a second comparison. Its JavaScript and TypeScript implementation, built with bun compile, ran faster than the Go port in the single-threaded comparison Sumner presented. Thread support for Bun’s AOT build was still in progress.

Bun treats TypeScript types as predictions. An annotation can suggest which case to optimize, but a runtime value can differ from the annotation. The compiler needs stronger evidence before it can specialize an operation.

Keep the existing tests and compare three executions

The table reports 62,858 matches with the JIT. In matching, refused, and different order, the counts are 49,473, 1,685, and 0 for test262, 8,624, 508, and 8 for WebKit, 2,894, 81, and 0 for Node.js, and 1,867, 15, and 3 for Bun.Open full source frame
Bun checked its ahead-of-time compiler on Linux using existing tests that pass in the JIT. The compiler matched the JIT on 62,858 tests and differed on 11. Most of the 2,289 refusals came from tests that modify built-in objects.

Bun’s existing tests, WebKit’s tests, Test262, and Claude Code’s suite all gave the compiler behavior to match. The team also made Bun’s own test runner work in AOT mode. New tests could exercise compiler-specific cases, while the suites that predated the project supplied expectations independent of the new implementation.

Some tests failed because of two deliberate compatibility changes. Their main purpose was to prevent prototype pollution, and Sumner said they helped performance as well. The failures made those changes in behavior visible in the same suites used to look for regressions.

How can the team tell whether compiling ahead of time or using type information changed what an application does? It runs the same application three ways and compares the behavior.

  • JIT. Use the existing execution path as the reference.
  • AOT. Run the compiled program with its type information available to the compiler.
  • Types removed. Strip the type information and run the program again to see whether the behavior changes. 8:22

Agreement gives confidence in the behavior those runs exercise. To widen coverage, Claude could write generators for different code patterns. Each generated program becomes another input to the three-way comparison. When the runs disagree, the team has a specific program to investigate.

How do three runs become one comparison?

One applicationStart all three runs from the same program.
JIT executionIndependent runs — Observe behavior on the existing execution path.
AOT executionIndependent runs — Run the compiled program with type information available to the compiler.
Execution with types removedIndependent runs — Observe program behavior after stripping the type information.
Compare behaviorAgreement covers the cases exercised by the runs.
The program branches into three independent executions. The observed behavior from each run converges at the comparison.
Read the diagram as text
  • One application. Start all three runs from the same program.
  • JIT execution. Independent runs — Observe behavior on the existing execution path.
  • AOT execution. Independent runs — Run the compiled program with type information available to the compiler.
  • Execution with types removed. Independent runs — Observe program behavior after stripping the type information.
  • Compare behavior. Agreement covers the cases exercised by the runs.
  • One application → JIT execution: Run with the JIT.
  • One application → AOT execution: Compile ahead of time and run.
  • One application → Execution with types removed: Strip the types and run.
  • JIT execution → Compare behavior: Observed behavior.
  • AOT execution → Compare behavior: Observed behavior.
  • Execution with types removed → Compare behavior: Observed behavior.

Write in batches, then make the build work

Tests accounted for most of the project’s code volume. During a big implementation pass, agents wrote changes in parallel and the team ran one build against the combined work. Repeated builds during that pass would have meant waiting on the compiler and chasing errors while other pieces were still being written. Once the batch was in place, individual agents could work through build errors and test failures.

The first compiler reused as much of JavaScriptCore’s code as possible. That gave it a starting point and tied its performance ceiling to what the team could get from the existing code. The early Claude Code result fell short of what Sumner wanted.

The team added a TypeScript type checker to Bun as bun check and asked Claude to use it. After that, Sumner reported that Claude Code started about twice as fast and used about a third as much memory. He still called the code “slop.”

What made the archive rule too broad? An ordinary read such as record.archive would flag possible use of Bun’s archive API even if record had nothing to do with Bun. The rule took the property name as its signal and ignored which object the code was reading from. That false positive was enough for Sumner to rule out shipping the version. 11:27

Agent-written planning could swamp reviewers too. Sumner’s example was 1,500 Markdown files. For the third compiler version, the coding batch had a concrete endpoint. He had 140 agents write code at the same time, then turned to getting Claude Code to run. 12:34

A 50-second build forces a fifth rewrite

The fourth compiler had better code and roughly the same runtime performance as before. It took about 50 seconds to compile Claude Code, up from 10 to 20 seconds in earlier versions. Claude Code was a large codebase, but even the single-digit waits Sumner expected for smaller projects would add friction for JavaScript developers accustomed to running their code straight away. 12:51

Sumner also questioned why the version was 900,000 lines. The team rewrote it again. He judged the fifth version’s code ready to ship, and the build came in under 20 seconds. Moving compilation out of the session had created a separate performance target. Claude Code could start quickly and still leave developers waiting too long for a build.

Much of the work began by asking Claude to try an idea and see what happened. Claude was quick to estimate whether a change was worth pursuing. Sumner wanted to revisit some of those calls. An estimate could talk the team out of trying a promising change, and a misleading measurement could persuade it to keep a slow one.

Long-lived subagents and hourly scorecards

For the Rust rewrite, Sumner had leaned on Claude Code workflows. For the compiler, he shifted to long-lived subagents after the initial coding batch. An agent could keep the relevant code in its context window across successive fixes and spend less effort rediscovering how its part of the compiler worked.

A property read shows when the compiler can act on type information. If it can prove the access is monomorphic, meaning the relevant type stays consistent at that site, it can emit a direct field access. Otherwise, it has to check each time the operation runs. The compiler also uses some inline caching to reuse lookup information at an access site.

What did the team track while agents worked in parallel? An hourly scorecard reported the metrics the team had chosen to prioritize. The regular Slack post usually put the previous and current values side by side, so a measurement moving in the wrong direction could catch someone’s eye while work was still underway. 16:48

Bun already used Fuzzili, a JavaScript engine fuzzer also used by V8. The compiler project extended it to exercise TypeScript types, so generated programs could cover cases where type information might change a compiler decision. The test machinery needed a check of its own. A clean run carries weight once the team knows its tests can catch the kinds of failures they’re meant to find.

When runtime-generated code gives back the speedup

Where did AOT lose its edge over the JIT? AOT led on most of the application benchmarks Sumner showed, with UglifyJS as an exception. Code created through eval or new Function only becomes available at runtime. When enough of the workload takes that path, the interpreter does more of the work and the AOT speedup can disappear. 18:07

One deliberate compatibility change concerned Object.prototype. The AOT compiler bans assigning properties to it. Many ordinary objects inherit from that shared prototype, so changing it can affect property lookups across the application. The restriction addresses a common route for prototype pollution and changes behavior for applications that deliberately modify the shared prototype.

What the human does all day

One of Sumner’s most frequent messages was “continue.” The more consequential prompts asked why an agent had taken an approach, what was making it slow, or whether it could try a faster method. Claude could turn its own assumptions into rules or underestimate what it could take on. A question as simple as “what’s taking so long?” could reopen a choice the agent had already settled. 19:18

How often did the AOT build beat both JITs? In the closing JavaScript engine benchmark comparison, Bun’s AOT build beat the JavaScriptCore JIT and Node.js’s V8 JIT on most of the cases Sumner showed. The result applied to the individual benchmark cases, where the rankings could vary by workload. 20:23

The compiler also ran on the tool doing the work. The team used Claude Code to build Bun’s compiler, compiled Claude Code with bun compile, and used that compiled version during development.

Working in the compiled build gave the team daily use of the result. Sumner still stressed rerunning tests and measurements throughout development. With many changes in flight, a regression can slip by between big milestones if the team stops measuring. On a large project that had yet to ship, he found it easier to rewrite around a better approach than to refactor the current version into shape. He used 0.1% and 10% to describe different scales of ambition. When an agent settled for a string of tiny gains, he pushed it to try for a larger one.

At the time of the talk, readers who already had Bun installed could try the compiler by running bun upgrade --canary and then using bun compile. 22:02

Transcript download
Full transcript

Loading transcript…