[BUG] Messages category exceeds total context and context window size. Maybe calculation bug in read tool token counting.
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The messages token category in /context reports values that exceed both the total context usage and the 200k context window itself. This is a calculation bug which results in an early context limit reached warning. Messages appears to be computed independently from actual context, overcounting or double-counting file read tool results.
Session 1:
/context
⎿ Context Usage
⛁ ⛀ ⛁ ⛁ ⛁ ⛀ ⛀ ⛁ ⛁ ⛁ claude-sonnet-4-6 · 128k/200k tokens (64%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Estimated usage by category
⛁ System prompt: 3.3k tokens (1.6%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ System tools: 6.5k tokens (3.2%)
⛁ Memory files: 912 tokens (0.5%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Skills: 626 tokens (0.3%)
⛁ Messages: 187.5k tokens (93.7%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Compact buffer: 3k tokens (1.5%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
Suggestions
i Read results using 172.3k tokens (86%) → save ~51.7k
Use offset and limit parameters to read only the sections you need. Avoid
re-reading entire files when you only need a few lines.
i Autocompact is disabled
Without autocompact, you will hit context limits and lose the conversation.
Enable it in /config or use /compact manually.
Session 2:
/context
⎿ Context Usage
⛁ ⛀ ⛁ ⛁ ⛁ ⛀ ⛀ ⛁ ⛁ ⛁ claude-sonnet-4-6 · 158k/200k tokens (79%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Estimated usage by category
⛁ System prompt: 3.3k tokens (1.6%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ System tools: 6.5k tokens (3.2%)
⛁ Memory files: 912 tokens (0.5%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Skills: 626 tokens (0.3%)
⛁ Messages: 206k tokens (103.0%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Compact buffer: 3k tokens (1.5%)
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
Suggestions
i Read results using 193.6k tokens (97%) → save ~58.1k
Use offset and limit parameters to read only the sections you need. Avoid
re-reading entire files when you only need a few lines.
i Autocompact is disabled
Without autocompact, you will hit context limits and lose the conversation.
Enable it in /config or use /compact manually.
The actual conversational messages in both sessions were minimal. The messages value tracks almost 1:1 with "read results" from the suggestion line. For smaller files the jump is minimal and barely noticeable but if 1-2 bigger files with +30k token were read the percentage jumped to the above displayed wrong values on the third read. It seems like something happens around the 50% context mark.
Impact
- Messages displays values above 100% of the context window
- Context full warnings and autocompact triggers fire based on a number that is larger than reality
- Users may compact or restart sessions unnecessarily while significant free context remains
What Should Happen?
- Token calculation should produce the actual value currently in context
- Context limit reached warning should also work correctly
Error Messages/Logs
Steps to Reproduce
Read multiple (larger) files until the context limit reached warning appears. The current context window percentage should be lower than the message percentage. Message percentage will be wrong.
Claude Model
Not sure / Multiple models
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.84 (Claude Code)
Claude Code Version
2.1.87 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
_No response_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗