Claude Desktop: scheduled-task/background `claude` CLI sessions never exit → memory exhaustion over 1–2 days

Open 💬 1 comment Opened Jun 29, 2026 by retreatvr-alt

Summary

Headless claude CLI sessions spawned by Claude Desktop (macOS) for scheduled tasks / background agents do not terminate after their run completes or hangs. They accumulate indefinitely — one per scheduled fire — each retaining its full plugin + MCP-server stack in RAM. Over ~1–2 days of uptime on a 16 GB machine this exhausts memory and drives the system into a swap death-spiral.

Environment

  • Claude Desktop (macOS), CLAUDE_CODE_ENTRYPOINT=claude-desktop
  • Bundled Claude Code CLI 2.1.187, Agent SDK 0.3.187
  • Apple Silicon (M4), 16 GB RAM, macOS 26.2

Observed impact (real instance)

  • 151 leaked claude CLI processes + 151 Helpers/disclaimer wrappers + ~160 orphaned MCP children (context7-mcp, node, etc.).
  • Load average ~134 on a 10-core machine — processes blocked on swap I/O, not CPU-bound.
  • Swap ~19.8 GB / 20 GB used; ~900M swapins; system-wide free memory ~25%.
  • Oldest leaked session alive ~47 h (since previous boot). New leaked sessions appear on a steady cadence matching scheduled-task cron intervals.
  • Disk is not involved (plenty free). Purely process/memory accumulation.
  • Reboot fully resets it (count → 0, load → ~3), then it rebuilds over 1–2 days (~7 leaked sessions accumulated within 45 min of a fresh boot, with ~28 enabled scheduled tasks).

Repro

  1. Run Claude Desktop with several recurring scheduled tasks (a sub-hourly one accelerates it).
  2. Leave the app running 1–2 days without rebooting.
  3. Observe:

``
ps -Ao comm | sed -E 's|.*/||' | sort | uniq -c | sort -rn | head # hundreds of claude/disclaimer/context7-mcp/node
uptime # load average in the dozens-to-hundreds
sysctl vm.swapusage # swap near-full
`
Each leaked CLI process traces
claudeHelpers/disclaimer → the Desktop app, launched with --allow-dangerously-skip-permissions --permission-mode auto --disallowedTools AskUserQuestion`, and never exits.

Note for triage

Interactive and background sessions are indistinguishable by command-line flags and by environment (same entrypoint, both carry --allow-dangerously-skip-permissions/--permission-mode, sometimes --resume/--mcp-config), which makes safe external cleanup hard.

Expected

After a scheduled-task / background-agent run completes or times out, the claude CLI process and its MCP child processes should be torn down. Consider capping concurrent background sessions and adding an idle/hung-session timeout.

---
Filed by an affected user. Happy to provide process dumps, logs, or further detail on request.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗