Feature: configurable context compaction threshold (e.g. compact_at_percent: 66)
Summary
Add a configurable threshold that triggers /compact automatically when context usage reaches a specified percentage of the context window, rather than waiting until near 100%.
Use Case
Currently, automatic compaction only fires when the context window is nearly full. By that point, context quality has already degraded. Many users want to proactively compact at a lower threshold (e.g. 66%) to keep response quality consistently high throughout a session.
There is no way to implement this today - there is no hook event that exposes current context usage, and no settings.json option to configure a threshold.
Proposed API
In settings.json:
\\\json\
{
"compactAtPercent": 66
}
\\
Or per-project in .claude/settings.json:
\\\json\
{
"compactAtPercent": 80
}
\\
When context usage reaches the threshold, Claude Code would automatically trigger the same compaction behaviour as /compact.
Alternatives Considered
- Rule-based soft enforcement (telling Claude to suggest /compact at 70%) - works but relies on Claude noticing, not a hard system-level trigger
- Hooks - no context usage variable is available to hook scripts, so this can't be implemented via hooks today
Impact
- More consistent response quality across long sessions
- User control over the quality/continuity tradeoff
- Enables workflows where context hygiene is critical (large codebases, multi-hour sessions)
---
Submitted via Claude Code session
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗