You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scripts/hooks/suggest-compact.js currently triggers purely on cumulative tool-call count (first at COMPACT_THRESHOLD/50, then every 25). Tool count is a weak proxy for actual window pressure, and adding a context-size signal would make the suggestion fire when it actually matters.
Why tool count alone is weak
A few large operations (big file reads, large MCP tool responses) can fill a large fraction of the window in very few tool calls — the count signal stays silent.
Conversely, many tiny calls can cross 50 while the window is barely used — it nags early.
In MCP/Bash-heavy sessions the count climbs without reflecting real context growth.
Proposal
Add a second (primary) signal based on the real context size, read from the latest assistant turn's usage in the session transcript. transcript_path is already provided in the PreToolUse hook stdin payload.
Sum input_tokens + cache_read_input_tokens + cache_creation_input_tokens from the most recent usage record (these three partition the prompt, so the sum is the true context size of the turn).
Compare to a window-scaled threshold (e.g. 250k on a 1M-context model, 160k on a 200k window; env-overridable), and re-remind every +N tokens (e.g. 60k).
Detect the window: treat as 1M if the model id carries a [1m] marker, or if observed tokens already exceed 200k (covers logs that drop the suffix); else 200k.
Summary
scripts/hooks/suggest-compact.jscurrently triggers purely on cumulative tool-call count (first atCOMPACT_THRESHOLD/50, then every 25). Tool count is a weak proxy for actual window pressure, and adding a context-size signal would make the suggestion fire when it actually matters.Why tool count alone is weak
Proposal
Add a second (primary) signal based on the real context size, read from the latest assistant turn's
usagein the session transcript.transcript_pathis already provided in the PreToolUse hook stdin payload.input_tokens + cache_read_input_tokens + cache_creation_input_tokensfrom the most recentusagerecord (these three partition the prompt, so the sum is the true context size of the turn).+Ntokens (e.g. 60k).[1m]marker, or if observed tokens already exceed 200k (covers logs that drop the suffix); else 200k.output({ hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext } })path the count signal already uses (post-PreToolUse warn-only hooks: stderr output not visible to users #2082), so it stays non-blocking.Reference sketch
Threshold crossing is tracked with a small per-session "bucket" so it only re-fires when context grows by another step.
I'm happy to open a PR if this direction is welcome.
Filed after auditing a local copy of the skill; surfaced via Claude Code.