Skip to content

ContextWindowExceededError during compaction (litellm & claude-opus-4.5) #11450

Closed

Description

@Hexecu

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

  1. Start a session with a model having a limited context window (e.g., claude-opus-4.5).
  2. Have a long conversation until the token usage exceeds the context window.
  3. 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

Image

Operating System

macOS 15.7.2

Terminal

Integrated Terminal (VSCode) / Zsh

Activity

  1. github-actions commented on Jan 31, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    These issues relate to compaction failures with context window errors, particularly affecting Anthropic models like Claude Opus 4.5. The core problem appears to be that compaction itself fails when attempting to process oversized history, which is exactly what you're experiencing.

    Feel free to ignore if none of these address your specific case.

  2. github-actions commented on Apr 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions