MCP server processes not terminated when Claude Code session exits

Status Closed — duplicate
Maintainer reply None cached
Activity 3 comments · opened Jul 20, 2026 · closed Aug 19, 2026

Summary

When a Claude Code session ends (tab closed, \exit\, or crash), MCP server child processes are left running as orphans. On macOS, these accumulate across sessions and each consumes ~90% of a CPU core indefinitely.

Reproduction

  1. Configure any MCP server (e.g. \gitnexus\) in Claude Code settings
  2. Start N Claude Code sessions
  3. Close/exit all sessions
  4. Run \ps aux | grep mcp\ — observe N orphaned node processes still running at high CPU

Expected behavior

Claude Code should SIGTERM (and optionally SIGKILL after a grace period) all MCP server processes it spawned when the session exits cleanly or crashes.

Observed behavior

MCP server processes are never cleaned up. Over days of normal use, accumulated orphans consumed thousands of CPU-minutes each:

  • PID 35136 (started Thu) → 5664 CPU-minutes at ~90% CPU
  • PID 60526 (started Thu) → 5607 CPU-minutes at ~90% CPU
  • PID 94718 (started Fri) → 4545 CPU-minutes at ~90% CPU
  • 10 total processes, each pegging a full core

Environment

  • macOS Darwin 25.5.0 (Apple Silicon)
  • Claude Code CLI
  • MCP server: \gitnexus\ via \npx\

Workaround

Startup-time cleanup in the MCP wrapper script kills orphans before each new spawn. A launchd hourly job handles the case where no new session starts for extended periods.

View original on GitHub ↗

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