← Back
AI Engineer November 24, 2026 22m

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

Read full transcript 20 segments
  1. [music] >> Hello everyone. My name is Jared. Uh I'm the creator of Bun uh and I work at Anthropic. Um uh Bun is the JavaScript runtime that powers Cloud code. And recently I merged a several million line of code PR um to add an ahead of time compiler uh to to Bun which is uh basically the idea is uh instead of paying the cost of a JIT at runtime, you can uh uh you can compile all the code ahead of time. Um and it's it's like a really big project. Um over the summer I uh rewrote Bun in Rust. Um uh and this is a project on a larger scale.

  2. This ahead of time compiler is like a larger project than that. Um and I think one of the challenges right now with large projects is like how do you actually confidently ship a like millions of lines of code written by agents. Um so that's what I'm going to talk about. This was like the opening prompt after some discussion with it was like basically uh we need to make Cloud code use a lot less memory and uh and faster and we can modify either WebKit or Bun. Um Bun uses JavaScript Core which is WebKit um under the hood. Uh and it's been a little bit over a month. Um uh uh this is this compiler has gone through five rewrites. Um you can see the like the first couple ones like pretty short. And then I like almost shipped the blue one.

  3. Uh and then I was like, this is building way too long. Like it's taking way too long to compile the code. So we wrote it again. Uh and this next one is shipping next week. Uh this is kind of the the way I think about a project like this is like you're really constrained by how you test that the code works. Um so that's like even more important than what you're specifically like like the approach you go with for how to build it is entirely driven by how do you verify that it actually is going to like work and not be buggy and that you can trust it. Um and so just a little more background on like why this particular project, why the ahead of time compiler? And it's because uh for a typical JavaScript based application roughly half of like the the CPU time is just spent compiling code on demand. Um and so a lot of the general like thing you've seen in a lot of applications where people are rewriting their code bases in in a language like Rust or sometimes Go um it's like when coming from JavaScript, it's because uh like there it's really the the combination of the JIT and that it's a single threaded application.

  4. Um so that's sort of the difference between a JIT and AOT is that uh you compile before, whereas with a JIT you compile as you go along. This is particularly important for something like Cloud Code where when using like the Cloud Code like iOS app where the CPU time is a lot uh if you're if you have to have every session of Cloud Code also compiling. Um so we talked a lot about like like should we rewrite Cloud Code in Rust? Um, because the Bun team us re- rewrote Bun in Rust, so like we're pretty good at rewrites. Um, uh, and we decided not to. Um, and the the reason why is because like for in Bun's case it's actually like pretty easy to do. Like Bun is an easy project to do a Rust rewrite because the tests were written in a language that's independent of the one it runs in. So because all the tests were written in TypeScript, um, we could run the tests on both the Zig version and the Rust version.

  5. Whereas for Cloud Code, uh, we like Cloud Code's tests are written in TypeScript. So we would have to port Cloud Code's test suite. And as soon as you're like rewriting the tests, then you can't really trust the tests anymore. Um, so that seemed like it'd be too risky. So instead, what if we just make JavaScript faster so we don't have to rewrite it in Rust? Um, this was another prompt a little bit later. Um, uh, and the result is that it actually did uh have JavaScript's memory like the memory usage uh it uses about 4x less memory. Um, uh, it starts about two times faster. Um, uh, and we we're dogfooding this internally and it'll be external soon.

  6. Um, some more benchmarks uh and then I'll also go into more detail about how we actually did this. Um, so like it's it's possible that if an interesting thing is like uh like TypeScript 7 re rewrote their code by by hand um from uh JavaScript / TypeScript to to Go and uh the single-threaded version uh with it you when compiled via Bun compile is now faster than the single-threaded TypeScript Go port. Um and we will add threads also to the ahead-of-time compiled version of Bun, but we haven't done that yet. So there is a PR. Um and so a little bit about like the actual ahead-of-time compiler um uh TypeScript is not type TypeScript types are don't necessarily need to be correct. So it treats types as predictions uh instead of like trusting them.

  7. Um and this kind of problem works really well for models because uh they're just really good at writing compilers. Um so so uh uh this is sort of like more about like how you how uh like should we like how we were thinking about this decision. Um and a b a big thing here is like there's so many tests you can run when you're when it's like uh in ahead of time like like for something like this because we don't need to write any tests pretty much ourselves. Like we actually do write a lot of tests, but uh we can largely trust that the tests that predate the project work. Um and this was the same thing with the the Bun Rust rewrite where we had Bun's existing test we we could run. And now with the compiler uh we have Bun's existing test suite plus WebKit's tests plus test 262 plus Cloudflare Codes tests.

  8. Um and then we also made it so that way Bun itself the Bun's own test runner could be run in the AOT mode. Uh and like the we have one breaking change with or really it's two breaking changes with the ahead-of-time compiler and that's pretty much why these particular tests are failing. Um but the and the the two breaking changes are actually like, mostly security things, um, to prevent prototype pollution attacks, but they also end up benefiting for performance. Um, so like what makes this particular kind of problem pretty good for agents is like uh, you run it with you can run all three versions of an application, one with a JIT, one with ahead of time compiled, and one also without the types. And as long as the three of them uh, behave the same, then you know that it works at least for that specific application. But then you can take that kind of problem and fuzz it a lot.

  9. Um, uh, and just have Claude like turn out code generators to like fuzz different patterns. Um, and you can catch a lot of bugs that way. Um, uh, this is a very large project. This is the biggest I think I've worked on uh, in terms of like code volume. Um, most of this is tests, um, and also because we rewrote it five times. Um, when you're like doing this kind of project, what how I think about it is like you have like batches of like okay, we need to write a lot of code at once and then after that initial batch, then it's okay, let's have let's like fix everything, make sure it compiles, make sure it passes a bunch of tests, um, and make sure it like really truly works. Um, and the actual logistics of that are like when you're in the big batch kind of project stage, then uh, you don't want to run builds.

  10. You want to run one build because otherwise you're going to spend all your time compiling and like waiting for build errors and it's going to like not be a good use of anyone's time. Uh, and then separately uh, for like longer running like once you have once you've written all the code uh, you want to uh, have it like have lots of individual agents. Um, this is like a little bit of the timeline um, of this project. Uh, the first one was not very good. Uh, like Cloud Code was a gigabyte um, which is terrible. Uh, uh, and like this used as much as possible from JavaScript Core's existing code. Um, so it was like basically the ceiling was what is is like at only as good as like what it could be from that.

  11. Um, uh, so then a little bit after this we added a TypeScript type checker into Bun itself. Um, these were prompts uh, uh, and so we added Bun Check and then we're like hey Claude, please use Bun Check. Um, uh, and then after that startup time got two times faster and uh, in Cloud Code and uh, started using about 3x less memory. But the code was slop. Uh, and like like this is not good. It should never it basically this meant that any object that accessed a property called archive it would then assume that the Bun.archive API was potentially used. Um, and I looked at this and I was like we cannot ship this. This is not good. Um, so then uh, this is like yeah and then this is another thing too is like it just like to like when you're doing like a large planning like when you're trying to like have it do a bunch of design docs and stuff it just loves writing Markdown docs and it doesn't make sense because who's going to like 1,500 markdown files is just not reasonable.

  12. Uh uh So for this it was like this was like I think the third compiler version, maybe it was the fourth. No, this was the third. Um uh it to like just to kind of fast get it all out 140 agents at the same time, write all the code all at the same time, then get Cloud Code to run. Um uh and then uh this is the fourth one um and this one the code was not slow um pretty good um with like basically the same performance as before. However, the compilation time was way too slow cuz people coming from like a JavaScript background don't expect any compilation time. Um uh so 50 seconds for like Cloud Code is like a pretty large codebase, but this meant that like other projects would take like single digit seconds and people don't want to wait that long.

  13. Um so uh we're going to rewrite it again um and and uh cuz in in older versions of this compiler it was taking like 10 to 20 seconds. Uh and then Cloud does this thing where like it'll try to like size up everything to judge whether or not it's worth working on, but it's really easy to convince yourself that like your measurements are good um when they're not good. Uh uh and like part of it was also like why is this 900,000 lines of code this should be a lot like smaller. Um uh so then we did it one more time. And the code was good. And the build time was under 20 seconds. It's possible that we end up with a sixth time sometime later, but the fifth one is like very shippable and I've worked on this for enough time that it's like time to ship it.

  14. A lot of this was like just like hey Claude, try this idea and then see what happens and then it would like size up the idea. And I think this is like still kind of not right. Like I think a lot of this are like things that we should try again and not let it like kind of what I said earlier about like sizing up the the impact of a change is like it's really easy to under or to like size it up incorrectly and then talk yourself out of it. So I think this probably needs to be revisited more. My old approach, particularly with like the the Bun runtime, was very much leaning on like Claude code workflows to do things. And pretty much now with the most recent models, I mostly just rely on sub agents that are like very long lived. Except for that initial part where you're like writing all the code all at once.

  15. And this with the sub agents it works pretty well because they keep all the context of the relevant code in their head or like in the context window. And that's like less wasteful. And like they can just keep going. Here's a little more about like how the different parts of the compiler works. Generally it's like there's if we can confidently prove that the value is like the types are the same, that they're monomorphic, then it can become a field access. Otherwise, it has to check every single time. Uh and it has like some inline caching, but not like a lot. Um uh as for the project of this size, you really do need to it's kind of hard to follow sometimes like what everything what everything's happening. So uh I leaned a lot on like just having an hourly update um and where it would post a scorecard comparing a bunch of metrics that we were prioritizing.

  16. Um usually though when it was posting in Slack, it would show like a previous and this version, so that way it was easy to see if numbers went up or down. Um but it's like not helpful in a slide cuz the previous one is just the JIT. Um the the important thing is like none of these tests for the most part are things that are like made up. Um uh they're things that like pre predated the project so that way we know that like the agent couldn't have messed with it. V8 Zilly is like a JavaScript engine fuzzer that V8 uses. Um so uh and we were already using that in one, but we also extended it to have uh to like test for TypeScript types um as well. Um uh and it's also important to check that the tests actually catch things because it's really easy to fool yourself that it's finding bugs when it 's not finding bugs.

  17. Some more numbers uh on the ahead of time compiler. Um it generally for most projects outperforms the JIT. Um not always. The you can see in the uglify JS And that's basically if it has to use the interpreter a lot. So if there's a lot of like eval or a new function, um then it's not faster. Um but most applications don't do that. Uh and it's like it's like a make it like it's as close as possible as you can get to like a one liner to like make an application run faster. Um this is not 100% true cuz as you can see uglify JS and there are other cases as well. Um but it is often true. So like yeah the the other thing is object prototype. Uh this is like a a rare edge case but basically there's a lot of security vulnerabilities in JavaScript applications called like prototype pollution. And this usually works by assigning properties onto object dot prototype.

  18. Um and the compiler bans that. So like for a large project like this what do you actually do all day? These are like the top messages that I sent saying continue a lot. Um uh also like my laptop kept dying. Um uh and then like but like more concretely what you actually do is like a bunch of leading questions like why are we doing this? Uh can we do this? Also I end up saying like can you do this faster or like what's taking so long? Cuz it kind of like talks itself into making up rules. Um uh and also it tends to not be uh it tends to like underestimate what it can do.

  19. Um so I often end up saying things like this to Claude to to get it to like uh try harder. And the result is that uh JetStream three, which is one of the main benchmarks that JavaScript engines use, um uh the Bun outperforms both JavaScript Core's JIT and Node Node.js in like V8 JIT um in most of them. Uh and the whole time like it's been using Cloud Code to like build the Bun compile, like to build Bun compile itself, and then using the build of Cloud Code that was compiled with Bun compile. Um uh so sort of how I think about this is like like the testability thing is super important when you're working on a large project with Cloud uh and to make sure that the tests actually test things.

  20. Um and if you're not actively re-measuring, then it's going to like get worse cuz it's just if there's so much stuff going on, it's really easy to lose track. Um uh and like it's easier for large projects like this that haven't shipped yet to uh rewrite than it is to refactor. Um and if you don't act ambitiously, then the models will like start having like 0.1% improvements instead of like 10% improvements. So you kind of have to constantly nudge it to like hey, you can do really cool things if you try harder. Uh you can try this now if you want uh by running Bun upgrade dash dash canary if you have Bun installed. Um and then just Bun compile. Thanks everyone.

Summary

Jared, creator of Bun and employee at Anthropic, discusses the integration of a massive ahead-of-time (AOT) compiler into Bun to significantly improve the performance and memory efficiency of Cloud Code. Key subjects include contrasting JIT and AOT compilation, the complexities of shipping millions of lines of agent-written code, leveraging existing robust test suites for verification, and achieving major performance gains—such as using four times less memory and starting twice as fast—without needing to rewrite the application in Rust. The practical takeaway is that instead of undertaking risky rewrites of large codebases or test suites, developers can dramatically optimize JavaScript performance and memory usage by implementing an AOT compiler backed by rigorous, pre-existing test validation.

View original episode ↗