MCP plugin bun processes orphaned on unclean exit, peg CPU at 100% each

Resolved 💬 3 comments Opened Mar 26, 2026 by bnishit Closed Mar 29, 2026

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:

  • telegrambun run startbun install && bun server.ts
  • discord — same pattern
  • imessage — same pattern
  • fakechat — same pattern

Steps to Reproduce

  1. Start Claude Code with any bun-based MCP plugin enabled (e.g., Telegram)
  2. Force-close the terminal (Cmd+Q, kill -9 on Claude, or crash)
  3. Observe orphaned bun processes via ps -eo pid,pcpu,comm -r | head -10
  4. 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 SIGTERM
  • kill -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>

View original on GitHub ↗

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