Skip to content
CLI tool · Dev & Git

Bun for AI agents

Bun for coding agents: install dependencies from the lockfile, run tests and scripts, and add packages, with rules for lockfiles and lifecycle scripts.

bunby Oven
What it is

What Bun does for an agent

Bun is an all-in-one JavaScript runtime and toolkit from Oven: a runtime, a package manager, a test runner, and a bundler in one binary. bunx runs package binaries, like npx.

In a project that uses bun.lock, an agent should use bun for every install and script so it does not create a second lockfile from another package manager.

Official site: bun.sh

Install

Install Bun

The install commands from the official docs. Check it worked with bun --version.

Install script (macOS, Linux)
curl -fsSL https://bun.sh/install | bash
npm (global)
npm install -g bun
Auth

Signing in Bun for an agent

No account is needed. Private registries are configured in bunfig.toml or .npmrc.

Common agent tasks

What agents use Bun for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Install exactly what the lockfile says

    bun
    bun install --frozen-lockfile
  2. Run the test suite

    bun
    bun test
  3. Run a package.json script

    bun
    bun run build
  4. Type-check with the project's TypeScript

    bun
    bunx tsc --noEmit
  5. Add a dependency

    bun
    bun add zod

    Changes package.json and bun.lock. Mention it in the summary.

Safety

Safety rules for agents

Safe to run without asking

  • bun --version
  • bun test
  • bun run <script> (for build, lint, and test scripts)
  • bun install --frozen-lockfile

Ask a human first

  • bun add / remove (changes dependencies)
  • bun update
  • bun publish
  • bun pm trust
  • Use the project's package manager only; do not mix bun with npm, pnpm, or yarn in one repository.
  • Bun skips dependency lifecycle scripts unless a package is listed in trustedDependencies; do not add packages there without approval.
  • Explain every new dependency and why an existing one does not cover it.
Agent instructions

AGENTS.md or CLAUDE.md snippet

Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.

AGENTS.md
## Bun (bun)

Use `bun` for installing JavaScript dependencies, running scripts, and running tests in Bun projects.

- Check it is installed with `bun --version`. If it is missing, ask before installing it.
- Auth: none needed.
- Run without asking (read-only): `bun --version`, `bun test`, `bun run <script> (for build, lint, and test scripts)`, `bun install --frozen-lockfile`.
- Ask a human first (changes or deletes things): `bun add / remove (changes dependencies)`, `bun update`, `bun publish`, `bun pm trust`.
- Use the project's package manager only; do not mix bun with npm, pnpm, or yarn in one repository.
- Bun skips dependency lifecycle scripts unless a package is listed in trustedDependencies; do not add packages there without approval.
- Explain every new dependency and why an existing one does not cover it.
- Prefer JSON output where the command supports it, and keep output short.
CLI or MCP server?

Bun or an MCP server?

No official MCP server. Bun is a local tool, so agents run it directly; there is no need for an MCP server. Many JavaScript MCP servers can be launched with bunx instead of npx.

Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.

Same category
All Dev & Git tools
FAQ

Bun questions

How do I install Bun?

Install script (macOS, Linux): curl -fsSL https://bun.sh/install | bash. Other official options: npm (global). Check the install with bun --version, and see the Oven docs for other platforms.

How does an AI agent authenticate Bun?

No account is needed. Private registries are configured in bunfig.toml or .npmrc. There is nothing to set up: an agent can use it as soon as bun --version succeeds.

Which Bun commands are safe for an agent to run?

Commands that only read state are safe to run without asking: bun --version; bun test; bun run <script> (for build, lint, and test scripts); bun install --frozen-lockfile. Ask a human before anything that changes or deletes something: bun add / remove (changes dependencies); bun update; bun publish; bun pm trust.

Is there an MCP server for Bun?

Bun is a local tool, so agents run it directly; there is no need for an MCP server. Many JavaScript MCP servers can be launched with bunx instead of npx.