Add option to disable or replace auto-compact per-session or per-invocation (headless, scripts, and skill loops)

Open 💬 1 comment Opened Jun 15, 2026 by sabihismail

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):

  1. CLI flag: claude --no-auto-compact — disables auto-compact for the session; hits context limit → exits or clears instead
  2. Settings key: "autoCompact": false in settings.json or settings.local.json, optionally scoped per-project
  3. PreCompact hook abort: Allow the PreCompact hook to return a non-zero exit code to cancel compaction (consistent with how other hooks work)
  4. autoCompactBehavior: "clear" setting — instead of summarizing, just wipe context and continue (equivalent to /clear)
  5. Programmatic /clear access for skills/hooks — a clearContext() 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

View original on GitHub ↗

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