[FEATURE] Give idle compactions their own trigger value ("idle")
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
An idle compaction ("Compacted while idle, before the prompt cache expired") is recorded with the same trigger as a compaction at the context threshold. Since 2.1.290 that is "auto", and before it was "manual" (#98747). In 2.1.296 the idle path calls the same compaction routine as /compact with no origin, so the routine sets trigger: "auto". The hooks reference lists only manual and auto as PreCompact and PostCompact matcher values.
So in compactMetadata and in PreCompact and PostCompact hook input, an idle compaction at 200K looks exactly like a threshold compaction:
- A PreCompact or PostCompact hook with matcher
auto, written for "the context is full", also fires when the session was merely idle. - Anything that models the threshold (a warning before compaction, a check that it fired where expected) can only tell the two apart by matching the notice text in the transcript. That text is a display string, not a contract.
- People who see
trigger: "auto"at a fraction of their window report it as a premature auto-compact bug (#100277).
Proposed Solution
Record idle compactions as trigger: "idle" in compactMetadata, pass the same value in PreCompact and PostCompact hook input, and accept idle as a matcher value for those events. The routine already takes a trigger other than manual and auto (in 2.1.296 it is passed "plugin" when a plugin starts the compaction), so this would be one more value, not a new mechanism.
Alternative Solutions
- Match the "Compacted while idle, before the prompt cache expired" notice in the transcript. This works on 2.1.296, but it breaks silently if the wording changes, and a PreCompact hook runs before the notice is written.
- Infer an idle compaction from the gap since the last response (about 54 minutes with the 1-hour cache). This is a heuristic, and it also catches a threshold compaction that follows a long pause.
Priority
Low - Nice to have
Feature Category
Developer tools/SDK
Use Case Example
A user-level hook warns the model as its context approaches the auto-compact threshold and raises an alarm when an automatic compaction lands far from the predicted point, since that suggests the threshold formula changed. On 2026-10-10 an idle session compacted twice, at 207,910 and 225,866 tokens with a 600K auto-compact window, and the alarm fired both times although nothing had changed. With trigger: "idle", the hook could skip the alarm without depending on the notice wording.
Additional Context
- Environment: Claude Code 2.1.296, macOS, Opus 5.5. Both compactions were recorded as
trigger: "auto", each came about 54 minutes after the last response, and the idle notice followed each one. - Related docs gap:
idleCompactionandCLAUDE_CODE_IDLE_COMPACT_MIN_TOKENSdon't appear on the settings, env-vars, hooks, prompt-caching, troubleshooting, context-window or costs pages, or in the changelog (checked 2026-10-10).autoCompactWindow,CLAUDE_AUTOCOMPACT_PCT_OVERRIDEandDISABLE_AUTO_COMPACTdo appear. - Related: #98747 (idle compaction and the
idleCompactionopt-out), #100277 (idle compaction reported as premature auto-compact), #66115 (the original idle-compaction request).