Feature Request: autoCompactThreshold setting — auto-trigger /compact before context window is full
Problem
In multi-worker cowork setups (multiple Claude Code sessions working in parallel on the same repo), sessions regularly reach 100% context window. At that point, /compact itself fails — there is no context space left for the compaction operation to execute. This creates a hard deadlock requiring manual intervention to recover the session.
Requested Feature
Add an autoCompactThreshold setting to settings.json that automatically triggers compaction when the context window reaches a configurable percentage, while there is still enough space left for the compact operation to complete:
\\\json\
{
"autoCompactThreshold": 0.75
}
\\
A threshold of 0.75–0.80 would trigger compaction at 75–80% usage, leaving sufficient buffer for the compact operation itself.
Why Current Workarounds Don't Work
- Hooks (PreToolUse/PostToolUse): Hooks execute shell commands, but
/compactis a user slash-command — it cannot be triggered programmatically from a hook. - CronCreate / scheduled tasks: Same limitation — no programmatic access to slash-commands.
- Manual
/compact: Works if the user notices and acts early enough, but in long autonomous sessions this is easy to miss.
Impact
- Affects all long-running autonomous sessions (agents, multi-worker setups)
- The 100% → deadlock pattern occurs daily in sessions with large codebases and extensive context (CLAUDE.md, multiple worktrees, parallel agents)
- No graceful recovery path exists once the deadlock is reached
Environment
- Claude Code version: 2.1.153
- Platform: macOS (darwin 25.5.0)
- Multi-worker setup: 4–5 parallel sessions per repo
🤖 Submitted via Claude Code
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗