# 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.

Source: https://ai-garage.dev/blog/find-dev-servers-left-running-mac · Updated 2026-11-16 · Facts checked 2026-11-16 · By Az, maker of AI Garage

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 short:** Some of what your agent started may outlive the session, depending on the tool and on how the server was started. Check the agent's own list first, then every program listening on a port, then Node processes with no port. Stop leftovers one at a time, never all Node processes at once.

**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.

| Tool | Where to see what it started | What its docs say about the end of a session |
| --- | --- | --- |
| Claude Code | Type `/tasks` in the chat | Background tasks stop when you quit Claude Code. If you send the session to the background instead, they keep running. |
| Codex CLI | Type `/ps`; `/stop` stops them all | `/stop` covers the background terminals of the current session. The docs don't say what happens when you quit. |
| Cursor | The terminal where the agent ran the command | The 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:

**Prompt for your agent — Find leftovers, change nothing:**

```text
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 Terminal

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

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

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

```sh
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.

```sh
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.

```text
  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.

```sh
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).

```text
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 see | What it most likely means | What to do |
| --- | --- | --- |
| Your project folder, parent is 1, running since an old session | An orphan: nothing will stop it for you | Stop it, unless you still use that project |
| Your project folder, parent chain leads to your agent app | Owned by an open agent session | Stop 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 open | Started in that tab | Press Control-C there |
| A database, Docker or OrbStack | It may hold data | Stop it from its own app, or leave it |
| A folder or name you don't recognize | Could be anything | Leave 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.

## 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:

**Prompt for your agent — Close only the leftovers:**

```text
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.
```

> **Careful: Don't stop all Node processes at once.** A command like `killall node` stops every program named node, including ones you never started. On our test Mac, 24 of the 38 Node processes running at that moment were MCP servers, the small helpers that connect AI apps to outside tools. Stopping all Node processes would stop those too. Stop one PID at a time.

### Stop one leftover in Terminal

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

```sh
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](https://ai-garage.dev/blog/port-already-in-use-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.

**See every listening port, and which ones look like your agent's.** AI Garage is a free macOS panel we build. It shows all listening ports on your Mac in one window and marks the processes that look like dev servers started by AI agents, so leftovers stand out. Saved projects get Start, Stop and Restart buttons. Honest limits: which agent started a process is a guess based on its name, and processes that don't listen on a port aren't shown. Run `npx ai-garage` to try it.

## 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](https://code.claude.com/docs/en/interactive-mode#background-bash-commands)).
- Claude Code: `run_in_background`, `/tasks` and time limits for background commands ([code.claude.com](https://code.claude.com/docs/en/tools-reference#background-commands)).
- Claude Code: the `/tasks` command, also available as `/bashes` ([code.claude.com](https://code.claude.com/docs/en/commands)).
- OpenAI Codex CLI: `/ps` and `/stop` for background terminals ([developers.openai.com](https://developers.openai.com/codex/cli/slash-commands)).
- Cursor: how the agent runs terminal commands ([cursor.com](https://cursor.com/docs/agent/tools/terminal)).
- `lsof` manual: `-i`, `-sTCP:LISTEN`, `-a`, `-d cwd` and `+c` ([lsof-org/lsof](https://github.com/lsof-org/lsof/blob/master/Lsof.8)).
- macOS manual pages: `wait(2)` on orphaned children getting parent process 1 ([developer.apple.com](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/wait.2.html)); `_exit(2)`, `ps(1)` (ELAPSED, RSS, zombies) and `launchd(8)`, read with `man` on macOS 15.7.4.
