claude-code - 💡(How to fix) Fix [BUG] CronCreate: lacks predicate-gated execution and context isolation, leading to large unintended costs on repeated trivial checks [1 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#54156Fetched 2026-04-29 06:34:48
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×5unlabeled ×1

Error Message

No error or exception — the tool works as implemented. The problem is the cost structure and the absence of a warning about it. Observed figures from a real session:

Configuration: cron="7,18,29,40,51 * * * *" (every ~11 min), recurring=True, durable=False ~88 fires over ~16 hours of an active session, each producing a single-line "inbox empty" response New work output per fire: one ls tool call + ~30 output tokens Input cost per fire grew with each fire because every prior fire's prompt-and-response was appended to the session history The 88 turns of no-signal output dominated the session's token cost and made context compaction fire repeatedly

Root Cause

Configuration: cron="7,18,29,40,51 * * * *" (every ~11 min), recurring=True, durable=False ~88 fires over ~16 hours of an active session, each producing a single-line "inbox empty" response New work output per fire: one ls tool call + ~30 output tokens Input cost per fire grew with each fire because every prior fire's prompt-and-response was appended to the session history The 88 turns of no-signal output dominated the session's token cost and made context compaction fire repeatedly

Code Example

No error or exception — the tool works as implemented. The problem is the cost structure and the absence of a warning about it. Observed figures from a real session:

Configuration: cron="7,18,29,40,51 * * * *" (every ~11 min), recurring=True, durable=False
~88 fires over ~16 hours of an active session, each producing a single-line "inbox empty" response
New work output per fire: one ls tool call + ~30 output tokens
Input cost per fire grew with each fire because every prior fire's prompt-and-response was appended to the session history
The 88 turns of no-signal output dominated the session's token cost and made context compaction fire repeatedly
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

CronCreate fires its prompt as a regular turn in the current Claude session. Every fire re-loads the full session context — system prompt, all in-scope CLAUDE.md files, and the entire prior conversation transcript — regardless of how trivial the prompt is. For a repeated low-information check (e.g., "is this directory empty?"), the dominant cost per fire is not the work itself but the conversation history that must be re-read by the model, which itself grows with every fire that gets appended to it. The cost-per-fire is roughly quadratic in the number of fires over a session's life, even when every fire is a no-op.

The tool's docstring frames CronCreate as a lightweight scheduling primitive and uses */5 * * * * (every 5 min) as its first example, with no mention of this cost structure. The framing is misleading: "session-only" + "every 5 min" reads as cheap; in practice it is the most expensive combination possible.

Claude Code Version

2.1.116

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

No response

What Should Happen?

wo improvements would fix this:

  1. Predicate-gated execution — an optional condition field the scheduler evaluates (without invoking the model) before deciding whether to enqueue the prompt. Only when the predicate is true does the model get called.

CronCreate( cron="*/5 * * * *", condition="ls agent_inbox/ | grep -v '^archive$\|^README.md$' | grep -q .", prompt="New files in agent_inbox/. Read them and propose handling.", ) Predicate types worth supporting: shell command (exit 0 = true), file-existence / file-mtime tests, HTTP webhook, inotify-style filesystem event.

  1. Context isolation — an isolated_context: bool flag. When true, the prompt fires in a fresh sub-context (system prompt + cron prompt only, not the parent session's accumulated history). This is exactly the pattern the Agent tool already uses. A sensible default for recurring=True cron jobs would be isolated_context=True.

Until predicate-gating and isolation exist, the docstring should at minimum warn:

"Each fire is a full Claude turn that re-loads the host session's context. For frequently-firing repeated checks (every few minutes), strongly prefer OS-level cron / inotify / shell scripts; CronCreate's recurring mode is best suited to less-frequent (hourly or coarser) substantive tasks where the host session's context is genuinely needed."

Error Messages/Logs

No error or exception — the tool works as implemented. The problem is the cost structure and the absence of a warning about it. Observed figures from a real session:

Configuration: cron="7,18,29,40,51 * * * *" (every ~11 min), recurring=True, durable=False
~88 fires over ~16 hours of an active session, each producing a single-line "inbox empty" response
New work output per fire: one ls tool call + ~30 output tokens
Input cost per fire grew with each fire because every prior fire's prompt-and-response was appended to the session history
The 88 turns of no-signal output dominated the session's token cost and made context compaction fire repeatedly

Steps to Reproduce

Open a Claude Code session that is already doing substantive work (so the context is non-trivial).

Create a recurring cron to poll an empty directory:

CronCreate( cron="7,18,29,40,51 * * * *", prompt="Run ls agent_inbox/. If empty, respond 'inbox empty'. Otherwise list files.", recurring=True, durable=False, ) Leave the session running for several hours while doing other work in the same session.

Observe:

Each cron fire appends a full prompt+response turn to the session history. Input token count per fire increases with each successive fire. After ~20–30 fires the session history is dominated by repetitive "inbox empty" turns. Context compaction begins triggering even though the substantive conversation hasn't grown that much. Compare with a shell watcher that uses inotifywait or a polling script with an early-exit: the shell approach pays zero model cost on negative checks.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.150

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

No response

extent analysis

TL;DR

To mitigate the high cost of frequent CronCreate fires, consider using an OS-level cron job or shell script for low-information checks instead of relying on Claude Code's CronCreate with recurring mode.

Guidance

  • Evaluate the necessity of using CronCreate for frequent, low-information checks and consider alternatives like OS-level cron jobs or shell scripts that can perform these tasks more efficiently.
  • If using CronCreate is necessary, be aware of the cost structure and the impact of frequent fires on the session history and context compaction.
  • Monitor the session history and input token count to understand the performance implications of using CronCreate with recurring mode.
  • Consider the proposed improvements to CronCreate, such as predicate-gated execution and context isolation, which could help mitigate the current cost structure issues.

Example

No code snippet is provided as the issue is more related to the usage and understanding of the CronCreate feature rather than a specific code problem.

Notes

The current implementation of CronCreate may not be suitable for frequent, low-information checks due to its cost structure. The proposed improvements, if implemented, could help alleviate these issues. However, without these improvements, users should be cautious when using CronCreate with recurring mode for such tasks.

Recommendation

Apply workaround: Use OS-level cron jobs or shell scripts for frequent, low-information checks to avoid the high cost associated with CronCreate's current implementation. This approach can help mitigate the performance issues until the proposed improvements to CronCreate are available.

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 [BUG] CronCreate: lacks predicate-gated execution and context isolation, leading to large unintended costs on repeated trivial checks [1 participants]