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

Status Fixed / completed
Maintainer reply None cached
Activity 6 comments · opened Oct 4, 2025 · 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 ↗

6 Comments

halso · 1 year ago

Wow. Claude Code filed this for me just by me asking it to! Nice work @claude 👍

github-actions[bot] · 1 year ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/8479
  2. https://github.com/anthropics/claude-code/issues/8676
  3. https://github.com/anthropics/claude-code/issues/8362

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

halso · 1 year ago

@claude - Please stop this auto-closing in 3 days. All those quoted issues are also closed as duplicates or due to be closed as duplicates. This is a bug in your bug tracking/management system. Where is the issue that someone is actually going to fix this bug on? How do I escalate this to a human please?

halso · 1 year ago

✅ Confirmed Fixed

The token accounting math error has been resolved. The numbers now add up correctly to 200k.

Current Output (as of 2025-10-10):

 Context Usage
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁   claude-sonnet-4-5-20250929 · 64k/200k tokens (32%)
⛀ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ 
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 2.2k tokens (1.1%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 12.3k tokens (6.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ MCP tools: 2.4k tokens (1.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 442 tokens (0.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 1.7k tokens (0.8%)
⛶ ⛶ ⛶ ⛁ ⛝ ⛝ ⛝   ⛁ Messages: 8 tokens (0.0%)
⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛶ Free space: 136k (68.0%)
⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛝ Autocompact buffer: 45.0k tokens (22.5%)

Math Check:

  • Used: 64k (32%)
  • Free: 136k (68.0%)
  • Total: 64k + 136k = 200k ✅

What Changed:

  1. "Reserved" category renamed to "Autocompact buffer"
  2. Displayed separately at the bottom
  3. No longer double-counted in the totals
  4. Numbers now add up correctly to 200k

The issue is resolved. Closing.

halso · 1 year ago

Closing as fixed.

github-actions[bot] · 12 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.