Feature Request: Expand hook input JSON with model, effort, and context window data
Problem
Hook scripts (PreToolUse, PostToolUse, Stop, UserPromptSubmit, etc.) receive a JSON payload that includes session_id, transcript_path, cwd, permission_mode, and hook_event_name — but not the current model name, effort level, or context window usage percentage.
The model field is available on SessionStart events, but not on any other hook event. effort and context_window are not available on any event.
This forces a workaround: the statusline command (which does receive full session state) writes values to /tmp/ files, and hooks read them back:
# In statusline-command.sh:
echo "${mshort:-unknown}" > /tmp/claude-model
echo "${CLAUDE_CODE_EFFORT_LEVEL:-default}" > /tmp/claude-effort
echo "${pct:-0}" > /tmp/claude-context-pct
# In hooks (e.g., a cost-tracking hook):
model=$(cat /tmp/claude-model 2>/dev/null || echo "unknown")
effort=$(cat /tmp/claude-effort 2>/dev/null || echo "unknown")
This is fragile (race conditions, stale reads if statusline hasn't rendered yet) and unintuitive. It also fails in headless mode where no statusline runs.
Proposed Solution
Add model, effort, and context_window to the common hook input fields available on all events:
{
"tool_name": "Bash",
"tool_input": { "command": "git status" },
"session_id": "abc123",
"cwd": "/home/user/project",
"permission_mode": "default",
"hook_event_name": "PostToolUse",
"model": "claude-opus-4-6",
"effort": "medium",
"context_window": {
"used_percentage": 42,
"remaining_tokens": 116000
}
}
Use Cases
- Cost tracking hooks that log model and effort per tool call for spend analysis — currently the #1 reason for the statusline bridge workaround
- Context-aware compaction guards that warn users when context is high (currently requires
/tmp/bridge viaUserPromptSubmit) - Effort-adaptive hooks that apply stricter validation at higher effort levels (e.g., security review at max effort → additional checks)
- Analytics correlating effort level with session outcomes (tool call count, duration, quality)
- Headless automation where no statusline renders — hooks currently get "unknown" for model/effort in headless
claude -pinvocations
Current Workaround
Statusline → /tmp/ file → hook read. Works in interactive mode but:
- Adds filesystem I/O per hook invocation
- No atomicity guarantee (hook may read mid-write)
- Requires statusline to have rendered at least once before hooks read accurate values
- Completely fails in headless mode (
claude -p) where statusline doesn't run - Race condition on first tool call of a session (statusline hasn't fired yet)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗