Feature request: configurable auto-compact token threshold via settings.json
Summary
Add a settings.json option (e.g. autoCompactThreshold) that triggers /compact automatically when the session's context reaches a user-specified token count, rather than relying solely on the built-in near-limit auto-compact.
Motivation
The current auto-compact fires reactively, very close to the model's context ceiling. For conversational / non-coding sessions — where compaction earlier and more often keeps responses snappier and costs lower — there's no way to trigger it proactively at a chosen threshold.
A hooks-based workaround is not feasible today because:
- Hooks (PreToolUse, PostToolUse, Stop) do not receive the current token count.
- Hooks cannot inject slash commands back into the session.
Proposed API
// settings.json (user or project scope)
{
"autoCompactThreshold": 120000 // compact when context reaches ~120K tokens
}
Alternatively, expose the current token count to hooks via a CLAUDE_CONTEXT_TOKENS env var or a context_tokens field in the hook stdin payload — that would let power users implement their own threshold logic in a Stop or PreToolUse hook.
Scope
- Applies to the main interactive session (not to spawned sub-agents, which have their own context windows).
- The threshold could also be session-type-aware (e.g., only apply in non-agentic / conversational sessions) if that distinction is useful, but a simple global knob would cover most needs.
Workaround today
None reliable. Character-count estimation from transcript files is too inaccurate (~20–30K token error margin) to be useful.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗