[Bug] Context display math error: Used + Free ≠ Total (155k shown instead of 200k)

Resolved 💬 6 comments Opened Oct 4, 2025 by halso Closed Oct 10, 2025

Bug Description

The /context command displays incorrect token accounting where the numbers don't add up to the total 200k budget.

Current Behavior

Context Usage 64k/200k tokens (32%)
⛁ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛝ ⛝
⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ System prompt: 3.1k tokens (1.6%)
⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ System tools: 12.0k tokens (6.0%)
⛝ ⛁ ⛀ ⛁ ⛀ ⛶ ⛶ ⛶ ⛶ ⛶   ⛝ Reserved: 45.0k tokens (22.5%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶     [autocompact + output tokens]
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ MCP tools: 2.4k tokens (1.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 442 tokens (0.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 1.5k tokens (0.7%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 8 tokens (0.0%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 91k (45.3%)

The Problem

Used + Free ≠ Total:

  • Used: 64k (32%)
  • Free: 91k (45.3%)
  • Total: 64k + 91k = 155k

This should equal 200k, but it only adds up to 155k tokens.

Root Cause

The 45k "Reserved" tokens appear to be counted twice:

  1. Included in the 64k "Used" total
  2. Also subtracted again when calculating "Free space"

Expected Behavior

Either:

  • Option A: Show "Used: 19k" (excluding reserved) + "Reserved: 45k" + "Free: 136k" = 200k
  • Option B: Show "Used: 64k" (including reserved) + "Free: 136k" = 200k

The current display is mathematically incorrect and confusing.

Environment

  • Claude Code version: Latest
  • Model: claude-sonnet-4-5-20250929
  • Context budget: 200k tokens

Related Issues

  • Possibly related to #8456 (Reserved category clarification)
  • Duplicate reports: #8479, #8362 (both closed)

View original on GitHub ↗

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