Localhost · Ports, dev servers and previews on your Mac

AI Agent Left Dev Servers Running? Find Them on Your Mac

A checklist for after a Claude Code, Codex or Cursor session: find background Node processes and dev servers still running on your Mac, stop them one by one.

Illustration: three small robots asleep on a workshop shelf with their status lights still on
Using an AI agent?View as MarkdownOpen in ClaudeOpen in ChatGPT

You spent the afternoon building with Claude Code, Codex or Cursor. The agent started a dev server so you could see the preview, maybe a second one for the API, and something that rebuilds files whenever they change. You closed the chat and moved on.

The next day localhost:3000 shows an old project, or a new server can't start because the port is taken. Something from yesterday is still running, and nothing on the screen tells you what.

In this checklist:

  • What Claude Code, Codex and Cursor say about servers their agents start.
  • A request for your agent that finds leftovers and changes nothing.
  • How to tell a forgotten server from something your Mac needs, and close it safely.

Does a dev server stop when the agent session ends?

Sometimes. It depends on the tool and on how the agent started the server, so check instead of assuming.

ToolWhere to see what it startedWhat its docs say about the end of a session
Claude CodeType /tasks in the chatBackground tasks stop when you quit Claude Code. If you send the session to the background instead, they keep running.
Codex CLIType /ps; /stop stops them all/stop covers the background terminals of the current session. The docs don't say what happens when you quit.
CursorThe terminal where the agent ran the commandThe agent runs commands in your terminal. The docs don't say what happens to a server when the chat ends.

While a Claude Code session stays open on your Mac, its background commands have no time limit, so a server from the morning can still be up at night. Codex notes that /ps may show nothing, depending on how it runs commands.

The agent's own list can also miss things. Every program on a Mac has a number, its PID, and a parent: the program that started it. A server can be started so that it cuts loose from whatever launched it. We tried this on our test Mac from inside a Claude Code session: the server kept running after the command that started it had finished, and its parent became process 1. That's an orphan. When a parent exits first, macOS hands its children to process 1, launchd, the system's own process manager.

What should you check after an agent session?

Five things, in this order:

  1. Ask the agent what it still has running. Its own list shows what it started in this session, and it can stop those for you.
  2. List every program listening on a port. These are the servers you could open in a browser, and the usual cause of "port already in use".
  3. Find the folder each one runs from. The folder tells you which project it belongs to, which the program name often doesn't.
  4. Look for Node processes without a port. File watchers, build tools and test runners can keep running without ever showing up in the port list.
  5. Check the age and the parent of each one. A process running since yesterday whose parent is gone is very likely a leftover.

The easiest way is to hand the whole checklist to your coding assistant:

Give this to your agent · Find leftovers, change nothing

Find what may be left over from my coding sessions on this Mac: background tasks you started in this session, every process listening on a TCP port, and Node.js processes without a port. For each, show PID, parent PID, running time, memory, full command and folder. Group them into my projects, apps and system, unknown, and mark likely leftovers with a reason. Hide anything that looks like a key, token or password. Only look: don't stop, restart or change anything. Wait for my decision.

The last two sentences matter. Without them, an assistant may start cleaning up right away.

The same checklist in Terminalfor you or your agent

1. Everything listening on a port. +c 0 prints full program names; by default lsof cuts them to 9 characters.

lsof +c 0 -nP -iTCP -sTCP:LISTEN

2. The folder of one process. Replace 68901 with a PID from step 1.

lsof -a -p 68901 -d cwd

3. Node processes, with or without a port. ELAPSED is how long it has run, RSS is memory in kilobytes, PPID is the parent.

ps -o pid,ppid,etime,rss,command -p "$(pgrep -d, -f 'node|next-server|vite')"

Our test: a server on port 4499 and a process with no port, both started from a shell that had already exited.

  PID  PPID ELAPSED    RSS COMMAND
68901     1   01:04  34464 node -e … ag-demo-server
68903     1   01:04  32608 node -e … ag-demo-watcher

pgrep -f matches the whole command line, so apps that merely mention node can appear too. Next.js dev servers show up as next-server. If you see “Invalid (zero-length) process id”, no Node processes are running.

4. Who started it. Walks up the parent chain to process 1.

pid=68901; while [ "$pid" -gt 1 ]; do ps -o pid=,ppid=,etime=,comm= -p "$pid"; pid=$(ps -o ppid= -p "$pid" | tr -d ' '); done

How a server cuts loose: nohup <command> & keeps it running after the shell that started it exits. That is how our test orphans above were made.

Our test: a server Claude Code started as a background task, traced back to the Claude app (paths shortened).

74915 74914 00:03 node
74914 40074 00:04 /bin/zsh
40074 40073 09:35 …/Claude/claude-code/2.1.325/…
40073  2035 09:35 …/Claude.app/Contents/Helpers/disclaimer
 2035     1 08:52:22 /Applications/Claude.app/Contents/MacOS/Claude

Which ones did your agent leave behind?

The folder answers most of it. A process running from one of your project folders is yours. One running from a system folder or from inside an app belongs to macOS or that app, so leave it alone.

What you seeWhat it most likely meansWhat to do
Your project folder, parent is 1, running since an old sessionAn orphan: nothing will stop it for youStop it, unless you still use that project
Your project folder, parent chain leads to your agent appOwned by an open agent sessionStop it from the agent. Quitting Claude Code also stops its background tasks; after closing Codex or Cursor, check again
Your project folder, parent is a Terminal tab you have openStarted in that tabPress Control-C there
A database, Docker or OrbStackIt may hold dataStop it from its own app, or leave it
A folder or name you don't recognizeCould be anythingLeave it until you know

Parent 1 on its own proves little. Every app you open from the Dock has it too: when we checked, 323 processes on our test Mac had parent 1, Finder among them. Read it together with the folder.

Names mislead as well. On our test Mac, a Next.js server appeared as node in the port list and as next-server in the process list, and a server started with python3 showed up as Python.

Leftovers are often called zombies. In Unix terms, a zombie has already exited and only waits for its parent to notice it ended, so it can't hold a port. You're after orphans and forgotten servers, which still run.

Coming nextOpen a Localhost Project on Your Phone: Wi-Fi, USB or Tunnel?

How do you close the leftovers safely?

Close each one where it was started, if that place still exists: /tasks in Claude Code, /stop in Codex (it closes all of the session's background terminals at once), or Control-C in the Terminal tab that runs it.

An orphan has nowhere left to close it from, so stop that one process by its PID with a normal stop. Your assistant can do it:

Give this to your agent · Close only the leftovers

Stop only these processes: [PIDs or folders you picked]. Right before stopping each one, check that the PID still has the same command and folder. Use a normal stop (SIGTERM), not a force kill, and don't use killall or pkill. If one of them is a background task in your own session, stop it there instead. Then list the listening ports again and tell me if anything came back.

Stop one leftover in Terminalfor you or your agent

Check the PID again first, because numbers get reused. Then send a normal stop and confirm it's gone (use your PID and port):

kill -TERM 68901
ps -o pid=,command= -p 68901
lsof -nP -iTCP:4499 -sTCP:LISTEN

Both checks print nothing once it has stopped. Use kill -KILL only for a process you've identified that ignores the normal stop, since it skips any cleanup.

Prefer a window? Our guide to port 3000 already in use on Mac shows how to quit a process by its PID in Activity Monitor.

What if a Node process keeps running after you stop it?

Then something starts it again: a process manager such as pm2 (a tool that restarts servers), a file watcher, a macOS launch agent (a background job that starts at login), a Run task in your editor, a keep-alive setting, or the agent itself. Follow the parent chain, turn the restart off where it's set up, then stop the server once. The port guide walks through a real chain.

How do you stop this from piling up?

Make the agent account for what it starts:

  • Ask it to start servers as background tasks it can list later, and to tell you each port and folder.
  • Before you close a session, ask it to stop what it started and confirm the ports are free.

When you run several projects every day

Terminal and a careful prompt are enough for an occasional cleanup. If your agents start servers every day, it helps to see all listening ports on one screen.

Sources

Checked on November 16, 2026. Commands were run on macOS 15.7.4 with Node.js 24.11; the agent test ran inside Claude Code 2.1.325.

  • Claude Code: background Bash commands, cleanup when Claude Code exits, background sessions (code.claude.com).
  • Claude Code: run_in_background, /tasks and time limits for background commands (code.claude.com).
  • Claude Code: the /tasks command, also available as /bashes (code.claude.com).
  • OpenAI Codex CLI: /ps and /stop for background terminals (developers.openai.com).
  • Cursor: how the agent runs terminal commands (cursor.com).
  • lsof manual: -i, -sTCP:LISTEN, -a, -d cwd and +c (lsof-org/lsof).
  • macOS manual pages: wait(2) on orphaned children getting parent process 1 (developer.apple.com); _exit(2), ps(1) (ELAPSED, RSS, zombies) and launchd(8), read with man on macOS 15.7.4.

Next up:Port 3000 Already in Use on Mac? Find the Project Behind It

Explore more:LocalhostMCP, simplySecurity

More on your setup

swipe sideways
MCP, simplySoon
Where Each AI Client Stores Its MCP Config (and How to Add a Server)
Config paths for every client, with the date we checked.
SecuritySoon
Stop Pasting API Keys Into AI Chats: Safer Ways to Get a Secret Into .env
A setup where the key never passes through the chat.
LocalhostSoon
Open a Localhost Project on Your Phone: Wi-Fi, USB or Tunnel?
Same network, cable or tunnel: pick the right way in one minute.
Top picksSoon
ngrok Alternatives for Local Dev on Mac
Cloudflare Tunnel, Tailscale and others in one honest table.
MCP, simplySoon
Use One Skill in Claude Code and Codex
One skill folder that works for two agents.
LocalhostSoon
What Is Localhost, and Why localhost:3000 Shows the Wrong Project
Localhost in plain words, plus the wrong-project case.

Essentials

Five guides to read first
1
Localhost7 min read
Port 3000 Already in Use on Mac? Find the Project Behind It
Find which project is using port 3000 on your Mac, decide whether to keep it running, and get your app preview working again — without killing your browser.
2
MCP, simplySoon
Where Each AI Client Stores Its MCP Config (and How to Add a Server)
Config paths for every client, with the date we checked.
3
SecuritySoon
Stop Pasting API Keys Into AI Chats: Safer Ways to Get a Secret Into .env
A setup where the key never passes through the chat.
4
LocalhostSoon
Open a Localhost Project on Your Phone: Wi-Fi, USB or Tunnel?
Same network, cable or tunnel: pick the right way in one minute.
5
Top picksSoon
ngrok Alternatives for Local Dev on Mac
Cloudflare Tunnel, Tailscale and others in one honest table.