-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Bug: preemptive-compaction hook built but never registered in hooks.json #2180
Copy link
Copy link
Open
Labels
agentsRelated to agent definitionsRelated to agent definitionsbugSomething isn't workingSomething isn't working
Description
Summary
The preemptive-compaction hook is built and exists in dist/hooks/preemptive-compaction/index.js, but it is never registered in hooks/hooks.json under PostToolUse. This means the HUD context warning feature silently does nothing.
Root Cause
- Not registered in hooks.json — the hook script exists in
dist/but no entry is added tohooks.jsonduring build/install. - In-memory state doesn't work for shell hooks — the original
createPreemptiveCompactionHook()uses an in-memoryMap()to track accumulated token counts, but each hook invocation spawns a new process, so state is always lost. The hook would never reach its threshold. - Token estimation is unrealistic — the original hook only counts
tool_responsecontent characters ÷ 4 as token estimate. A single tool response would need to be 680k+ characters to trigger at 170k tokens — practically never happens.
Environment
- OMC version: 4.10.2
- Claude Code version: 2.1.90
- macOS (Darwin)
Workaround
I rewrote the hook to use the transcript-file approach (same as pre-tool-enforcer and context-guard-stop) — reading input_tokens and context_window from the transcript's last 4KB. This is accurate and works reliably across process boundaries.
Key changes:
- Reads
transcript_pathfrom stdin JSON (provided by Claude Code) - Uses
resolveTranscriptPath()for git worktree compatibility - File-based cooldown (1 min per cwd in
/tmp/) to prevent warning spam - Warns at 70%, critical at 90%
Suggested Fix
Register the hook in hooks.json under PostToolUse and switch to transcript-based token reading instead of in-memory accumulation.
Would be happy to contribute a PR if helpful.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
agentsRelated to agent definitionsRelated to agent definitionsbugSomething isn't workingSomething isn't working