[FEATURE] Per-model configurable autocompact threshold
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
With the 1M context window now available for Opus, a single global CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is no longer sufficient. Different models benefit from different compaction strategies, and users need per-model control over when autocompact triggers.
Motivation
When using Opus (1M context) as the primary model that spawns Sonnet subagents, the optimal autocompact threshold differs significantly between them:
Use Case Example
- Opus (1M): I may want to compact at ~30% (300K tokens) to keep costs manageable and responses fast, since the full 1M window is rarely needed
- Sonnet subagents: I want them to use a larger portion of their context (e.g., 80-90%) since they handle focused, bounded tasks where more context is useful
Currently, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE applies globally — forcing a single trade-off that can't serve both use cases.
Proposed Solution
Allow per-model autocompact thresholds in settings.json:
{
"autoCompactThreshold": {
"default": 80,
"opus": 30,
"sonnet": 90,
"haiku": 95
}
}
Or alternatively, extend the environment variable approach:
CLAUDE_AUTOCOMPACT_PCT_OPUS=30
CLAUDE_AUTOCOMPACT_PCT_SONNET=90
CLAUDE_AUTOCOMPACT_PCT_HAIKU=95
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=80 # fallback default
Why Not Use the Existing Global Override
| Scenario | Global at 30% | Global at 90% |
|----------|---------------|---------------|
| Opus (1M) primary session | Good — keeps cost/latency down | Bad — consumes up to 900K tokens before compacting |
| Sonnet subagents | Bad — compacts too early, loses useful context for focused tasks | Good — maximizes available context |
There is no single value that works well for both.
Priority
High - Significant impact on productivity
Feature Category
Configuration and settings
Additional Context
Related Issues
- #28728 — Auto-compact should trigger earlier / threshold should be configurable
- #15719 — Configurable Context Window Compaction Threshold
- #15435 — Configurable autocompact buffer size
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗