Skip to content

bun run CLI Usage

bash
bun run <file or script>

General Execution Options

--silentboolean
Don't print the script command
--if-presentboolean
Exit without an error if the entrypoint does not exist
--evalstring
Evaluate argument as a script. Alias: -e
--printstring
Evaluate argument as a script and print the result. Alias: -p
--helpboolean
Display this menu and exit. Alias: -h

Workspace Management

--elide-linesnumber default: 10
Number of lines of script output shown when using --filter (default: 10). Set to 0 to show all lines
--filterstring
Run a script in all workspace packages matching the pattern. Alias: -F
--workspacesboolean
Run a script in all workspace packages (from the workspaces field in package.json)

Runtime & Process Control

--bunboolean
Force a script or package to use Bun's runtime instead of Node.js (via symlinking node). Alias: -b
--shellstring
Control the shell used for package.json scripts. Supports either bun or system
--smolboolean
Use less memory, but run garbage collection more often
--expose-gcboolean
Expose gc() on the global object. Has no effect on Bun.gc()
--no-deprecationboolean
Suppress all reporting of the custom deprecation
--throw-deprecationboolean
Determine whether or not deprecation warnings result in errors
--titlestring
Set the process title
--zero-fill-buffersboolean
Boolean to force Buffer.allocUnsafe(size) to be zero-filled
--no-addonsboolean
Throw an error if process.dlopen is called, and disable export condition node-addons
--unhandled-rejectionsstring
One of strict, throw, warn, none, or{" "} warn-with-error-code
--console-depthnumber default: 2
Set the default depth for console.log object inspection (default: 2)

Development Workflow

--watchboolean
Automatically restart the process on file change
--hotboolean
Enable auto reload in the Bun runtime, test runner, or bundler
--no-clear-screenboolean
Disable clearing the terminal screen on reload when --hot or --watch is enabled

Debugging

--inspectstring
Activate Bun's debugger
--inspect-waitstring
Activate Bun's debugger, wait for a connection before executing
--inspect-brkstring
Activate Bun's debugger, set breakpoint on first line of code and wait

Dependency & Module Resolution

--preloadstring
Import a module before other modules are loaded. Alias: -r
--requirestring
Alias of --preload, for Node.js compatibility
--importstring
Alias of --preload, for Node.js compatibility
--no-installboolean
Disable auto install in the Bun runtime
--installstring default: auto
Configure auto-install behavior. One of auto (default, auto-installs when no node_modules),{" "} fallback (missing packages only), force (always)
-iboolean
Auto-install dependencies during execution. Equivalent to --install=fallback
--prefer-offlineboolean
Skip staleness checks for packages in the Bun runtime and resolve from disk
--prefer-latestboolean
Use the latest matching versions of packages in the Bun runtime, always checking npm
--conditionsstring
Pass custom conditions to resolve
--main-fieldsstring
Main fields to lookup in package.json. Defaults to --target dependent
--preserve-symlinksboolean
Preserve symlinks when resolving files
--preserve-symlinks-mainboolean
Preserve symlinks when resolving the main entry point
--extension-orderstring default: .tsx,.ts,.jsx,.js,.json
Defaults to: .tsx,.ts,.jsx,.js,.json

Transpilation & Language Features

--tsconfig-overridestring
Specify custom tsconfig.json. Default $cwd/tsconfig.json
--definestring
Substitute K:V while parsing, e.g. --define process.env.NODE_ENV:"development". Values are parsed as JSON. Alias: -d
--dropstring
Remove function calls, e.g. --drop=console removes all console.* calls
--loaderstring
Parse files with .ext:loader, e.g. --loader .js:jsx. Valid loaders: js,{" "} jsx, ts, tsx, json, toml, text,{" "} file, wasm, napi. Alias: -l
--no-macrosboolean
Disable macros from being executed in the bundler, transpiler and runtime
--jsx-factorystring
Changes the function called when compiling JSX elements using the classic JSX runtime
--jsx-fragmentstring
Changes the function called when compiling JSX fragments
--jsx-import-sourcestring default: react
Declares the module specifier to be used for importing the jsx and jsxs factory functions. Default: react
--jsx-runtimestring default: automatic
automatic (default) or classic
--jsx-side-effectsboolean
Treat JSX elements as having side effects (disable pure annotations)
--ignore-dce-annotationsboolean
Ignore tree-shaking annotations such as @__PURE__

Networking & Security

--portnumber
Set the default port for Bun.serve
--fetch-preconnectstring
Preconnect to a URL while code is loading
--max-http-header-sizenumber default: 16384
Set the maximum size of HTTP headers in bytes. Default is 16KiB
--dns-result-orderstring default: verbatim
Set the default order of DNS lookup results. Valid orders: verbatim (default), ipv4first,{" "} ipv6first
--use-system-caboolean
Use the system's trusted certificate authorities
--use-openssl-caboolean
Use OpenSSL's default CA store
--use-bundled-caboolean
Use bundled CA store
--redis-preconnectboolean
Preconnect to $REDIS_URL at startup
--sql-preconnectboolean
Preconnect to PostgreSQL at startup
--user-agentstring
Set the default User-Agent header for HTTP requests

Global Configuration & Context

--env-filestring
Load environment variables from the specified file(s)
--cwdstring
Absolute path to resolve files & entry points from. This just changes the process' cwd
--configstring
Specify path to Bun config file. Default $cwd/bunfig.toml. Alias: -c

Examples

Run a JavaScript or TypeScript file:

bash
bun run ./index.js
bun run ./index.tsx

Run a package.json script:

bash
bun run dev
bun run lint