Let Claude Code own the dev servers it starts

Problem: I ask Claude Code to check a change in the browser. It starts a dev server (next dev, vite, it doesn’t matter which), takes a screenshot and moves on. Hours later the server is still holding port 3000, and the next npm run dev quietly lands on 3001.

Why: It depends on how the server was started. The Bash tool has a background mode: the command gets a task ID, shows up in /tasks, and Claude Code stops it when it exits. A server started with npm run dev &, nohup, start, Start-Process or a tool’s own --background flag detaches from the shell instead, so Claude Code never knows it exists. Killing it afterwards by scraping netstat is fragile too: on a German Windows the state column says ABHÖREN, not LISTENING, so a grep LISTENING cleanup silently kills nothing.

Fix: Make every dev server a background task that Claude Code tracks. Put the rule in ~/.claude/CLAUDE.md so it applies to every project:

## Dev servers
- Start dev servers (npm run dev, next dev, vite, ...) only with the Bash tool's
  run_in_background option. Never use `&`, `nohup`, `start`, `Start-Process`,
  or the tool's own background/daemon flag.
- If a dev server you started earlier in the session is still running, reuse it.
- When you're done checking a change, stop the task.
  • /tasks lists the running shells and subagents, and you can stop one from there.
  • Exiting Claude Code stops all background tasks. On macOS and Linux that includes processes that detached from the task’s shell.
  • Ctrl+B moves a Bash command that is already running into the background, so a server started in the foreground can still be handed over.
  • Backgrounding the session instead of exiting it keeps its tasks running.

Remember: A dev server that Claude Code starts must be a background task, never a &. Then /tasks shows it and exiting stops it.