Summary
opencode run spawns MCP server processes (e.g., mcp-searxng, mcp-tavily, sequential-thinking, etc.) but does not terminate them when the run session exits. These processes get reparented to PID 1 and persist indefinitely, causing significant memory leaks over time.
Reproduction
- Configure MCP servers in
opencode.json (e.g., mcp-searxng)
- Run
opencode run "any prompt" — MCP servers are spawned as child processes
- After
opencode run completes and exits, check: ps -eo pid,ppid,args | grep mcp-searxng
- The MCP processes are still alive with PPID=1 (orphaned)
Impact
In a cron-based setup (e.g., heartbeat scripts calling opencode run every 30 minutes), orphaned MCP processes accumulate rapidly:
- Each
mcp-searxng process consumes ~61MB RSS
- ~90
opencode run invocations/day = ~5.5GB/day leaked
- Observed: 301 orphaned
mcp-searxng processes consuming ~18GB before manual cleanup
Environment
- OpenCode version: 1.3.0
- OS: Ubuntu 20.04 (ARM64, Oracle Cloud)
- MCP servers configured: searxng, tavily, sequential-thinking, zhipu-vision, github-search, websearch
Expected Behavior
opencode run should send SIGTERM to all spawned MCP child processes before exiting (or use a process group so they all terminate together).
Current Workaround
Cron script that periodically kills orphaned MCP processes (PPID=1):
#!/usr/bin/env bash
MCP_PATTERNS="mcp-searxng|mcp-tavily|sequential-thinking|github-search|zhipu-vision|websearch"
while IFS= read -r line; do
pid=$(echo "$line" | awk '{print $1}')
ppid=$(echo "$line" | awk '{print $2}')
[ "$ppid" = "1" ] && kill "$pid" 2>/dev/null
done < <(ps -eo pid,ppid,args | grep -E "$MCP_PATTERNS" | grep -v grep)
Summary
opencode runspawns MCP server processes (e.g.,mcp-searxng,mcp-tavily,sequential-thinking, etc.) but does not terminate them when the run session exits. These processes get reparented to PID 1 and persist indefinitely, causing significant memory leaks over time.Reproduction
opencode.json(e.g.,mcp-searxng)opencode run "any prompt"— MCP servers are spawned as child processesopencode runcompletes and exits, check:ps -eo pid,ppid,args | grep mcp-searxngImpact
In a cron-based setup (e.g., heartbeat scripts calling
opencode runevery 30 minutes), orphaned MCP processes accumulate rapidly:mcp-searxngprocess consumes ~61MB RSSopencode runinvocations/day = ~5.5GB/day leakedmcp-searxngprocesses consuming ~18GB before manual cleanupEnvironment
Expected Behavior
opencode runshould send SIGTERM to all spawned MCP child processes before exiting (or use a process group so they all terminate together).Current Workaround
Cron script that periodically kills orphaned MCP processes (PPID=1):