claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG]`API Error: Context limit exceeded makes tool unusable in longer sessions`

Open brandontan opened this issue 1 year ago • 9 comments

Body:

# Context Limit Error Makes Claude Code Unusable

## Problem
Claude Code becomes completely unusable when conversations get longer due to context limit being exceeded.

## Error Details

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"input length and max_tokens exceed context limit: 197202 + 21333 > 200000, decrease input length or max_tokens and try again"},"request_id":"req_011CSVYpzXYKxaxzSc64txNM"}


## Impact
- **Critical**: Tool becomes completely non-functional mid-session
- **Workflow Disruption**: Forces users to restart conversations, losing context
- **Professional Impact**: Affects productivity for developers relying on the tool for client work

## Expected Behavior
The tool should handle context limits gracefully by:
1. **Auto-compacting**: Automatically compress conversation history when approaching limits
2. **Warning System**: Alert users before hitting the limit
3. **Graceful Degradation**: Offer options to continue working (summarize, restart, etc.)
4. **Smart Context Management**: Prioritize recent and relevant conversation parts

## Suggested Solutions
1. Implement automatic context compression/summarization
2. Add `/compact` command functionality that actually works
3. Provide clear warnings when approaching context limits
4. Allow manual context pruning options
5. Implement sliding window approach for conversation history

## Environment
- Platform: Various (affects all users)
- Claude Code Version: 0.2.27
- Model: Claude Sonnet 4

## Workaround
Currently no viable workaround - tool becomes completely unusable requiring full restart and loss of all conversation context.

## Priority
**High** - This fundamentally breaks the core functionality of the tool for any extended development session.

Labels: bug, high-priority, usability

brandontan avatar Aug 26 '25 02:08 brandontan

Getting this as well

⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.155: all messages must have non-empty content except for the optional final assistant message"},"request_id":"req_011CSVUaJnG64vNG4KWZ6FmT"}

had to exit and restart new session

brandontan avatar Aug 26 '25 02:08 brandontan

so you need two zoko send? ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.101: all messages must have non-empty content except for the optional final assistant message"},"request_id":"req_011CSVr5wVsdD3MZNBkCavrR"}

⏵⏵ accept edits on (shift+tab to cycle) Context low (0% remaining) · Run /compact to compact & continue

  • unusable .. need to exit ... errors come up when context is low...

brandontan avatar Aug 26 '25 06:08 brandontan

/compact ⎿ Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.101: all messages must have non-empty content except for the optional final assistant message"},"request_id":"req_011CSVrDrf93W6NekUWoEebT"}

brandontan avatar Aug 26 '25 06:08 brandontan

I had a similar issue in vscode with context seemingly vanishing. I fixed it by changing the model, send a random message and then switch back to the model you had issues with. The issue seemed to start when i have multiple claude code open in same vs code instance:

Here is what i saw : ⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"input length and max_tokens exceed context limit: 197651 + 21333 > 200000, decrease input length or max_tokens and try again"},"request_id":"req_011CSWdCgJVzAYnK8Ae68Has"}

/context
⎿ ⛁ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Context Usage
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ claude-opus-4-1-20250805 • 61k/200k tokens (31%)
⛁ ⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ System prompt: 3.1k tokens (1.5%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ System tools: 11.6k tokens (5.8%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ MCP tools: 927 tokens (0.5%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Memory files: 2.2k tokens (1.1%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Messages: 43.5k tokens (21.7%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ Free space: 138.8k (69.4%)
MCP tools · /mcp
└ mcp__ide__getDiagnostics (ide): 428 tokens
└ mcp__ide__executeCode (ide): 499 tokens
Memory files · /memory
└ Project (D:\search_v3\CLAUDE.md): 2.2k tokens
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ > │╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ⏵⏵ accept edits on (alt+m to cycle) ◯
Context low (0% remaining) · Run /compact to compact & continue

After using /model , change to sonnet send some random message and then change back to whatever you were using:

/context ⎿ ⛁ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ Context Usage ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ claude-opus-4-1-20250805 • 99k/200k tokens (49%) ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ System prompt: 3.3k tokens (1.6%) ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ System tools: 11.6k tokens (5.8%) ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ MCP tools: 927 tokens (0.5%) ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Memory files: 2.2k tokens (1.1%) ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Messages: 80.6k tokens (40.3%) ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ Free space: 101.4k (50.7%)

 MCP tools · /mcp
 └ mcp__ide__getDiagnostics (ide): 428 tokens
 └ mcp__ide__executeCode (ide): 499 tokens

 Memory files · /memory
 └ Project (D:\learch_v3\CLAUDE.md): 2.2k tokens

danhill2020 avatar Aug 26 '25 16:08 danhill2020

As another observation - I am using ClaudeCode in VSCode (so not in the terminal). I have found that when I get the "prompt is too long" message, if I select the option to "login", or just click on "memory" and immediately after refresh the window and continue - I can just send another prompt of "k", and the model will continue doing whatever it was doing. I do not lose context this way, but it is super annoying to have to do this multiple times per day.

jgreywolf avatar Nov 12 '25 19:11 jgreywolf

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 13 '25 10:12 github-actions[bot]

Getting it too! Ability to memorize the current state before restarting would be good enough...

gshilin-sdb avatar Jan 07 '26 07:01 gshilin-sdb

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] avatar Feb 06 '26 10:02 github-actions[bot]

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.

github-actions[bot] avatar Feb 13 '26 14:02 github-actions[bot]