Skip to content

feat(hooks): warn before autocompact silently drops raw context - #39

Open
szarkans wants to merge 2 commits into
jojoprison:mainfrom
szarkans:feat/autocompact-nudge
Open

feat(hooks): warn before autocompact silently drops raw context#39
szarkans wants to merge 2 commits into
jojoprison:mainfrom
szarkans:feat/autocompact-nudge

Conversation

@szarkans

Copy link
Copy Markdown

Summary

  • New opt-in Stop hook 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.
  • Window W is resolved only from sources Claude Code itself already resolved — CLAUDE_CODE_AUTO_COMPACT_WINDOW env → settings.autoCompactWindow → its own ~/.claude.json cache — never a hardcoded per-model default. Unknown W means silence.
  • Token usage comes from the transcript (Stop-hook stdin carries no token count), via the new plugins/mnemo/scripts/context-window.py.
  • Claude Code only — no-ops on Codex.
  • Docs: docs/design-decisions.md gets a new bullet under "Proactive nudges via hooks", including an explicit Rejected note — an explicit settings.autoCompactWindow larger 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.md entry 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 hook
  • test-context-hook.py failure reproduces identically on a clean git stash off main — pre-existing, unrelated to this change
  • Live smoke test in a real Claude Code session approaching the autocompact window (not run — see review discussion)

🤖 Generated with Claude Code

szarkans and others added 2 commits August 16, 2026 03:44
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant