Claude Desktop: scheduled-task/background `claude` CLI sessions never exit → memory exhaustion over 1–2 days
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
claudeCLI processes + 151Helpers/disclaimerwrappers + ~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
- Run Claude Desktop with several recurring scheduled tasks (a sub-hourly one accelerates it).
- Leave the app running 1–2 days without rebooting.
- 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
claude
Each leaked CLI process traces → Helpers/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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗