
Bun Runtime
- 86 installs
- 202 repo stars
- Updated August 4, 2026
- secondsky/claude-skills
Helps with ai & agent building tasks during AI-assisted development.
About
bun runtime is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- bun runtime
- AI & Agent Building
- AI-coding skill
Bun Runtime by the numbers
- 86 all-time installs (skills.sh)
- Ranked #5,032 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/secondsky/claude-skills --skill bun-runtimeAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 86 |
|---|---|
| repo stars | ★ 202 |
| Last updated | August 4, 2026 |
| Repository | secondsky/claude-skills ↗ |
What it does
Helps with ai & agent building tasks during AI-assisted development.
Files
Bun Runtime
Bun is a fast all-in-one JavaScript runtime built on JavaScriptCore (Safari's engine). It provides 4x faster startup than Node.js on Linux.
Quick Start
# Run a file
bun run index.ts
bun index.ts # shorthand
# Run with watch mode
bun --watch run index.ts
# Run package.json script
bun run dev
# Run with hot reloading
bun --hot run server.tsCore CLI Flags
| Flag | Purpose |
|---|---|
--watch | Restart on file changes |
--hot | Hot module replacement (preserves state) |
--smol | Reduce memory usage (slower GC) |
--inspect | Enable debugger |
--preload | Load modules before execution |
--env-file | Load specific .env file |
-e, --eval | Evaluate code string |
Running Files
Bun transpiles TypeScript and JSX on-the-fly:
bun run index.js
bun run index.ts
bun run index.jsx
bun run index.tsxImportant: Put Bun flags immediately after bun:
bun --watch run dev # Correct
bun run dev --watch # Wrong - flag passed to scriptPackage.json Scripts
# Run script
bun run dev
bun dev # shorthand (if no Bun command conflicts)
# List available scripts
bun run
# Run with Bun instead of Node
bun run --bun viteBun respects lifecycle hooks (preclean, postclean, etc.).
Watch Mode vs Hot Reloading
| Mode | Flag | Behavior |
|---|---|---|
| Watch | --watch | Full process restart on changes |
| Hot | --hot | Replace modules, preserve state |
# Watch mode - full restart
bun --watch run server.ts
# Hot reloading - preserves connections/state
bun --hot run server.tsEnvironment Variables
Bun automatically loads .env files:
# Loads automatically: .env, .env.local, .env.development
bun run index.ts
# Specify env file
bun --env-file .env.production run index.ts
# Disable auto-loading
# In bunfig.toml: env = falseAccess in code:
const apiKey = process.env.API_KEY;
const bunEnv = Bun.env.NODE_ENV;Globals Available
| Global | Source | Notes |
|---|---|---|
Bun | Bun | Main API object |
Buffer | Node.js | Binary data |
process | Node.js | Process info |
fetch | Web | HTTP requests |
Request/Response | Web | HTTP types |
WebSocket | Web | WebSocket client |
crypto | Web | Cryptography |
console | Web | Logging |
__dirname | Node.js | Current directory |
__filename | Node.js | Current file |
Preload Scripts
Load modules before your main script:
bun --preload ./setup.ts run index.tsOr in bunfig.toml:
preload = ["./setup.ts"]Use cases: polyfills, global setup, instrumentation.
Stdin Execution
# Pipe code to Bun
echo "console.log('Hello')" | bun run -
# Redirect file
bun run - < script.jsWorkspaces & Monorepos
# Run script in specific packages
bun run --filter 'pkg-*' build
# Run in all workspaces
bun run --filter '*' testDebugging
# Start debugger
bun --inspect run index.ts
# Wait for debugger connection
bun --inspect-wait run index.ts
# Break on first line
bun --inspect-brk run index.tsConnect via Chrome DevTools or VS Code.
Common Errors
| Error | Cause | Fix |
|---|---|---|
Cannot find module | Missing dependency | Run bun install |
Top-level await | Using await outside async | Wrap in async function or use .mts |
--watch not working | Flag in wrong position | Put flag before run |
When to Load References
Load references/bunfig.md when:
- Configuring bunfig.toml
- Setting up test configuration
- Configuring package manager behavior
- Setting JSX options
Load references/cli-flags.md when:
- Need complete CLI flag reference
- Configuring advanced runtime options
- Setting up debugging
Load references/module-resolution.md when:
- Troubleshooting import errors
- Configuring path aliases
- Understanding Bun's resolution algorithm
bunfig.toml Configuration Reference
Complete reference for configuring Bun's behavior via bunfig.toml.
File Locations
Local (project root): bunfig.toml Global: $HOME/.bunfig.toml or $XDG_CONFIG_HOME/.bunfig.toml
Local settings override global. CLI flags override both.
Runtime Configuration
preload
Load scripts/plugins before running files:
preload = ["./preload.ts"]jsx
Configure JSX handling (also settable in tsconfig.json):
jsx = "react"
jsxFactory = "h"
jsxFragment = "Fragment"
jsxImportSource = "react"smol
Reduce memory usage at cost of performance:
smol = truelogLevel
Set log verbosity:
logLevel = "debug" # "debug" | "warn" | "error"define
Replace global identifiers with constant expressions:
[define]
"process.env.bagel" = "'lox'"loader
Map file extensions to loaders:
[loader]
".bagel" = "tsx"Available loaders: jsx, js, ts, tsx, json, jsonc, toml, yaml, css, html, text, wasm, napi, file, sh
telemetry
Enable/disable analytics and crash reports:
telemetry = falseenv
Configure .env file loading:
# Disable automatic .env loading
env = false
# Or use object syntax
[env]
file = falseconsole
Configure console output:
[console]
depth = 3 # Default: 2Test Runner Configuration
[test]
root = "./__tests__"
preload = ["./setup.ts"]
smol = true
coverage = true
coverageThreshold = 0.9
coverageSkipTestFiles = false
coveragePathIgnorePatterns = ["**/*.spec.ts", "**/*.test.ts"]
coverageReporter = ["text", "lcov"]
coverageDir = "coverage"
randomize = true
seed = 2444615283
rerunEach = 3
concurrentTestGlob = "**/concurrent-*.test.ts"
onlyFailures = true
[test.reporter]
dots = true
junit = "test-results.xml"Coverage Threshold Options
# Single threshold for all
coverageThreshold = 0.9
# Per-type thresholds
coverageThreshold = { line = 0.7, function = 0.8, statement = 0.9 }Package Manager Configuration
[install]
optional = true # Install optionalDependencies
dev = true # Install devDependencies
peer = true # Install peerDependencies
production = false # Production mode
exact = false # Use exact versions in package.json
saveTextLockfile = true # Use text-based bun.lock
auto = "auto" # Auto-install behavior
frozenLockfile = false # Don't update lockfile
dryRun = false # Don't actually install
globalDir = "~/.bun/install/global"
globalBinDir = "~/.bun/bin"
registry = "https://registry.npmjs.org"
linkWorkspacePackages = true
linker = "hoisted" # "hoisted" | "isolated"
minimumReleaseAge = 259200 # 3 days in seconds
minimumReleaseAgeExcludes = ["@types/bun", "typescript"]Auto-install Values
| Value | Description |
|---|---|
"auto" | Auto-install when no node_modules |
"force" | Always auto-install |
"disable" | Never auto-install |
"fallback" | Check local first, then auto-install missing |
Scoped Registries
[install.scopes]
myorg = "https://username:password@registry.myorg.com/"
myorg = { username = "myusername", password = "$npm_password", url = "https://registry.myorg.com/" }
myorg = { token = "$npm_token", url = "https://registry.myorg.com/" }Cache Configuration
[install.cache]
dir = "~/.bun/install/cache"
disable = false
disableManifest = falseLockfile Configuration
[install.lockfile]
save = true
print = "yarn" # Generate yarn.lock alongside bun.lockSecurity Scanner
[install.security]
scanner = "@acme/bun-security-scanner"CA Certificates
[install]
ca = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
cafile = "path/to/cafile"bun run Configuration
[run]
shell = "system" # "system" | "bun"
bun = true # Auto-alias node to bun
silent = true # Suppress command outputDebug Configuration
[debug]
editor = "code" # Editor for blob:/src: linksAvailable editors: subl, sublime, vscode, code, textmate, mate, idea, webstorm, nvim, neovim, vim, vi, emacs
Complete Example
# Runtime
preload = ["./setup.ts"]
smol = false
logLevel = "warn"
telemetry = false
[define]
"process.env.NODE_ENV" = "'production'"
[loader]
".graphql" = "text"
[console]
depth = 4
# Testing
[test]
root = "./tests"
coverage = true
coverageThreshold = { line = 0.8, function = 0.9 }
coverageReporter = ["text", "lcov"]
# Package Manager
[install]
production = false
exact = false
saveTextLockfile = true
linker = "isolated"
[install.scopes]
company = { token = "$NPM_TOKEN", url = "https://npm.company.com/" }
# bun run
[run]
shell = "bun"
bun = true
silent = falseBun CLI Flags Reference
Complete reference for bun run CLI flags and options.
General Execution
| Flag | Description |
|---|---|
--silent | Don't print the script command |
--if-present | Exit without error if entrypoint doesn't exist |
--eval, -e | Evaluate argument as script |
--print, -p | Evaluate and print result |
--help, -h | Display help menu |
Workspace Management
| Flag | Description |
|---|---|
--elide-lines <n> | Lines shown with --filter (default: 10) |
--filter, -F | Run in matching workspace packages |
--workspaces | Run in all workspace packages |
Runtime & Process Control
| Flag | Description |
|---|---|
--bun, -b | Force Bun runtime instead of Node.js |
--shell | Shell for scripts: bun or system |
--smol | Use less memory, more GC |
--expose-gc | Expose gc() global |
--no-deprecation | Suppress deprecation warnings |
--throw-deprecation | Throw on deprecation |
--title | Set process title |
--zero-fill-buffers | Zero-fill Buffer.allocUnsafe |
--no-addons | Disable process.dlopen |
--unhandled-rejections | strict, throw, warn, none, warn-with-error-code |
--console-depth <n> | console.log depth (default: 2) |
Development Workflow
| Flag | Description |
|---|---|
--watch | Restart on file change |
--hot | Hot module replacement |
--no-clear-screen | Don't clear terminal on reload |
Debugging
| Flag | Description |
|---|---|
--inspect | Activate debugger |
--inspect-wait | Wait for debugger connection |
--inspect-brk | Break on first line |
Dependency & Module Resolution
| Flag | Description |
|---|---|
--preload, -r | Import module before others |
--require | Alias of --preload |
--import | Alias of --preload |
--no-install | Disable auto install |
--install | auto, fallback, force |
-i | Shorthand for --install=fallback |
--prefer-offline | Skip staleness checks |
--prefer-latest | Always check npm for latest |
--conditions | Custom resolve conditions |
--main-fields | package.json main fields |
--preserve-symlinks | Preserve symlinks when resolving |
--preserve-symlinks-main | Preserve main entry symlinks |
--extension-order | Default: .tsx,.ts,.jsx,.js,.json |
Transpilation & Language
| Flag | Description |
|---|---|
--tsconfig-override | Custom tsconfig.json path |
--define, -d | Substitute K:V while parsing |
--drop | Remove function calls (e.g., --drop=console) |
--loader, -l | Parse files with .ext:loader |
--no-macros | Disable macros |
--jsx-factory | JSX element function |
--jsx-fragment | JSX fragment function |
--jsx-import-source | JSX import source (default: react) |
--jsx-runtime | automatic or classic |
--jsx-side-effects | Treat JSX as having side effects |
--ignore-dce-annotations | Ignore @PURE annotations |
Networking & Security
| Flag | Description |
|---|---|
--port | Default port for Bun.serve |
--fetch-preconnect | Preconnect URL while loading |
--max-http-header-size | Max HTTP header bytes (default: 16384) |
--dns-result-order | verbatim, ipv4first, ipv6first |
--use-system-ca | Use system CA store |
--use-openssl-ca | Use OpenSSL CA store |
--use-bundled-ca | Use bundled CA store |
--redis-preconnect | Preconnect to $REDIS_URL |
--sql-preconnect | Preconnect to PostgreSQL |
--user-agent | Default HTTP User-Agent |
Global Configuration
| Flag | Description |
|---|---|
--env-file | Load env from file(s) |
--cwd | Working directory |
--config, -c | Config file path |
Examples
Basic Execution
# Run a file
bun run index.ts
bun index.ts # shorthand
# Run package.json script
bun run dev
bun dev # shorthand
# Run with flags
bun --watch run index.ts
bun --hot run server.tsWatch & Development
# Watch mode (full restart)
bun --watch run server.ts
# Hot reloading (preserves state)
bun --hot run server.ts
# With verbose output
bun --watch --no-clear-screen run devDebugging
# Start debugger
bun --inspect run index.ts
# Wait for debugger
bun --inspect-wait run index.ts
# Break on first line
bun --inspect-brk run index.tsWorkspaces
# Run in matching packages
bun run --filter 'pkg-*' build
# Run in all workspaces
bun run --filter '*' test
# Exclude packages
bun install --filter '!pkg-c'Environment
# Specific env file
bun --env-file .env.production run index.ts
# Multiple env files
bun --env-file .env --env-file .env.local run index.tsMemory & Performance
# Reduce memory usage
bun --smol run index.ts
# Increase console depth
bun --console-depth 5 run index.tsForcing Bun Runtime
# Force Bun instead of Node for CLI tools
bun --bun run vite
bun run --bun next devPiping Code
# Execute from stdin
echo "console.log('Hello')" | bun run -
# Redirect file
bun run - < script.jsCustom Loaders
# Custom file extension loader
bun --loader .graphql:text run index.ts
# Multiple loaders
bun -l .sql:text -l .md:text run index.tsDefine Constants
# Replace at parse time
bun --define process.env.NODE_ENV:"'production'" run build.ts
bun -d DEBUG:true run index.tsDrop Code
# Remove console calls
bun --drop=console run index.ts
# Remove debugger statements
bun --drop=debugger run index.tsBun Module Resolution Reference
How Bun resolves modules and handles imports in JavaScript and TypeScript.
Import Syntax
Extension Resolution Order
When importing without extension, Bun checks in order:
./hello.tsx
./hello.jsx
./hello.ts
./hello.mjs
./hello.js
./hello.cjs
./hello.json
./hello/index.tsx
./hello/index.jsx
./hello/index.ts
./hello/index.mjs
./hello/index.js
./hello/index.cjs
./hello/index.jsonWith Extensions
import { hello } from "./hello"; // Extensionless
import { hello } from "./hello.ts"; // TypeScript
import { hello } from "./hello.js"; // Also resolves .ts/.tsxImporting from .js also checks for matching .ts file (TypeScript compatibility).
Module Systems
Bun supports both ES Modules and CommonJS.
Module Type Resolution
| Module Type | require() Returns | import * as Returns |
|---|---|---|
| ES Module | Module Namespace | Module Namespace |
| CommonJS | module.exports | default = module.exports, named = keys |
Using require()
const { foo } = require("./foo"); // No extension
const { bar } = require("./bar.mjs"); // ESM
const { baz } = require("./baz.tsx"); // TSXUsing import
import { foo } from "./foo";
import bar from "./bar.ts";
import { stuff } from "./my-commonjs.cjs";Mixed Usage
// Both work in same file
import { stuff } from "./my-commonjs.cjs";
const myStuff = require("./my-commonjs.cjs");Top-Level Await Restriction
Files with top-level await cannot be require()d (synchronous limitation). Use import or dynamic import() instead.
Package Resolution
exports Field Priority
{
"name": "foo",
"exports": {
"bun": "./index.ts", // Bun-specific (TypeScript!)
"node": "./index.js", // Node.js
"require": "./index.js", // CommonJS
"import": "./index.mjs", // ESM
"default": "./index.js" // Fallback
}
}First matching condition wins.
Subpath Exports
{
"exports": {
".": "./index.js",
"./utils": "./utils.js"
}
}Conditional Subpath Exports
{
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
}
}
}Fallback Fields
If no exports, Bun checks: 1. module (ESM imports only) 2. main
{
"name": "foo",
"module": "./index.mjs",
"main": "./index.js"
}Shipping TypeScript
Use "bun" export condition for direct TypeScript:
{
"exports": {
"bun": "./src/index.ts",
"default": "./dist/index.js"
}
}Custom Conditions
bun build --conditions="react-server" --target=bun ./app.js
bun --conditions="react-server" ./app.jsProgrammatic:
await Bun.build({
conditions: ["react-server"],
target: "bun",
entryPoints: ["./app.js"],
});Path Re-mapping
tsconfig.json paths
{
"compilerOptions": {
"paths": {
"config": ["./config.ts"],
"components/*": ["components/*"]
}
}
}package.json imports (Node.js style)
{
"imports": {
"#config": "./config.ts",
"#components/*": "./components/*"
}
}NODE_PATH
Additional module resolution directories:
NODE_PATH=./packages bun run src/index.js
# Multiple paths
NODE_PATH=./packages:./lib bun run src/index.js # Unix
NODE_PATH=./packages;./lib bun run src/index.js # Windowsimport.meta Properties
| Property | Description | Example |
|---|---|---|
import.meta.dir | Directory path | /path/to/project |
import.meta.dirname | Alias for dir | /path/to/project |
import.meta.file | Filename | index.ts |
import.meta.path | Full path | /path/to/project/index.ts |
import.meta.filename | Alias for path | /path/to/project/index.ts |
import.meta.url | File URL | file:///path/to/project/index.ts |
import.meta.main | Is entry point? | true or false |
import.meta.env | Alias for process.env | { NODE_ENV: "..." } |
import.meta.resolve() | Resolve specifier | "file:///path/to/module.js" |
Usage Examples
// Get current directory (like __dirname)
const dir = import.meta.dir;
// Check if main entry point
if (import.meta.main) {
console.log("Running directly");
}
// Resolve module path
const zodPath = import.meta.resolve("zod");
// "file:///path/to/node_modules/zod/index.js"Resolution Order
When running bun run:
1. package.json scripts 2. Source files 3. Binaries from project packages 4. System commands (bun run only)
Common Patterns
Dynamic Imports
const module = await import("./dynamic.ts");Conditional Imports
const db = process.env.USE_SQLITE
? await import("./sqlite.ts")
: await import("./postgres.ts");JSON Imports
import config from "./config.json";
import data from "./data.json" with { type: "json" };TOML Imports
import config from "./config.toml";Text/File Imports
// With custom loader
import sql from "./query.sql" with { type: "text" };Troubleshooting
Cannot find module
1. Check file exists at expected path 2. Verify extension resolution order 3. Check package.json exports field 4. Run bun install
Circular Dependencies
Bun handles circular imports, but use caution with:
- Top-level await in circular chains
- CommonJS modules with complex circular refs
TypeScript Path Aliases Not Working
Ensure tsconfig.json is at project root or specify:
bun --tsconfig-override ./path/to/tsconfig.json run index.ts