[BUG] API returns 500 Internal Server Error when context is near capacity (~92%)
Resolved 💬 3 comments Opened Dec 23, 2025 by michelsdev Closed Dec 23, 2025
Description
Claude Code returns 500 Internal Server Error when context usage is high (~92%), even though there are still ~16k tokens available. The API should either work normally or return a graceful error message, not an unhandled 500.
Error Message
API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal server error"},"request_id":null}
Context at Time of Error
- Total context: 184k / 200k tokens (92%)
- Free space: 16k tokens (8%)
- Model: claude-opus-4-5-20251101
Context Usage: 184k/200k tokens (92%)
⛁ System prompt: 5.2k tokens (2.6%)
⛁ System tools: 16.0k tokens (8.0%)
⛁ Custom agents: 370 tokens (0.2%)
⛁ Memory files: 6.1k tokens (3.1%)
⛁ Messages: 156.7k tokens (78.4%)
⛶ Free space: 16k (7.8%)
Steps to Reproduce
- Use Claude Code until context reaches ~90%+
- Attempt to send a message or perform an edit
- API returns 500 Internal Server Error
Expected Behavior
- Either the operation should succeed (16k tokens is still significant space)
- Or return a graceful error like "Context too large, please run /compact"
Actual Behavior
- Unhandled 500 Internal Server Error
- No useful error message
- User has no idea what went wrong
Impact
- Users paying for 200k context window effectively can't use the last ~10-15%
- Poor UX with cryptic error message
- Forces users to compact earlier than necessary
Environment
- Claude Code version: 2.0.75
- Model: claude-opus-4-5-20251101
- Plan: Max 20X
- Auto-compact: Disabled
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗