Stop your AI agent from starting a second dev server

Updated · 2 min read

Ask Claude Code, Cursor or Codex to check a page, and many will run npm run dev themselves. If your server already runs on 3000, the new one moves to 3001. The agent tests 3001, you look at 3000, and after a few sessions there are servers on 3002 and 3003 that nobody stops. Agents that work on several copies of a project at once make it worse.

Tell the agent what already runs

Put it in the project's instructions: CLAUDE.md for Claude Code, AGENTS.md for Codex and others, the rules file for Cursor.

markdown
The dev server already runs at http://localhost:3000. Don't start another one.
If it isn't running, ask me to start it.

That helps. The agent still can't tell whether the server is up, which port it's on, or what it printed when it broke, so it reaches for npm run dev again when something looks off.

Make a second copy fail

A server with a fixed port stops instead of moving, so a second copy can't appear on 3001 unnoticed. For Next.js, next dev -p 3000; for Vite, strictPort: true. See Next.js or Vite started on the wrong port.

Clean up after a session

bash
lsof -nP -iTCP -sTCP:LISTEN | grep -E '^(node|bun|deno|python)'

lists what's still running. More in See every dev server running on your Mac.

How Portroom handles itPRO

Give the agent the servers you already run

Portroom has an MCP server built in. Connected once, the agent asks Portroom instead of guessing: which projects there are and on which ports, start, stop or restart one, read its log, get its current errors with stack traces. It works with the servers in your window, so no second copy turns up on 3001.

The agent can’t change a project’s folder, command or variables, and can’t delete anything.

bash
claude mcp add portroom --scope user -- /Applications/Portroom.app/Contents/Resources/portroom mcp
Settings ▸ MCP in Portroom: the MCP server on, Claude Code connected, setup commands to copySettings ▸ MCP in Portroom: the MCP server on, Claude Code connected, setup commands to copy

Part of Pro, $49 once. Portroom starts with 14 days of Pro, so you can try it first.

Something wrong or out of date on this page? Write to support@portroom.dev.

More guides

Every dev server on your Mac, in one window.

Free for three servers at once, with 14 days of Pro first. No account.