← Guides

Find dev servers your AI coding agent left running

By , who makes Ramback · Updated

Claude Code, Cursor, Codex and Gemini CLI run npm run dev to check their work, and often leave the server running when they move on or the session ends. The next one lands on port 3001, then 3002. Each holds a few hundred megabytes, sometimes more than a gigabyte, until you find it.

List every server that's listening

lsof -nP -iTCP -sTCP:LISTEN
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    48213 you    23u  IPv6 0x1f…      0t0  TCP *:3000 (LISTEN)
node    51877 you    25u  IPv6 0x7a…      0t0  TCP *:3001 (LISTEN)
node    52410 you    24u  IPv4 0x3c…      0t0  TCP 127.0.0.1:5173 (LISTEN)

Dev servers are usually node, bun, deno, python or ruby. macOS and other apps show up here too: ControlCe on ports 5000 and 7000 is the AirPlay Receiver, not something you started.

See which agent started it

Walk up the process tree from the server's PID. Each line is the parent of the one above it:

pid=48213
while [ "$pid" -gt 1 ]; do
  ps -o pid=,command= -p "$pid"
  pid=$(ps -o ppid= -p "$pid" | tr -d ' ')
done
48213 next-server (v16.4.2)
48201 node /Users/you/code/shop/node_modules/.bin/next dev
48190 npm run dev
48177 /bin/zsh -c … npm run dev
47902 claude

The first line that names an agent tells you who started it: claude for Claude Code, codex for Codex, cursor-agent for Cursor's CLI and gemini for Gemini CLI. Servers started from Cursor's editor trace back to Cursor.app.

If the chain reaches PID 1 (launchd) right after the server, whatever started it has already quit and the server was left behind. Its working directory still tells you which project it belongs to:

lsof -a -p 48213 -d cwd

Stop it

kill 48213

That sends SIGTERM, so the server closes its connections and exits. npm and the shell above it exit on their own once it's gone. If it comes straight back, a watcher such as nodemon or pm2 is restarting it: Kill the process on port 3000 covers that case.

Ask the agent to clean up after itself

Put this in CLAUDE.md for Claude Code, AGENTS.md for Codex and Cursor, or GEMINI.md for Gemini CLI:

## Dev servers
- Before starting a dev server, check whether this project already has one:
  lsof -nP -iTCP -sTCP:LISTEN
- Reuse a running server instead of starting another on a new port.
- If you start a server, stop it before you finish.

Agents follow it most of the time. When a session is cut short, nothing runs the last step, so it's still worth checking the list now and then.