fix(gemini): use AfterTool instead of PostToolUse for Gemini CLI hooks
Gemini CLI uses AfterTool as the post-tool hook event name, not PostToolUse (which is Claude Code's event name). The installer was registering the context monitor under PostToolUse for all runtimes, causing Gemini to print "Invalid hook event name" warnings on every run and silently disabling the context monitor. Changes: - install.js: use runtime-aware event name (AfterTool for Gemini, PostToolUse for others) when registering context monitor hook - install.js: uninstall cleans up both PostToolUse and AfterTool entries for backward compatibility with existing installs - gsd-context-monitor.js: runtime-aware hookEventName in output - docs/context-monitor.md: document both event names with Gemini example Closes #750 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Context Window Monitor
|
||||
|
||||
A PostToolUse hook that warns the agent when context window usage is high.
|
||||
A post-tool hook (`PostToolUse` for Claude Code, `AfterTool` for Gemini CLI) that warns the agent when context window usage is high.
|
||||
|
||||
## Problem
|
||||
|
||||
@@ -37,7 +37,7 @@ Statusline Hook (gsd-statusline.js)
|
||||
/tmp/claude-ctx-{session_id}.json
|
||||
^ reads
|
||||
|
|
||||
Context Monitor (gsd-context-monitor.js, PostToolUse)
|
||||
Context Monitor (gsd-context-monitor.js, PostToolUse/AfterTool)
|
||||
| injects
|
||||
v
|
||||
additionalContext -> Agent sees warning
|
||||
@@ -63,9 +63,9 @@ GSD's `/gsd:pause-work` command saves execution state. The WARNING message sugge
|
||||
Both hooks are automatically registered during `npx get-shit-done-cc` installation:
|
||||
|
||||
- **Statusline** (writes bridge file): Registered as `statusLine` in settings.json
|
||||
- **Context Monitor** (reads bridge file): Registered as `PostToolUse` hook in settings.json
|
||||
- **Context Monitor** (reads bridge file): Registered as `PostToolUse` hook in settings.json (`AfterTool` for Gemini)
|
||||
|
||||
Manual registration in `~/.claude/settings.json`:
|
||||
Manual registration in `~/.claude/settings.json` (Claude Code):
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -88,6 +88,25 @@ Manual registration in `~/.claude/settings.json`:
|
||||
}
|
||||
```
|
||||
|
||||
For Gemini CLI (`~/.gemini/settings.json`), use `AfterTool` instead of `PostToolUse`:
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"AfterTool": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node ~/.gemini/hooks/gsd-context-monitor.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Safety
|
||||
|
||||
- The hook wraps everything in try/catch and exits silently on error
|
||||
|
||||
Reference in New Issue
Block a user