context_window.used_percentage doesn't match internal context warning calculation
Description
The used_percentage and remaining_percentage fields added in v2.1.6 for status line input don't include system overhead (tool definitions, CLAUDE.md files, MCP server configs, system prompt). This causes a significant discrepancy between the reported percentage and Claude Code's internal "Context low" warning.
Steps to Reproduce
- Use Claude Code 2.1.6 with a custom status line that reads
context_window.used_percentage - Use the session until context gets high
- Compare
used_percentagevalue with Claude's "Context low (X% remaining)" warning
Expected Behavior
used_percentage should match the percentage used in Claude Code's internal warning, so users can accurately track context usage.
Actual Behavior
| Source | Value |
|--------|-------|
| context_window.used_percentage | 75% |
| Claude Code warning | "Context low (6% remaining)" = 94% used |
19% discrepancy - the system overhead is not included in used_percentage.
Debug Data
{
"total_input_tokens": 78446,
"total_output_tokens": 28311,
"context_window_size": 200000,
"current_usage": {
"input_tokens": 0,
"output_tokens": 115,
"cache_creation_input_tokens": 1793,
"cache_read_input_tokens": 147730
},
"used_percentage": 75,
"remaining_percentage": 25
}
current_usage total: 149,638 tokens = 74.8% ≈ matches used_percentage: 75
But Claude's warning says 6% remaining (94% used), meaning ~38,000 tokens of system overhead aren't accounted for.
Suggested Fix
Either:
- Include system overhead in
used_percentageto match internal warning calculation - Add a separate
system_tokensfield so status lines can calculate the true total - Add a
total_used_percentagefield that includes everything
Environment
- Claude Code version: 2.1.6
- OS: macOS
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗