MCP plugin bun processes orphaned on unclean exit, peg CPU at 100% each
Bug Description
When Claude Code exits without properly shutting down child processes (terminal force-close, crash, kill -9, or macOS sleep/wake race), the bun MCP server processes spawned by plugins become orphans and spin at ~100% CPU each indefinitely.
Today I found 3 orphaned bun processes consuming 300% CPU total on my M4 MacBook, causing sustained max fan speed. They did not respond to SIGTERM and required SIGKILL.
Environment
- OS: macOS Darwin 25.4.0 (Apple M4)
- Claude Code: CLI (latest)
- Bun: 1.3.10
Affected Plugins
All plugins using bun as MCP transport:
telegram—bun run start→bun install && bun server.tsdiscord— same patternimessage— same patternfakechat— same pattern
Steps to Reproduce
- Start Claude Code with any bun-based MCP plugin enabled (e.g., Telegram)
- Force-close the terminal (Cmd+Q,
kill -9on Claude, or crash) - Observe orphaned
bunprocesses viaps -eo pid,pcpu,comm -r | head -10 - Each orphaned process uses ~100% CPU
Evidence
PID %CPU COMM
45437 100.2 /Users/.../.bun/bin/bun
15640 99.8 /Users/.../.bun/bin/bun
16121 99.7 /Users/.../.bun/bin/bun
kill <pids>— no effect, processes ignore SIGTERMkill -9 <pids>— terminates them, CPU returns to normal
Expected Behavior
MCP server child processes should terminate when Claude Code exits, regardless of exit type (clean, crash, force-kill).
Suggested Fixes
1. Process Group Cleanup
Launch MCP servers in a process group. On exit, SIGKILL the entire group:
setsid bun run server.ts &
trap 'kill -9 -$PGID' EXIT
2. MCP Server Self-Termination
Detect parent death via stdin close or ppid check:
process.stdin.on('end', () => process.exit(0));
// or
setInterval(() => {
try { process.kill(process.ppid, 0); }
catch { process.exit(0); }
}, 5000);
3. Stale Process Detection on Startup
On launch, scan for orphaned MCP bun processes from previous sessions and offer to kill them.
4. SIGTERM Handler
MCP servers should handle SIGTERM for graceful shutdown:
process.on('SIGTERM', () => { server.close(); process.exit(0); });
Impact
- CPU: 300% sustained (3/10 cores pegged)
- Thermal: Max fan speed, significant heat
- Battery: Major drain
- Discoverability: Zero — no notification or log. Only noticed via fan noise.
Workaround
# Find and kill orphaned bun processes
ps -eo pid,pcpu,comm -r | grep bun
kill -9 <pids>This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗