[BUG] Status bar shows different token count than /context command (22k vs 24k)

Status Fixed / completed
Reported on v2.1.16
Maintainer reply None cached
Activity 4 comments · opened Jan 22, 2026 · closed Jan 23, 2026

Bug Description

The status bar displays a different token count and percentage than the /context command output, even though issue #6537 and fix in v2.1.14 were supposed to align these values.

Environment

  • Claude Code version: 2.1.16
  • OS: macOS (Darwin 25.2.0)
  • Node: v20.13.1
  • Model: claude-opus-4-5-20251101

Steps to Reproduce

  1. Start a Claude Code session
  2. Have a conversation to build up context
  3. Run /context command
  4. Compare with status bar display

Expected Behavior

Both /context command and status bar should show the same token count and percentage.

Actual Behavior

  • Status bar shows: 24k/200k tokens (12%)
  • /context shows: 22k/200k tokens (11%)

Difference is ~2k tokens (~1-2% discrepancy).

Additional Context

  • This occurs consistently, not just once
  • According to CHANGELOG, v2.1.14 should have fixed /context to show same values as status line

Related Issues

  • #6537 (context reporting bug)
  • #9964 (status bar baseline mismatch - closed as duplicate)

View original on GitHub ↗

4 Comments

github-actions[bot] · 8 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/19316
  2. https://github.com/anthropics/claude-code/issues/18400
  3. https://github.com/anthropics/claude-code/issues/18241

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

ghost10101110 · 8 months ago

Closing as duplicate of #19316 - same issue (status bar vs /context showing different token counts)

ghost10101110 · 8 months ago

Root Cause Found & Solution

After debugging the statusline API, I discovered the issue:

Problem

context_window.total_input_tokens is cumulative - it sums ALL input tokens sent during the entire session, not the current context window usage.

This causes custom status bars to show inflated values that grow continuously (e.g., 241k/200k = 120%) while /context shows the correct 32k/200k.

Available Fields

{
  "total_input_tokens": 217556,      // ❌ CUMULATIVE - grows with each turn
  "total_output_tokens": 32345,      // ❌ CUMULATIVE
  "context_window_size": 200000,
  "used_percentage": 27,             // ✅ CORRECT - actual context usage
  "remaining_percentage": 73
}

Fix for Custom Statuslines

Before (wrong):

total=$(echo "$input" | jq ".context_window.total_input_tokens")
used_pct=$((total * 100 / 200000))

After (correct):

used_pct=$(echo "$input" | jq ".context_window.used_percentage")
ctx_size=$(echo "$input" | jq ".context_window.context_window_size")
total_k=$(( (ctx_size * used_pct) / 100000 ))

This now matches /context output exactly.

github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.