Bun in AI agent setups: what actually changes
Someone opened a thread on Hacker News with a simple question: what's your current AI agent setup?. As usual, hundreds of replies showed up, and each one describes its own ecosystem. I read through them looking for one thing only: the runtime. People using agents to write TypeScript are, more and more, running everything on top of Bun. And that has less to do with hype than it seems.
That's what this post is about. What Bun gains in an agent workflow, where it changes nothing, and how I would put a setup together today.
Why the runtime matters when the agent is the one typing
When you code on your own, the time it takes to run a test barely registers. You save, glance at the terminal, take a sip of coffee. Two extra seconds make no difference.
With an agent it's different. It doesn't drink coffee. It runs the test, reads the error, edits, runs again. On an average task this happens 20, 30, sometimes 50 times. If each cycle burns 4 seconds of overhead just to boot the runtime, transpile and resolve modules, that's minutes of idle time per task. Multiply that by several tasks a day and a few agents running in parallel.
The bottleneck moved. It used to be your typing speed. Now it's the speed of the feedback loop.
A good agent with slow feedback is still a slow agent.
That's where Bun comes in. It was built for fast startup and for doing a lot without configuration. For a human, that's comfort. In an agent's loop, it turns into saved time and saved tokens.
What Bun solves in an AI agent's loop
Let me break down what I see working in practice.
It runs TypeScript directly. No tsc, no ts-node, no loader. The agent writes a .ts script and runs it right away:
bun run scripts/migrate-users.ts
It sounds minor, but it wipes out a whole category of errors. How many times have you seen an agent get lost in ERR_UNKNOWN_FILE_EXTENSION or fighting with "type": "module" in package.json? Every one of those fights costs several rounds and a pile of wasted context.
Fast, built-in testing. bun test has a Jest-compatible API in most cases. The agent already knows describe, it and expect by heart, so it writes tests without reading any docs:
import { describe, it, expect } from "bun:test";
import { calculateShipping } from "./shipping";
describe("calculateShipping", () => {
it("makes shipping free above 200", () => {
expect(calculateShipping({ total: 250, zip: "01310100" })).toBe(0);
});
});
On a small suite, the time difference compared to a Jest setup with transpilation is very noticeable. And the agent runs that suite all the time.
Dependency installs that don't drag. bun install is fast enough that the agent can delete node_modules and reinstall without fear. In ephemeral sandboxes, where every task starts from scratch, this matters even more.
Fewer tools for the agent to understand. Runtime, package manager, test runner, bundler and even a shell (Bun.$) in the same binary. Every tool you drop is one less page of docs the model has to get right. Less surface, less hallucination.
The setups that work in practice
Reading the thread, you notice the setups look different but converge on the same shape: a terminal agent, a repository with clear instructions and an automatic verification loop. The runtime sits in the middle of all that.
Mine today looks roughly like this:
- A terminal agent with access to the repository.
- An instructions file at the root (
CLAUDE.md,AGENTS.mdor similar) saying exactly which commands to use. - Short scripts in
package.jsonthat the agent calls without thinking.
The third part helps the most. I keep the commands explicit:
{
"scripts": {
"check": "bun run typecheck && bun test",
"typecheck": "tsc --noEmit",
"test": "bun test"
}
}
And in the instructions file, a single line: "before saying you're done, run bun run check". That alone changed quality more than any model switch I made this year.
Notice one detail: tsc --noEmit is still there. Bun runs TypeScript, but it doesn't check types. It just strips the annotations and runs. If you don't put the typecheck in the loop, the agent will ship code that runs and has hidden type errors. I've seen it happen more than once, and the agent replies with full confidence that "the tests passed".
Where Bun still isn't the answer
Now the honest part. I use Bun for almost everything new, but there are places where I don't switch.
Node compatibility isn't 100%. It got much better, and most libraries work. But old native modules, some obscure node: API, or tools that depend on Node internals can still break. The problem isn't just the breakage. It's that the agent doesn't know the runtime is to blame. It will try to fix your code for half an hour before suspecting the environment.
Large legacy projects. If you have a monorepo with Jest configured, complex mocks and transform plugins, migrating just because the agent would be faster rarely pays off. Do it package by package, starting with the new ones.
Production with specific requirements. If your provider, your APM or your infra team only support Node, developing on Bun and running on Node is asking for subtle behavior differences. It's doable, but then your tests need to run on both.
React Native. Metro and the Expo ecosystem live in the Node world. I use bun install for dependencies and stop there. Not worth the headache.
My rule of thumb: new project, script, internal CLI, API in pure Bun or with Hono, a tool the agent will run a thousand times? Bun. A project that already exists and works? Leave it alone until there's a concrete reason.
How to build your setup in an afternoon
If you want to try it without rewriting anything, do this:
- Pick a small project or an isolated package from the monorepo.
- Switch the package manager:
bun installgeneratesbun.lock. - Run the current suite with
bun testand see what breaks. Most of the time it's just adjusting mock imports. - Create the
checkscript with typecheck and tests, as shown above. - Write in the agent's instructions file which commands it should use. Be specific: "use
bun, nevernpmornpx".
Item 5 sounds silly, but it isn't. Without that line, the agent sometimes mixes npm install with bun.lock and you end up with two lockfiles fighting in the repo. It's like letting two people organize the same drawer without talking to each other.
After a week, compare. How long the tasks took, how many times the agent got stuck on environment errors and how many times it shipped something that didn't pass the typecheck. Numbers, not feelings.
My take
The HN thread shows that nobody has found the perfect setup. Everyone is patching their own. But one thing seems clear to me: the runtime has become part of the AI tooling, not an infrastructure detail. When the agent runs the same command fifty times per task, every second and every piece of config you remove counts.
Bun doesn't make the model smarter. It clears obstacles out of the way. And often that's exactly what separates an agent that solves the problem from one that walks in circles. Just don't forget the typecheck, because running is not the same as being right.
If you want to see where I'm already using this stack, take a look at my projects.
LinkedIn summary
My agent ran the tests 50 times per task. The bottleneck was never the model.
When the agent is the one typing, every second of runtime overhead gets multiplied across the feedback loop.
That's why I started using Bun on new projects: TypeScript out of the box, a built-in test runner and fast installs. Fewer tools for the agent to understand, fewer chances to hallucinate.
But there's a catch: Bun runs TypeScript without checking types. Without `tsc --noEmit` in the loop, the agent ships code with hidden errors and swears the tests passed.
One line in the instructions file ("run bun run check before saying you're done") improved quality more than any model switch I made this year.
I wrote about where Bun helps and where I'm still not switching. What's your setup these days?
#Bun #TypeScript #AI #AIAgents #DevTools