Expose context_window data in hook event stdin JSON
Feature Request
Problem: The context_window object (specifically used_percentage) is currently only available in the statusLine command's stdin JSON. It is not included in any hook event payload (UserPromptSubmit, PreToolUse, PostToolUse).
The statusLine command only runs in CLI mode. Users running Claude Code in VS Code / Desktop Code mode have no way to access context usage data from hooks.
Use case: I have a UserPromptSubmit hook that injects a timestamp and context usage percentage into every response. This works in CLI by reading a cache file written by the statusLine command, but in Desktop Code mode the statusLine never runs, so there's no context data available.
I also have a PostToolUse hook that warns at escalating thresholds (75/120/160 tool calls) and would benefit from including context % in those warnings.
Tested stdin fields by hook event (Claude Code on Windows, v1.0.x):
| Hook Event | Fields Received |
|---|---|
| UserPromptSubmit | session_id, transcript_path, cwd, permission_mode, hook_event_name, prompt |
| PostToolUse | session_id, transcript_path, cwd, permission_mode, hook_event_name, tool_name, tool_input, tool_response, tool_use_id |
| statusLine (not a hook) | All of the above plus context_window, model, cost, etc. |
Request: Include context_window (at minimum used_percentage) in the stdin JSON for hook events, particularly UserPromptSubmit and PostToolUse. This would allow hooks to react to context usage regardless of whether the CLI statusLine is available.
Workaround attempted: Using transcript file size as a heuristic for context usage. This was wildly inaccurate and was replaced by the statusLine cache approach, which only works in CLI mode.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗