Expose context window usage to the model
Problem
The model has no way to know how much of its context window has been consumed. The statusline displays context usage percentage to the user, but this information is not accessible to the model itself.
This means the model must guess when context is running low, and those guesses are unreliable. In practice, internal estimates can be off by 15-20% (e.g., the model thinks it's at 65% when it's actually at 80% and about to auto-compact).
This matters because CLAUDE.md instructions often tell the model to perform handoff actions (write a handoff file, notify the user) at a certain context threshold — but the model can't reliably follow these instructions without ground truth.
Proposed Solution
Expose the current context usage to the model via one or more of:
- Environment variable — e.g.
CLAUDE_CONTEXT_PERCENTorCLAUDE_CONTEXT_TOKENS_USED/CLAUDE_CONTEXT_TOKENS_MAX, readable via Bash tool - Built-in tool — a lightweight tool the model can call to get
{ "used": 150000, "max": 200000, "percent": 75 } - System message injection — periodically inject context usage into the conversation (e.g. at 25%, 50%, 75%)
Option 3 would be the most useful since it requires no explicit action from the model and enables proactive handoff behavior. Options 1 and 2 would also work but require the model to remember to check.
Current Workarounds
- User manually tells the model when context is high (unreliable, easy to forget)
- Model guesses based on conversation length (inaccurate)
- Auto-compact fires and the model loses context without a chance to write a handoff
Additional Context
The statusline already has access to this data internally — it receives JSON session data including context fields. This request is about surfacing that same data back to the model.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗