Skip to content

/compact fails with 'Conversation too long' when context limit is reached #23047

Description

@Asses13

Bug Description

/compact fails with an error when the conversation reaches the context limit — the exact situation where /compact is needed most. This creates a deadlock: the user cannot compact, cannot continue, and is forced to /clear (losing all context).

Steps to Reproduce

  1. Use Claude Code in a long session until "Context limit reached · /compact or /clear to continue" appears
  2. Run /compact
  3. Observe the error

Error Messages

First attempt:

❯ /compact
Error: Error during compaction: Error: Conversation too long. Press esc twice to go up a few messages and try again.

Subsequent attempts — same error, then the session becomes completely unresponsive:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must contain non-whitespace text"},"request_id":"req_011CXnuVCF3KmwzeqdM4gFNZ"}

Expected Behavior

/compact should always succeed, especially when the context limit is reached. Possible approaches:

  • Progressively drop older messages before attempting compaction
  • Use a smaller/faster model for the compaction summary when context is too large
  • Truncate the conversation to fit within limits before summarizing

Environment

  • Claude Code version: 2.1.31
  • OS: Ubuntu Linux 6.8.0-94-generic (x86_64)
  • Model: claude-opus-4-5-20251101

Impact

High — This is a Catch-22: /compact is the recommended action when context is full, but it fails precisely in that situation. The only workaround is /clear, which destroys all session context including task progress. This happens consistently across sessions and projects.

Additional Context

The "Press esc twice to go up a few messages and try again" suggestion does not help — the error persists regardless. After the compaction failure, the session often enters a broken state where even normal messages fail with the text content blocks must contain non-whitespace text API error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corebugSomething isn't workinghas reproHas detailed reproduction stepsoncallplatform:linuxIssue specifically occurs on Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions