Find dev servers left running by Claude Code or Codex on Mac
Find the dev servers a Claude Code or Codex session started, see if the session ended, and stop them safely.
You ask Claude Code or Codex to fix a bug. It runs pnpm dev to check its work, the session ends, and the server keeps running. A week later port 3000 is taken, five node processes hold memory, and none of them belongs to a terminal you have open. This guide shows how to find those servers and stop the right ones.
Why agent servers outlive the session
- The agent runs commands through a shell. A server started in the background, or with
&, does not stop when that shell exits. - When the session ends, the server's parent dies and macOS gives it to
launchd(PID 1). It keeps its port and its memory. - Agents often work in a git worktree, such as
.claude/worktrees/fix-cart. The server runs from a folder you may never open.
List what is listening
lsof -nP -iTCP -sTCP:LISTENNote the PIDs of dev servers you do not recognise. Then check each one:
ps -o pid,ppid,lstart,command -p 48213A ppid of 1 means the process that started it is gone. lstart shows when it started. The command often shows the project or worktree path.
Check if an agent started it
Both agents leave a mark in the environment of every command they run. You can read the environment of your own processes:
ps -E -ww -o command= -p 48213 | tr ' ' '\n' | grep -E '^(CLAUDECODE|CLAUDE_PID|CODEX_THREAD_ID)='CLAUDECODE=1means Claude Code started it.CLAUDE_PIDis the PID of that Claude Code session.CODEX_THREAD_IDmeans Codex started it. When both appear, Codex was started from inside Claude Code, so Codex is the one that ran the server.- No output means no agent started it, or macOS hides the environment. macOS hides it for system binaries such as
/usr/bin/python3.
Check if the session is still running
For Claude Code, check if CLAUDE_PID is still a claude process:
ps -o pid,command -p <CLAUDE_PID>No output, or a different command, means the session ended. Codex records no PID. If pgrep -x codex prints nothing, no Codex session runs at all. If one does, you cannot tell from the process alone which session started the server.
Stop it
kill 48213kill sends SIGTERM, so the server can clean up. Stop the root of the server, not only the process on the port. If the listener is a node child of a pnpm that is still alive, stop the pnpm. Otherwise it may start the server again. Do not stop a server while its session still uses it. The agent may be in the middle of a test run. For more on signals, see how to kill the process on a port.
Do it in one glance with Portfox
Portfox is a free menu bar app that runs these checks for every listener, all the time.
- A badge on each server that Claude Code or Codex started.
- A session ended mark when the agent's session is gone and the server still runs.
- Orphaned: the launcher exited and the server sits under launchd in a project folder.
- Idle time on agent servers, such as "Idle 45m", and one banner when a server has done nothing past your limit (30 minutes to 8 hours). Portfox never stops a server by itself.
- Stop sends SIGTERM to the server's root process, then shows roughly how much memory came back.
brew install --cask xergic/tap/portfoxNo Homebrew? Download the app from portfox.kandera.cz/download. Portfox needs macOS 15 or later and an Apple Silicon Mac. It is free and open source (MIT).
Next: see every dev server and port on your Mac or free a busy port.