Skip to content

claude -p leaves orphaned MCP child processes after exit #42881

Closed as duplicate

Description

@NinoDja

Bug

When claude -p (non-interactive/programmatic mode) finishes execution, the CLI node.exe process exits but all MCP server child processes remain alive as orphans. They are never cleaned up.

Reproduction

# Count node.exe processes before
powershell -Command "(Get-Process node -EA Silent).Count"

# Run a simple prompt with MCP config
claude -p "respond with OK" --mcp-config mcp-config.json --strict-mcp-config

# Count after — orphaned MCP processes remain
powershell -Command "(Get-Process node -EA Silent).Count"

The delta shows MCP servers (node.exe, python.exe) that were spawned by the CLI but never terminated.

Impact

In automated setups using Task Scheduler / cron with claude -p, each execution leaves 2-5 orphaned MCP processes (~80 MB each). With 4-6 scheduled runs per day, this accumulates to 10-30 zombie processes and ~1-2 GB of wasted RAM daily.

Environment

  • Windows 11 Pro
  • Claude Code 2.1.91
  • MCPs configured via --mcp-config with --strict-mcp-config

Expected behavior

When claude -p exits, it should terminate all MCP child processes it spawned (e.g., via process tree kill or Job Object on Windows, process group kill on Linux/macOS).

Current workaround

A scheduled PowerShell script (mcp-health-check.ps1) runs every 30 minutes: finds all active Claude CLI processes, walks their descendant trees, identifies MCP-pattern processes not descended from any living CLI, and kills them.

🤖 Generated with Claude Code

Activity

  1. github-actions commented on Apr 3, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. MCP server child processes not killed when pipe-mode (-p) session exits #40927
    2. [BUG] MCP server and subagent processes not cleaned up on session end — orphan accumulation (macOS PPID=1) #33947
    3. Windows: MCP server processes not terminated when scheduled/cron sessions end #39922

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. added
    duplicateThis issue or pull request already exists
    and removed
    bugSomething isn't working
    has reproHas detailed reproduction steps
    platform:windowsIssue specifically occurs on Windows
    on Apr 6, 2026
  3. github-actions commented on Apr 6, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #40927.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  4. github-actions commented on Apr 14, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions