Add option to disable or replace auto-compact per-session or per-invocation (headless, scripts, and skill loops)
Problem
When running Claude Code in non-interactive or looping contexts — e.g. CI pipelines, scheduled jobs, or long-running skill/tool loops — auto-compact fires automatically when the context window fills. For these use cases, context continuity is irrelevant: each iteration is independent and starts fresh anyway.
Auto-compact in this context:
- Burns tokens on a summary that will never be read
- Adds latency mid-run
- Can silently change behavior (compacted context ≠ original context)
There is also a related gap in interactive sessions running iterative loops: skills and hooks have no way to trigger /clear programmatically. They can't call slash commands mid-execution, so they can't reset context between iterations without terminating the session entirely. None of the headless-mode options below address this — the session is already live.
Requested Feature
A way to opt out of auto-compact, or replace it with a context clear, for specific invocations or session types. Proposed options (any one would solve the use case):
- CLI flag:
claude --no-auto-compact— disables auto-compact for the session; hits context limit → exits or clears instead - Settings key:
"autoCompact": falseinsettings.jsonorsettings.local.json, optionally scoped per-project - PreCompact hook abort: Allow the
PreCompacthook to return a non-zero exit code to cancel compaction (consistent with how other hooks work) autoCompactBehavior: "clear"setting — instead of summarizing, just wipe context and continue (equivalent to/clear)- Programmatic
/clearaccess for skills/hooks — aclearContext()function or equivalent in the skill/hook runtime, so iterative loops can reset context on demand without terminating the session
Use Cases
- CI/CD pipelines — deterministic, reproducible runs require consistent context state; auto-compact introduces non-determinism mid-job and adds latency overhead at scale
- Headless scheduled jobs — cron-triggered invocations have no user to read the compacted context; the summary is immediately discarded, burning tokens for nothing
- Evals and testing — reproducible eval runs require that context state at each step is predictable; auto-compact firing mid-run undermines this guarantee
- Interactive skill/tool loops — long-running loops inside live sessions need to reset context between iterations; currently impossible without killing the session
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗