feat(hooks): warn before autocompact silently drops raw context - #39
Open
szarkans wants to merge 2 commits into
Open
feat(hooks): warn before autocompact silently drops raw context#39szarkans wants to merge 2 commits into
szarkans wants to merge 2 commits into
Conversation
New opt-in Stop hook hooks.autocompactNudge (default false) blocks once per severity level when transcript token usage closes in on Claude Code's resolved autocompact window (warn ~50k / critical ~10k remaining, margins clamped down on a small window) and recommends /mn:review --full. Claude Code's effective threshold is min(settings.autoCompactWindow, the model's context window), which ranges 200k-1M by model, so no per-model table is shipped — the window is resolved only from sources Claude Code itself already resolved (env, settings, its own ~/.claude.json cache); unknown window means silence, never a guessed default. Claude Code only, no-op on Codex. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ocompact nudge Explicit settings.autoCompactWindow above the model's real limit is trusted as-is — no per-model table to clamp against, and that's the point of resolving W only from Claude Code's own sources. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hooks.autocompactNudge(default false) —hooks/mnemo-autocompact-nudge.sh— blocks once per severity level (warn ~50k / critical ~10k tokens remaining) when the transcript's token usage closes in on Claude Code's resolved autocompact window, and recommends/mn:review --full.Wis resolved only from sources Claude Code itself already resolved —CLAUDE_CODE_AUTO_COMPACT_WINDOWenv →settings.autoCompactWindow→ its own~/.claude.jsoncache — never a hardcoded per-model default. UnknownWmeans silence.plugins/mnemo/scripts/context-window.py.docs/design-decisions.mdgets a new bullet under "Proactive nudges via hooks", including an explicit Rejected note — an explicitsettings.autoCompactWindowlarger than the model's real context is trusted as-is; mnemo ships no per-model table to clamp against, so that's a user misconfiguration, not something the hook defends against (raised and resolved during review).CHANGELOG.mdentry under[Unreleased].Test plan
python3 scripts/test-context-window.py— 18/18 (resolver + level logic, including margin clamping on a small window)python3 scripts/test-autocompact-nudge.py— 10/10 (gating, warn→critical escalation, anti-loop dedup, Codex no-op, missing-transcript/window silence)python3 scripts/test-stop-nudge.py— 7/7, confirms no regression on the existing Stop hooktest-context-hook.pyfailure reproduces identically on a cleangit stashoffmain— pre-existing, unrelated to this change🤖 Generated with Claude Code