Skip to content

MCP server processes not cleaned up on exit (orphan processes) + eagerly starts all servers #30123

Closed as not planned

Description

@chenyuan35

Bug Description

When OpenCode exits, MCP server child processes are not killed, leaving orphan processes running indefinitely. Additionally, OpenCode eagerly starts ALL configured stdio-type MCP servers at launch regardless of whether they will be used.

Impact

  • 30 orphan node.exe processes accumulated (from just 2 sessions), each consuming 45-75MB RAM
  • Total wasted memory: ~1.5GB
  • CPU fan noise due to unnecessary load

Root Cause

  1. Process tree: OpenCode -> cmd /c npx -y -> node(npx-cli.js) -> node(MCP server)
  2. When OpenCode exits, it does not cascade SIGTERM/kill to child processes
  3. The cmd /c wrapper exits early (by design of /c), making npx and MCP server orphans
  4. Windows does not auto-clean orphan processes — they run forever waiting on closed stdin

All MCP servers are started eagerly

Even if a session never uses avily, exa, memory, sequential-thinking, or context7, all of them are launched at startup. This wastes CPU and memory on every session.

Expected Behavior

  1. On exit: OpenCode should kill all spawned child processes (the entire process tree)
  2. On startup: MCP servers should be lazily started only when first needed (or at least have a config option for this)
  3. Alternatively: MCP servers should detect stdin EOF and exit themselves

Environment

  • Windows (Win32)
  • OpenCode (latest)
  • MCP servers launched via: \cmd /c npx -y @modelcontextprotocol/server-sequential-thinking\ (and similar)

Workaround

Users can manually kill orphan processes:
\\powershell
taskkill /f /im node.exe
\\

Or disable unused MCP servers in opencode.json to prevent them from starting.

Activity

  1. github-actions commented on May 31, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct (e.g., the eager startup behavior or the Windows-specific cmd /c process tree issue), please clarify what is not covered by the above issues.

  2. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions