[Feature] Proactive /compact at configurable context threshold to prevent hard "context full" crashes
Summary
When running long, tool-heavy sessions (bulk file reads, multiple subagents), context can fill to 100% faster than auto-compact can reclaim space. At that point, /compact becomes unresponsive and the user is forced to manually restart the session, losing in-flight work.
Request: Allow configuring a proactive compact threshold (e.g., 15% remaining) that triggers a full /compact cycle before the context becomes irrecoverable.
Use Case
Reading 151 template files across a codebase audit — each file read consumes context, subagent outputs return large results, and the session hit "context full" twice. The only recovery was manually copying the /compact summary into a new session.
Key pain points:
- No warning: Context went from usable to "full" with no actionable alert
- Auto-compact insufficient: Built-in compaction couldn't keep up with the volume of tool results
- /compact failed at 100%: Once full, /compact itself couldn't execute
- Subagent outputs are large: Background agents return full results that spike context usage
Proposed Behavior
// In .claude/settings.json
{
"compactThreshold": 0.15,
"compactWarningThreshold": 0.25
}
- At
compactWarningThreshold→ show persistent banner: "Context at 75% — consider running /compact" - At
compactThreshold→ auto-run /compact (or prompt user to confirm) - Never let context reach the irrecoverable 100% state
Workarounds Currently Used
- Writing findings to persistent memory files as work progresses (survives session restarts)
- Manually running /compact after each major milestone
- Breaking large tasks into smaller sessions
Related Issues
- #5720 — Warning before auto-compact (similar direction, but no configurable threshold)
- #16209 — Context full with subagents, /compact unresponsive (describes the exact failure mode)
- #42 — Original auto-compact request
Environment
- Claude Code on macOS (Darwin 24.6.0)
- Model: claude-opus-4-6
- Session type: Heavy tool use (150+ file reads, 6 background agents, persistent memory writes)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗