# TL;DR
This is expected behavior, not a bug: hot reload replaces the running isolate, and the inspector session was attached to the old one. Reconnect the debugger after each reload, or pause your edits while you hold a debugging session. If you need stable breakpoints across edits, debug against a build you are not changing, or use logging instead of breakpoints for reload-heavy work.

```text
wrangler dev error: inspector websocket disconnected on reload
```

1. Confirm the disconnect lines up with a reload. Watch the wrangler dev output while the debugger is attached and save a file.

Expected: the terminal shows a rebuild at the same moment the inspector drops. Correlation confirms the cause.

2. Reconnect the inspector after the reload completes. In chrome://inspect or your DevTools, the worker target reappears under the new isolate; click inspect again.

Expected: a fresh debugging session attaches to the new isolate. Breakpoints need re-adding because it is a new session.

3. If you are iterating on one bug, stop editing during the debug session. Set your breakpoints, reproduce, inspect, then detach before the next edit.

Expected: no mid-session disconnects because no reload fires while you are attached.

4. For reload-heavy debugging, switch to structured logging (console.log with distinctive prefixes) and read output via the wrangler dev terminal or wrangler tail instead of breakpoints.

Expected: you get per-reload visibility without any inspector session to lose.

5. If the inspector disconnects WITHOUT any reload (no rebuild in the terminal), check for a proxy or VPN killing idle websockets, and check that only one DevTools client is attached; two clients fight over the session.

Expected: with a stable network and a single client, the session survives between reloads.

## Use this when
- The debugger drops exactly when hot reload rebuilds.
- Breakpoints vanish after every save.
- You are debugging wrangler dev locally and the session feels flaky.

## Not for this skill when
- The inspector never connects in the first place. That is a devtools URL or flag issue; check the --inspect output wrangler prints.
- The session drops with no reload and no network change. Look for a second attached client or an aggressive idle-timeout proxy.
- You are debugging the deployed worker. Deployed workers have no inspector; use wrangler tail and logs.

## Variant phrasings
- wrangler dev debugger disconnects on file save
- cloudflare workers inspector session lost on reload
- devtools disconnects when worker hot reloads
- wrangler --inspect websocket closed

## Why it happens
The inspector attaches to a specific V8 isolate instance. Hot reload works by compiling the new bundle into a fresh isolate and swapping it in; the old isolate, with your debugger session, is discarded. The websocket close is the runtime telling you the debuggee is gone. No debugger can survive the thing it is attached to being replaced, so every reload necessarily ends the session.

## Edge cases
- Breakpoints set by URL/line do not transfer to the new isolate. If your editor re-attaches automatically, you still need to re-set breakpoints each time.
- console.log output also resets its grouping per isolate; correlate logs with the rebuild timestamps in the terminal.
- Remote debugging (wrangler dev --remote with inspect) has the same lifecycle, plus network flakiness on top. Prefer local for interactive debugging.
- Some agents script the inspect URL and treat a disconnect as a crash. Teach the loop that a disconnect right after its own file write is a reload, not a failure, and have it re-fetch the inspect target.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_rH3Bx_lN5vx1l3hlzkHcmQ
