docs/context-monitor.md
A post-tool hook (PostToolUse for Claude Code, AfterTool for Gemini CLI) that warns the agent when context window usage is high.
The statusline shows context usage to the user, but the agent has no awareness of context limits. When context runs low, the agent continues working until it hits the wall — potentially mid-task with no state saved.
/tmp/claude-ctx-{session_id}.jsonadditionalContext| Level | Remaining | Agent Behavior |
|---|---|---|
| Normal | > 35% | No warning |
| WARNING | <= 35% | Wrap up current task, avoid starting new complex work |
| CRITICAL | <= 25% | Stop immediately, save state (/gsd-pause-work) |
To avoid spamming the agent with repeated warnings:
Statusline Hook (gsd-statusline.js)
| writes
v
/tmp/claude-ctx-{session_id}.json
^ reads
|
Context Monitor (gsd-context-monitor.js, PostToolUse/AfterTool)
| injects
v
additionalContext -> Agent sees warning
The bridge file is a simple JSON object:
{
"session_id": "abc123",
"remaining_percentage": 28.5,
"used_pct": 71,
"timestamp": 1708200000
}
GSD's /gsd-pause-work command saves execution state. The WARNING message suggests using it. The CRITICAL message instructs immediate state save.
Both hooks are automatically registered during npx get-shit-done-cc installation:
statusLine in settings.jsonPostToolUse hook in settings.json (AfterTool for Gemini)Manual registration in ~/.claude/settings.json (Claude Code):
{
"statusLine": {
"type": "command",
"command": "node ~/.claude/hooks/gsd-statusline.js"
},
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "node ~/.claude/hooks/gsd-context-monitor.js"
}
]
}
]
}
}
For Gemini CLI (~/.gemini/settings.json), use AfterTool instead of PostToolUse:
{
"hooks": {
"AfterTool": [
{
"hooks": [
{
"type": "command",
"command": "node ~/.gemini/hooks/gsd-context-monitor.js"
}
]
}
]
}
}