MCP server child processes not killed when pipe-mode (-p) session exits
Resolved 💬 3 comments Opened Mar 30, 2026 by irudkevich Closed Apr 3, 2026
MCP servers declared in .mcp.json spawn child processes (e.g. bun, node) that are not terminated when a -p (print/pipe mode) session completes. Each headless session leaves orphan processes that accumulate until OOM.
Repro
- Create
.mcp.jsonwith any MCP server (e.g. a trivial bun/node script) - Run
claude -p "say hello" --output-format json - Session completes and exits
- The MCP server child process is still alive (
ps aux | grep bun) - Repeat N times → N orphan processes
Impact
Any automation that spawns repeated -p sessions (CI, daemons, batch jobs) leaks one MCP server process per invocation. We hit OOM at ~236 sessions (~9.4GB of orphan bun processes).
Workaround
Use --mcp-config empty.json (where empty.json is {"mcpServers": {}}) for pipe-mode sessions that don't need MCP tools.
Notes
--strict-mcp-configdoes NOT prevent this — it only suppressesmcpServersfrom the global config, not from the project-level.mcp.json.- Plugin child processes have the same issue (previously reported/worked around by disabling plugins via
--settings).
Environment
- Claude Code 2.1.81
- macOS Darwin 25.3.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗