claude-code - 💡(How to fix) Fix Scheduled-task cron fires leak Claude Code processes + API session state [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#57910Fetched 2026-05-11 03:22:12
View on GitHub
Comments
2
Participants
2
Timeline
11
Reactions
0
Timeline (top)
labeled ×5cross-referenced ×3commented ×2closed ×1

Each cron-triggered scheduled-task fire spawns a new Claude Code process that never exits after the task completes. Over hours these accumulate, holding local RAM and active Anthropic API session state that bills against the account. On 10 May 2026 I discovered 78 orphan processes consuming 5.6 GB of RAM on a single laptop, accumulated over a few hours of normal scheduled-task operation. Account-level token usage continued to drain ~2% even after the local cleanup was visible — suggesting server-side sessions remain billed.

Root Cause

Each cron-triggered scheduled-task fire spawns a new Claude Code process that never exits after the task completes. Over hours these accumulate, holding local RAM and active Anthropic API session state that bills against the account. On 10 May 2026 I discovered 78 orphan processes consuming 5.6 GB of RAM on a single laptop, accumulated over a few hours of normal scheduled-task operation. Account-level token usage continued to drain ~2% even after the local cleanup was visible — suggesting server-side sessions remain billed.

Fix Action

Fix / Workaround

Workaround in place

I built a Bash sweeper that kills orphan processes (no --resume flag, age >10 min) and runs 3×/day via another scheduled task. Happy to share the script. This is patching a real bug — please prioritise the upstream fix.

Code Example

ps -eo pid,etime,command | grep 'claude.app/Contents/MacOS/claude' | grep -v -- '--resume'
RAW_BUFFERClick to expand / collapse

Summary

Each cron-triggered scheduled-task fire spawns a new Claude Code process that never exits after the task completes. Over hours these accumulate, holding local RAM and active Anthropic API session state that bills against the account. On 10 May 2026 I discovered 78 orphan processes consuming 5.6 GB of RAM on a single laptop, accumulated over a few hours of normal scheduled-task operation. Account-level token usage continued to drain ~2% even after the local cleanup was visible — suggesting server-side sessions remain billed.

Reproduction

  1. Create a scheduled task via the mcp__scheduled-tasks__create_scheduled_task MCP with a frequent cron (e.g. */5 * * * *)
  2. Let it run for an hour without quitting Claude Code
  3. Inspect:
    ps -eo pid,etime,command | grep 'claude.app/Contents/MacOS/claude' | grep -v -- '--resume'
    You will see many orphan claude processes, paired by start time (parent + child), with no --resume flag. Each is the residue of one cron fire.

Observed pattern

  • Each fire produces a pair of processes (parent + child) holding ~70 MB RAM
  • Process count grows linearly with (cron_frequency × time_since_quit)
  • API session state appears to remain active on the server side (visible in account usage)
  • Killing the orphan PIDs locally reclaims memory but cannot recover the already-billed tokens

Expected behaviour

A scheduled-task fire should: spawn process → run task → exit cleanly, releasing both the local process and the server-side API session.

Impact

  • 78 orphan processes / 5.6 GB RAM on one laptop
  • ~150 MB of accumulated JSONL session files written to disk in a single day
  • Visible 2%+ account token drain continuing after user reported the issue
  • iMessage plugin reuses one session ID indefinitely — accumulated to 40 MB over 10 days, replayed in full on every incoming text

Workaround in place

I built a Bash sweeper that kills orphan processes (no --resume flag, age >10 min) and runs 3×/day via another scheduled task. Happy to share the script. This is patching a real bug — please prioritise the upstream fix.

Suggested fix

The scheduled-task runner should:

  • Wait for the spawned Claude process to exit after task completion
  • If the process hasn't exited within N seconds of task completion, SIGTERM it
  • Confirm server-side that the API session is closed

Environment

  • macOS Sonoma 14.x, Apple Silicon
  • Claude Code 2.1.128
  • ~30 scheduled tasks defined; ~6 active
  • Plugins: telegram, imessage, oh-my-claudecode, chrome-devtools-mcp, and others
  • permission-mode: bypassPermissions set globally

Related

Separate-but-related: the iMessage plugin (~/.claude/plugins/cache/claude-plugins-official/imessage/0.1.0) reuses one session ID indefinitely. Over 10 days that session accumulated to 40 MB and was replayed in full on every incoming text. Worth auditing other long-running plugin servers (telegram, etc.) for the same pattern.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Scheduled-task cron fires leak Claude Code processes + API session state [2 comments, 2 participants]