-
Notifications
You must be signed in to change notification settings - Fork 14.7k
ContextWindowExceededError during compaction (litellm & claude-opus-4.5) #11450
Description
Description
Describe the bug
Context compaction fails with litellm.ContextWindowExceededError when the conversation history exceeds the model's context window, even when compaction is triggered manually.
This happens because the compaction process attempts to send the entire message history to the model for summarization, causing the input itself to exceed the context limit.
To reproduce
- Start a session with a model having a limited context window (e.g.,
claude-opus-4.5). - Have a long conversation until the token usage exceeds the context window.
- Wait for auto-compaction trigger or run
/compact.
Expected behavior
Compaction should summarize and shorten the history, allowing the session to continue.
Environment
- Model:
claude-opus-4.5 - Error:
litellm.ContextWindowExceededError: litellm.BadRequestError: BedrockException: Context Window Error - {"message":"The model returned the following errors: Input is too long for requested model."}
model=claude-opus-4.5. context_window_fallbacks=None. fallbacks=None.
Set 'context_window_fallback' - https://docs.litellm.ai/docs/routing#fallbacks. Received Model Group=claude-opus-4.5
Available Model Group Fallbacks=None
Additional context
The issue is located in packages/opencode/src/session/compaction.ts. The process function passes input.messages directly to MessageV2.toModelMessages without any truncation, leading to the overflow during the compaction request itself.
Plugins
Context7
OpenCode version
v1.1.47
Steps to reproduce
Steps to reproduce:
Configure model: Set active model to claude-opus-4.5 (or any model with strict context limits) connected via LiteLLM.
Fill context window: Engage in a long conversation or paste large files until the token usage exceeds the model's context limit (generating >200k tokens).
Trigger compaction: Either wait for auto-compaction to trigger, or manually run the /compact command.
Observe error: The process crashes with litellm.ContextWindowExceededError instead of summarizing the history.
Screenshot and/or share link
Operating System
macOS 15.7.2
Terminal
Integrated Terminal (VSCode) / Zsh