| name | bun-cli |
| description | Bun CLI reference for package management, script running, testing, bundling, and compilation. Covers bun install/add/remove, bun run, bun test, bun build, bunx, bun patch, bunfig.toml, bun.lock, workspace catalogs, zero-config frontend dev, parallel/sequential execution, compile-to-browser, and replacing npm/npx/yarn/pnpm with bun equivalents. Use for package management, lockfile issues, test runner config, bundler setup, or frontend dev server Not for Bun runtime APIs (Bun.file(), Bun.$(), Bun.sql()) -- use bun-api skill |
Bun CLI
Bun is an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Bun runs TypeScript natively — bun file.ts directly, no compile step, no tsc, no ts-node. Always use bun instead of node, npm, npx, yarn, or pnpm in Bun projects.
Verified against Bun v1.3.14 (2026-05-28).
Detecting Bun Projects
A project uses Bun if any of these are present:
bun.lock or bun.lockb in the project root
bunfig.toml in the project root
bun field in package.json (e.g., "bun": { "install": { ... } })
- Package manager field:
"packageManager": "bun@..."
[run] bun = true in bunfig.toml (forces Bun runtime for all scripts)
Critical Rule
In a Bun project, ALWAYS use bun for everything. Never fall back to node, npm, npx, yarn, or pnpm. This avoids compatibility issues, unnecessary retries, and cryptic errors from Node.js/npm not understanding Bun-specific features (workspace protocol, lockfile format, trustedDependencies, etc.).
- Run files:
bun file.ts (not node file.ts)
- Run scripts:
bun run dev (not npm run dev)
- Execute binaries:
bunx tool (not npx tool)
- Install packages:
bun add pkg (not npm install pkg)
- Run tests:
bun test (not npx jest or node --test)
Read-Only Commands (safe, no side effects)
| Command | Purpose |
|---|
bun --version | Runtime version |
bun info <pkg> | Package metadata, available versions |
bun info <pkg> versions | List all published versions |
bun pm ls | List installed packages |
bun pm ls --all | List all (including transitive) |
bun pm hash | Print lockfile hash |
bun pm cache | Show cache directory |
bun outdated | Check for outdated dependencies |
bun audit | Security vulnerability audit |
bun test | Run test suite |
bun run lint | Run linter (project-specific) |
bun run check-types | Type checking (project-specific) |
Reference: See references/allowlist.md for copy-paste Bash(command:*) patterns for Claude Code / OpenCode settings.
npm/npx/node to Bun Translation
| npm/npx/node | Bun equivalent |
|---|
npm install | bun install |
npm install pkg | bun add pkg |
npm install -D pkg | bun add -d pkg |
npm install -g pkg | bun add -g pkg |
npm uninstall pkg | bun remove pkg |
npm update | bun update |
npm run script | bun run script |
npx command | bunx command |
node file.js | bun file.js |
node --watch file.js | bun --watch file.js |
npm test | bun test |
npm pack | bun pm pack |
npm publish | bun publish |
npm info pkg | bun info pkg |
npm outdated | bun outdated |
npm audit | bun audit |
npm link | bun link |
Key Behavioral Differences
- No
npm run prefix needed: bun run dev works, but so does bun dev (direct script execution)
--bun flag: Forces Bun runtime instead of Node.js for scripts that use node in their shebang. In bunfig.toml, set [run] bun = true to make this the default
- Lockfile: Bun uses
bun.lock (text-based, v1.2+) or bun.lockb (binary, legacy). Text lockfile is default for new projects
- Workspace commands: Use
--filter flag: bun --filter 'pkg-name' add dep
- Lifecycle scripts: Bun ignores lifecycle scripts by default for security. Use
trustedDependencies in package.json to allowlist packages that need postinstall etc.
Package Management
Installing Dependencies
bun install
bun install --frozen-lockfile
bun install --no-save
bun install --production
bun install --dry-run
Adding/Removing Packages
bun add pkg
bun add pkg@version
bun add -d pkg
bun add -D pkg
bun add --optional pkg
bun add -g pkg
bun add --exact pkg
bun remove pkg
Updating and Inspecting
bun update
bun update pkg
bun outdated
bun info pkg
bun info pkg versions
bun pm ls
bun pm ls --all
bun pm hash
bun pm cache
bun pm cache rm
Linking and Patching
bun link
bun link pkg-name
bun pm pack
bun patch pkg
bun patch --commit pkg-dir
Publishing
bun publish
bun publish --dry-run
bun publish --tag beta
bun publish --access public
Reference: See references/package-management.md for complete flag details.
Running Scripts and Files
Direct Execution
bun file.ts
bun run script-name
bun script-name
bun --watch file.ts
bun --hot file.ts
bun --env-file .env file.ts
bun --env-file .env.local --env-file .env file.ts
bunx (npx Replacement)
bunx command
bunx --bun command
bunx command@version
Parallel and Sequential Execution
bun --parallel run build lint typecheck
bun --sequential run clean build deploy
Workspace-Aware Execution
bun --filter 'pkg-name' run script
bun --filter '*' run script
bun --filter './apps/*' run build
Script Flags
bun run --smol file.ts
bun run --silent script
bun run --shell=bun script
bun run --shell=system script
Zero-Config Frontend Development
Run HTML files directly as a dev server -- no Vite, Webpack, or any config needed:
bun ./index.html
bun --hot ./index.html
Bun automatically transpiles TypeScript, JSX, TSX, and CSS linked from the HTML. Resolves node_modules imports in <script> tags. Enables HMR and React Fast Refresh.
Reference: See references/running-and-execution.md for complete details.
Testing
Bun includes a built-in test runner compatible with Jest-like syntax.
Running Tests
bun test
bun test file.test.ts
bun test --filter "pattern"
bun test --timeout 10000
bun test --bail
bun test --bail 5
bun test --rerun-each 3
bun test --only
bun test --todo
Coverage
bun test --coverage
bun test --coverage-reporter text
bun test --coverage-dir ./cov
Test File Patterns
By default, Bun finds files matching: *.test.{ts,tsx,js,jsx}, *_test.{ts,tsx,js,jsx}, *.spec.{ts,tsx,js,jsx}, *_spec.{ts,tsx,js,jsx}, and files in __tests__/ directories.
Snapshot Testing
bun test --update-snapshots
Watch Mode
bun test --watch
Reference: See references/testing.md for test API, mocking, lifecycle hooks, and coverage config.
Bundling and Compilation
Bundling
bun build ./src/index.ts --outdir ./dist
bun build ./src/index.ts --outfile ./dist/out.js
bun build ./src/index.ts --target browser
bun build ./src/index.ts --format esm
bun build ./src/index.ts --minify
bun build ./src/index.ts --sourcemap external
bun build ./src/index.ts --splitting
Standalone Executables
bun build ./src/cli.ts --compile
bun build ./src/cli.ts --compile --target bun-linux-x64
bun build ./src/cli.ts --compile --minify
Available compilation targets: bun-linux-x64, bun-linux-arm64, bun-darwin-x64, bun-darwin-arm64, bun-windows-x64.
Browser target (v1.3.10+) -- compile to a self-contained HTML file:
bun build --compile --target=browser ./app.tsx --outfile ./dist/app.html
Build Options
bun build ... --external pkg
bun build ... --define 'KEY=VALUE'
bun build ... --loader .ext=type
bun build ... --entry-naming [dir]/[name].[ext]
bun build ... --public-path /cdn/
Reference: See references/bundling-and-compilation.md for complete options.
Project Initialization
bun init
bun create template-name
bun create next-app my-app
Configuration (bunfig.toml)
Key sections:
[run]
bun = true
[install]
exact = true
peer = false
production = false
frozenLockfile = false
globalDir = "~/.bun/install/global"
[install.scopes]
"@myorg" = { token = "$NPM_TOKEN", url = "https://npm.pkg.github.com/" }
[test]
coverage = false
coverageReporter = ["text", "lcov"]
timeout = 5000
[bundle]
entryPoints = ["./src/index.ts"]
outdir = "./dist"
Reference: See references/configuration.md for complete bunfig.toml reference.
Debugging and Profiling
bun --inspect file.ts
bun --inspect-wait file.ts
bun --inspect-brk file.ts
bun --cpu-prof file.ts
bun --cpu-prof-md file.ts
bun --heap-prof file.ts
bun --heap-prof-md file.ts
BUN_JSC_logJITCodeForPerf=1 bun file.ts
Environment Variables
bun --env-file .env file.ts
bun --env-file .env.local --env-file .env file.ts
Bun auto-loads .env, .env.production, .env.local, .env.production.local by default based on NODE_ENV.
Built-in Features That Replace External Tools
Bun has many capabilities built in that eliminate the need for external packages or tooling:
Native TypeScript
Bun runs .ts, .tsx files directly — no tsc, ts-node, or tsx needed. The transpiler is built into the runtime. Use bun file.ts to run any TypeScript file immediately.
Workspace Catalogs
Bun supports catalog: protocol in package.json for centralized dependency version management across monorepo workspaces — no need for tools like syncpack or manypkg:
{
"workspaces": ["packages/*"],
"catalog": {
"react": "^19.0.0",
"typescript": "^5.7.0"
}
}
{
"dependencies": {
"react": "catalog:"
}
}
Built-in Test Runner
bun test is a full Jest-compatible test runner with snapshot testing, mocking, coverage — no need for jest, vitest, or mocha.
Built-in Bundler
bun build replaces esbuild, webpack, rollup for many use cases. Supports code splitting, tree shaking, minification, and standalone executable compilation.
Built-in SQLite
import { Database } from 'bun:sqlite' — zero-dependency SQLite3 with prepared statements and transactions. No need for better-sqlite3 or sql.js.
Built-in Shell
Bun.$ tagged template — cross-platform shell execution with automatic escaping. Replaces execa, shelljs, zx.
Built-in File I/O
Bun.file() and Bun.write() — fast file operations without importing fs. Auto-detects MIME types.
Built-in Glob
new Bun.Glob(pattern) — fast glob matching and file scanning. Replaces glob, fast-glob, minimatch.
Built-in Password Hashing
Bun.password.hash() and .verify() with bcrypt and argon2id. Replaces bcrypt, argon2 packages.
Built-in Compression
Bun.gzipSync(), Bun.deflateSync(), Bun.zstdCompressSync() — no need for zlib wrapper packages.
Built-in Semver
Bun.semver.satisfies(), .order() — replaces semver package.
Built-in Runtime APIs
For Bun's built-in runtime helpers (Bun.s3, Bun.redis, Bun.Archive, JSONC, JSON5, JSONL, markdown, cron), see the bun-api skill.
Zero-Config Frontend Dev Server
bun ./index.html — serve HTML with auto-bundling of JS/TS/CSS, HMR, and React Fast Refresh. Replaces Vite/Webpack dev server for simple projects.
ES Decorators
TC39 standard ES decorators supported natively (v1.3.10+) — no experimentalDecorators tsconfig needed.
Key Gotchas
- Always use
bun not npm/node/npx in Bun projects
- Lockfile format:
bun.lock (text, v1.2+) is the default for new projects. Legacy bun.lockb is binary. Don't mix with package-lock.json
- trustedDependencies: Lifecycle scripts (postinstall, etc.) only run for packages listed in
trustedDependencies in package.json
--bun flag: Some tools (e.g., Next.js) use Node.js by default even when run with bun run. Use --bun or [run] bun = true in bunfig.toml to force Bun runtime
- Workspace protocol: Use
"workspace:*" in package.json to reference workspace packages
- Global binaries: Installed with
bun add -g, located in ~/.bun/bin/
- Node.js compatibility: Bun implements most Node.js APIs but some edge cases differ. Check https://bun.sh/docs/runtime/nodejs-apis for compatibility
- TypeScript: Bun runs TypeScript natively with no compilation step. Uses its own transpiler (not tsc)
- Auto-install: Bun can auto-install missing packages on import (disabled by default, enable with
[install] auto = true in bunfig.toml)
bun run vs bun: bun run script runs a package.json script; bun file.ts runs a file directly. bun script tries script first, then falls back to file