Loading...
Loading...
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
npx skill4agent add dmythro/agent-skills bun-clibun file.tstscts-nodebunnodenpmnpxyarnpnpmbun.lockbun.lockbbunfig.tomlbunpackage.json"bun": { "install": { ... } }"packageManager": "bun@..."[run] bun = truebunfig.tomlbunnodenpmnpxyarnpnpmbun file.tsnode file.tsbun run devnpm run devbunx toolnpx toolbun add pkgnpm install pkgbun testnpx jestnode --test| Command | Purpose |
|---|---|
| Runtime version |
| Package metadata, available versions |
| List all published versions |
| List installed packages |
| List all (including transitive) |
| Print lockfile hash |
| Show cache directory |
| Check for outdated dependencies |
| Security vulnerability audit |
| Run test suite |
| Run linter (project-specific) |
| Type checking (project-specific) |
Reference: Seefor copy-pastereferences/allowlist.mdpatterns for Claude Code / OpenCode settings.Bash(command:*)
| npm/npx/node | Bun equivalent |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
npm runbun run devbun dev--bunnodebunfig.toml[run] bun = truebun.lockbun.lockb--filterbun --filter 'pkg-name' add deptrustedDependenciesbun install # Install all from package.json
bun install --frozen-lockfile # CI mode: fail if lockfile needs update
bun install --no-save # Install without updating package.json
bun install --production # Skip devDependencies
bun install --dry-run # Show what would be installedbun add pkg # Add to dependencies
bun add pkg@version # Add specific version
bun add -d pkg # Add to devDependencies (--dev)
bun add -D pkg # Same as -d
bun add --optional pkg # Add to optionalDependencies
bun add -g pkg # Install globally
bun add --exact pkg # Pin exact version (no ^)
bun remove pkg # Remove packagebun update # Update all packages
bun update pkg # Update specific package
bun outdated # Show outdated packages
bun info pkg # Show package metadata
bun info pkg versions # List all available 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 pm cache rm # Clear cachebun link # Register current package as linkable
bun link pkg-name # Link a registered package
bun pm pack # Create tarball of package
bun patch pkg # Start patching a package
bun patch --commit pkg-dir # Apply patchbun publish # Publish to npm
bun publish --dry-run # Preview what would be published
bun publish --tag beta # Publish with tag
bun publish --access public # Set access levelReference: Seefor complete flag details.references/package-management.md
bun file.ts # Run TypeScript/JavaScript directly
bun run script-name # Run package.json script
bun script-name # Short form (if no conflict with bun commands)
bun --watch file.ts # Re-run on file changes
bun --hot file.ts # Hot reload (preserves state)
bun --env-file .env file.ts # Load env file
bun --env-file .env.local --env-file .env file.ts # Multiple env filesbunx command # Run package binary (auto-installs if needed)
bunx --bun command # Force Bun runtime for the command
bunx command@version # Run specific versionbun --parallel run build lint typecheck # Run all concurrently
bun --sequential run clean build deploy # Run one after anotherbun --filter 'pkg-name' run script # Run in specific workspace
bun --filter '*' run script # Run in all workspaces
bun --filter './apps/*' run build # Run with glob patternbun run --smol file.ts # Reduce memory usage (sacrifice throughput)
bun run --silent script # Suppress script name echo
bun run --shell=bun script # Use Bun's built-in shell (cross-platform, default on Windows)
bun run --shell=system script # Use system shell (default on macOS/Linux)bun ./index.html # Start dev server, auto-bundles JS/TS/CSS
bun --hot ./index.html # With hot module replacementnode_modules<script>Reference: Seefor complete details.references/running-and-execution.md
bun test # Run all test files
bun test file.test.ts # Run specific file
bun test --filter "pattern" # Filter by test name
bun test --timeout 10000 # Set timeout (ms)
bun test --bail # Stop on first failure
bun test --bail 5 # Stop after 5 failures
bun test --rerun-each 3 # Run each test 3 times
bun test --only # Run only tests marked with .only
bun test --todo # Include .todo testsbun test --coverage # Enable code coverage
bun test --coverage-reporter text # Coverage format: text, lcov, json
bun test --coverage-dir ./cov # Output directory*.test.{ts,tsx,js,jsx}*_test.{ts,tsx,js,jsx}*.spec.{ts,tsx,js,jsx}*_spec.{ts,tsx,js,jsx}__tests__/bun test --update-snapshots # Update snapshot filesbun test --watch # Re-run on file changesReference: Seefor test API, mocking, lifecycle hooks, and coverage config.references/testing.md
bun build ./src/index.ts --outdir ./dist # Bundle to directory
bun build ./src/index.ts --outfile ./dist/out.js # Bundle to single file
bun build ./src/index.ts --target browser # Target: browser (default), bun, node
bun build ./src/index.ts --format esm # Format: esm (default), cjs, iife
bun build ./src/index.ts --minify # Minify output
bun build ./src/index.ts --sourcemap external # Sourcemaps: external, inline, linked, none
bun build ./src/index.ts --splitting # Code splitting (ESM only)bun build ./src/cli.ts --compile # Create self-contained executable
bun build ./src/cli.ts --compile --target bun-linux-x64 # Cross-compile
bun build ./src/cli.ts --compile --minify # Minified executablebun-linux-x64bun-linux-arm64bun-darwin-x64bun-darwin-arm64bun-windows-x64bun build --compile --target=browser ./app.tsx --outfile ./dist/app.htmlbun build ... --external pkg # Exclude from bundle
bun build ... --define 'KEY=VALUE' # Define compile-time constants
bun build ... --loader .ext=type # Custom loaders (js, jsx, ts, tsx, json, css, text, file, base64, dataurl, binary)
bun build ... --entry-naming [dir]/[name].[ext] # Output naming pattern
bun build ... --public-path /cdn/ # Public path prefix for assetsReference: Seefor complete options.references/bundling-and-compilation.md
bun init # Initialize new project (creates package.json, tsconfig.json, index.ts)
bun create template-name # Create from template
bun create next-app my-app # Example: create Next.js app[run]
bun = true # Always use Bun runtime (not Node)
[install]
exact = true # Pin exact versions by default
peer = false # Don't auto-install peer deps
production = false # Include devDeps
frozenLockfile = false # Don't fail on lockfile mismatch
globalDir = "~/.bun/install/global" # Global install location
[install.scopes]
"@myorg" = { token = "$NPM_TOKEN", url = "https://npm.pkg.github.com/" }
[test]
coverage = false # Enable coverage by default
coverageReporter = ["text", "lcov"]
timeout = 5000 # Default test timeout
[bundle]
entryPoints = ["./src/index.ts"]
outdir = "./dist"Reference: Seefor complete bunfig.toml reference.references/configuration.md
bun --inspect file.ts # Start debugger (WebSocket, connect via Chrome DevTools)
bun --inspect-wait file.ts # Wait for debugger to attach before executing
bun --inspect-brk file.ts # Break on first line
bun --cpu-prof file.ts # Generate CPU profile
bun --cpu-prof-md file.ts # CPU profile as Markdown (v1.3.7+)
bun --heap-prof file.ts # Generate heap profile
bun --heap-prof-md file.ts # Heap profile as Markdown (v1.3.7+)
BUN_JSC_logJITCodeForPerf=1 bun file.ts # Linux perf integrationbun --env-file .env file.ts # Load .env file
bun --env-file .env.local --env-file .env file.ts # Load multiple (left takes precedence).env.env.production.env.local.env.production.localNODE_ENV.ts.tsxtscts-nodetsxbun file.tscatalog:package.jsonsyncpackmanypkg// Root package.json
{
"workspaces": ["packages/*"],
"catalog": {
"react": "^19.0.0",
"typescript": "^5.7.0"
}
}
// packages/app/package.json
{
"dependencies": {
"react": "catalog:"
}
}bun testjestvitestmochabun buildesbuildwebpackrollupimport { Database } from 'bun:sqlite'better-sqlite3sql.jsBun.$execashelljszxBun.file()Bun.write()fsnew Bun.Glob(pattern)globfast-globminimatchBun.password.hash().verify()bcryptargon2Bun.gzipSync()Bun.deflateSync()Bun.zstdCompressSync()zlibBun.semver.satisfies().order()semverBun.s3Bun.redisBun.ArchiveJSONCJSON5JSONLmarkdowncronbun-apibun ./index.htmlexperimentalDecoratorsbunnpmnodenpxbun.lockbun.lockbpackage-lock.jsontrustedDependencies--bunbun run--bun[run] bun = truebunfig.toml"workspace:*"bun add -g~/.bun/bin/[install] auto = truebun runbunbun run scriptbun file.tsbun script