bun-hot-reloading

Implements hot reloading and watch mode for Bun development servers.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-hot-reloading-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bun-hot-reloading
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/bun-hot-reloading
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill bun-hot-reloading-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Slow manual server restarts during Bun development break flow and lose application state; this Skill provides patterns for automatic code reloading with Bun's --watch and --hot flags. ## Core Features & Use Cases - Watch Mode: Restart the entire Bun process automatically when imported files change, ideal for scripts and tests. - Hot Mode: Reload modules in-place with Bun.serve while preserving in-memory state via import.meta.hot and globalThis. - Live Reload & Vite Integration: Build WebSocket-based browser live reload and run Vite with HMR through bunx. - Use Case: While developing a Bun HTTP API, run it with --hot so edits to route handlers apply instantly without losing WebSocket connections or in-memory caches. ## Quick Start Ask the assistant to set up a Bun development server with hot reloading that preserves state across code changes.

Frequently Asked Questions about bun-hot-reloading

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable hot reloading in Bun?

Run your server with bun --hot run src/server.ts to reload modules in-place without restarting the process. For full process restarts on file changes, use bun --watch run src/index.ts instead.

What is the difference between bun --watch and bun --hot?

The --watch flag restarts the entire process when files change, losing all in-memory state. The --hot flag reloads modules in-place, preserving state, and is designed for Bun.serve HTTP servers.

How do I preserve state across Bun hot reloads?

Store state on globalThis, for example globalThis.cache ??= new Map(), so it survives module reloads. Module-level variables are reset when the module is re-evaluated during a hot reload.

Why is my Bun server state lost after reload?

State is lost because you are either using --watch, which restarts the whole process, or storing state in module-level variables. Switch to --hot and move persistent state to globalThis.

Can I use Vite HMR with Bun?

Yes, run Vite through Bun with bunx --bun vite and enable hmr in the Vite server config. This gives frontend hot module replacement while Bun executes the dev server.

How do I clean up intervals and connections on Bun hot reload?

Register a cleanup callback with import.meta.hot.dispose() and clear intervals or close connections inside it. Without dispose handlers, old timers and sockets keep running after each reload, causing memory leaks.