The bug: BqA() in cli.js counts cache_creation_input_tokens and cache_read_input_tokens toward context usage, but these are cumulative session stats (millions of tokens), not actual context window consumption.

Resolved 💬 5 comments Opened Dec 15, 2025 by arsurvey82 Closed Feb 14, 2026

Bug Description:

The BqA() function in cli.js calculates context usage by summing all token types including cache_creation_input_tokens and cache_read_input_tokens:

function BqA(A){return A.input_tokens+(A.cache_creation_input_tokens??0)+(A.cache_read_input_tokens??0)+A.output_tokens}

These cache token values are cumulative session statistics (stored in stats-cache.json), not tokens currently in the context window. After extended use, these values grow to millions of tokens (e.g., 127M+), causing the percentage calculation in V1A() to always return 0%:

G=Math.max(0,Math.round((B-A)/B*100)) // When A >> B, result is 0

Steps to Reproduce:

  1. Use Claude Code extensively over multiple sessions
  2. Observe stats-cache.json shows large cacheReadInputTokens values (millions)
  3. Start a new conversation
  4. Status line shows "0% context remaining" or "Context low" warning immediately

Expected Behavior:
Context percentage should reflect actual tokens in the current conversation context, not cumulative cache statistics.

Workaround:
Change BqA() to exclude cache tokens:
function BqA(A){return A.input_tokens+A.output_tokens}

Environment:

  • Claude Code version: 2.0.69
  • Model: claude-opus-4-5-20251101
  • OS: Windows 10/11

View original on GitHub ↗

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