--watch— hard restarts the process when imported files change.--hot— soft reloads code without restarting the process.
- --watch
- --hot
Restarts the entire Bun process when a file changes. All global state is reset. Suitable for scripts, CLI tools, and test suites.
--watch mode
Run a file and restart it automatically whenever any imported file changes:
--watch mode, Bun:
- Tracks all imported files and watches them for changes.
- Restarts the process with the same CLI arguments and environment variables on change.
- Automatically restarts if the process crashes.
Bun uses operating system native filesystem APIs (
kqueue on macOS, inotify on Linux) rather than polling. This makes watch mode fast even in large projects.Example: live-reloading an HTTP server
server.ts, the process restarts and re-runs from the top.
--no-clear-screen
In environments where multiple watch processes run simultaneously (e.g., with concurrently), use --no-clear-screen to prevent each reload from clearing the terminal:
--preserveWatchOutput.
--hot mode
Use --hot to enable hot reloading. Unlike --watch, Bun does not restart the process. Instead, it detects file changes, resets the internal module cache, and re-evaluates changed files. All global state stored on globalThis is preserved across reloads.
node_modules) and watches them for changes.
Tracking reload count
BecauseglobalThis persists across reloads, you can use it to track state:
bun --hot run server.ts and saving the file prints an incrementing count:
HTTP servers with --hot
--hot is particularly useful with HTTP servers. When you save the file, Bun re-evaluates the module and the server picks up the new request handler — without closing the port or losing connections.
nodemon, which restart the entire process and tear down the HTTP server, bun --hot reflects code changes in-place. This results in much faster iteration cycles.
--hot is the server-side equivalent of browser hot reloading. For hot reloading in the browser (e.g., React component updates without a page refresh), use a framework like Vite.Comparison
| Feature | --watch | --hot |
|---|---|---|
| Full process restart | Yes | No |
| Global state preserved | No | Yes (globalThis) |
Works with bun test | Yes | No |
| Works with HTTP servers | Yes (reconnects) | Yes (no downtime) |
| Crash recovery | Yes | No |