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

  1. Create .mcp.json with any MCP server (e.g. a trivial bun/node script)
  2. Run claude -p "say hello" --output-format json
  3. Session completes and exits
  4. The MCP server child process is still alive (ps aux | grep bun)
  5. 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-config does NOT prevent this — it only suppresses mcpServers from 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗