context_window.used_percentage doesn't match internal context warning calculation

Open 💬 5 comments Opened Jan 13, 2026 by tomerbr1

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

  1. Use Claude Code 2.1.6 with a custom status line that reads context_window.used_percentage
  2. Use the session until context gets high
  3. Compare used_percentage value 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:

  1. Include system overhead in used_percentage to match internal warning calculation
  2. Add a separate system_tokens field so status lines can calculate the true total
  3. Add a total_used_percentage field that includes everything

Environment

  • Claude Code version: 2.1.6
  • OS: macOS

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗