[Bug] `/context` category breakdown shows double-counted tokens in Messages category

Resolved 💬 3 comments Opened Apr 15, 2026 by Crazytieguy Closed May 24, 2026

Bug Description

/context category breakdown doesn't add up — some context appears to be unaccounted for or double-counted.

Setup: fresh session, turn 0. One user turn ("Doing a quick context check"), one assistant response ("Ready. What would you like to work on?"). I ran /context immediately after.

/context displayed:
  System prompt: 6.3k
  System tools:  8.9k
  Custom agents: 1.5k
  Memory files:  2.3k
  Skills:        2.5k
  Messages:     15.7k
  Total:        37.2k

Cross-checked against assistant.message.usage on the preceding API call in the jsonl transcript: input=6, cache_creation=37,172 — matches the displayed 37.2k total exactly.

I reconstructed the actual message array at that point from the transcript (4 SessionStart hook attachments + deferred_tools_delta + mcp_instructions_delta + skill_listing + 1 user turn + 1 assistant turn, materialized per normalizeAttachmentForAPI) and passed it to the Anthropic count_tokens API (free endpoint):
  Real message content: 6,892 tok
  /context Messages:   15,700 tok
  Unexplained gap:      8,808 tok

Skills category (2.5k) is suspiciously close to the count_tokens value for the skill_listing attachment (2,466 tok) — suggesting that content is present in both the Skills and Messages categories.

The 8.8k gap is close in magnitude to:
  - System tools (8.9k), or
  - System prompt (6.3k) + Memory files (2.3k) = 8.6k

Either way, either (a) Messages is much larger than the actual message array warrants and some other category's content is being double-counted inside it, or (b) there's content in the API request the client-side breakdown isn't exposing. In both cases, /context's category breakdown doesn't accurately describe where the tokens are going, which makes it hard to act on when trying to trim context.

Environment Info

  • Platform: darwin
  • Terminal: WezTerm
  • Version: 2.1.108
  • Feedback ID: bfe27a60-783d-4d96-af67-b283cc285f65

Errors

[{"error":"MaxFileReadTokenExceededError: File content (13310 tokens) exceeds maximum allowed tokens (10000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at HY7 (/$bunfs/root/src/entrypoints/cli.js:4535:12021)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-15T02:16:56.943Z"}]

View original on GitHub ↗

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