Portmoleby techynARDownload

How to find and stop dev servers Claude Code, Cursor and Codex left running

By techynAR · Updated

Short answerAI coding agents like Claude Code, Cursor and Codex often start a dev server in the background and lose track of it, then start another one on the next free port. Run lsof -nP -iTCP -sTCP:LISTEN to list every server still running, check which project each one belongs to, and stop the leftovers with kill <PID>. Portmole shows the same list in your menu bar, by project name, with one click to close each server.

Why this keeps happening

When you ask an agent to “run the app” or “check it in the browser”, it usually starts npm run dev (or pnpm dev, uvicorn, rails s…) as a background process so it can keep working. That process outlives the step that started it. A few turns later the agent has forgotten it, runs the command again, finds port 3000 taken and quietly moves to 3001. Do that across a few sessions and projects and your Mac is running five copies of the same app.

Step 1: list everything that is still running

lsof -nP -iTCP -sTCP:LISTEN

Every line is a process waiting for connections. Dev servers usually show up as node, bun, python, ruby or deno on ports like 3000, 3001, 5173, 8000 or 8080. To check a run of ports at once, give lsof a range:

lsof -nP -iTCP:3000-3010 -sTCP:LISTEN

Step 2: work out which project each one belongs to

Five lines that all say node are not much help. These two commands tell you what a PID actually is. The first shows the full command and how long it has been running, the second shows the folder it was started from:

ps -o pid,ppid,etime,command -p 12345
lsof -a -p 12345 -d cwd

A PPID of 1 means whatever started the server (a terminal, an editor or an agent session) has already exited and the server is an orphan. Those are almost always safe to stop.

Step 3: stop the leftovers

kill 12345

Plain kill sends SIGTERM so the server can shut down cleanly. Use kill -9 only if it is still listening a few seconds later. To stop everything on ports 3000 to 3010 in one go:

lsof -t -iTCP:3000-3010 -sTCP:LISTEN | xargs kill

Check the list from step 1 first. A database such as Postgres on 5432 or a Docker container should usually stay running.

Stop it happening again

Give your agent a rule in its instructions file (CLAUDE.md, AGENTS.md or .cursor/rules) so it reuses the server instead of starting a new one:

Before starting a dev server, check whether one is already running:
lsof -nP -iTCP:3000 -sTCP:LISTEN
If it is, reuse it. Never start a second server on another port.
When you are done with a server you started, stop it.

Then make the port strict, so a leftover shows up as an error straight away instead of a silent move to 3001. In Vite, run vite --strictPort or set server.strictPort: true. For other frameworks, pin the port explicitly (for example next dev -p 3000) so you always know where the app should be.

See it all without the terminal

Portmole is a free Mac menu bar app made for exactly this. It lists every server by the page's title (“Acme Dashboard”, not “node”), shows the command that started it and its project folder, and closes it with one click. Servers your agents start show up as they appear, and the little mole hops each time one does.

Frequently asked questions

Why does Claude Code start my dev server on port 3001 instead of 3000?

Usually because a server it started earlier is still running on 3000. Most dev servers move to the next free port when theirs is taken. Find the old one with lsof -nP -iTCP:3000 -sTCP:LISTEN and stop it, or tell the agent to reuse it.

Is it safe to kill dev servers my AI agent started?

Yes, if they are dev servers for your own projects. Use plain kill first so they shut down cleanly. Leave databases and Docker containers alone unless you know you don't need them.

How do I stop all node processes listening on ports on Mac?

Run lsof -a -t -iTCP -sTCP:LISTEN -c node | xargs kill. The -a makes lsof match only node processes that are listening on a port. It stops all of them, so check the list first if you have one you want to keep.

How can I see which project a localhost server belongs to?

Run lsof -a -p <PID> -d cwd to see the folder the process was started from. Portmole shows the project folder next to every server automatically.

Skip the terminal

Portmole shows every port your Mac is listening on and closes any of them with one click. Free, signed and notarized, about 7 MB.

Download Portmole for Mac

Keep reading