Skip to content

[BUG] Error during compaction #7530

Closed as duplicate
Closed as duplicate

Description

@mtaksa

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The /compact command fails with an error message stating "Conversation too long. Press esc twice to go up a few messages and try again." This prevents users from compacting their conversation history when the conversation becomes lengthy.

What Should Happen?

The /compact command should successfully compress the conversation history regardless of length, summarizing previous messages while preserving important context. Users should be able to compact conversations of any reasonable size to manage token usage and maintain conversation continuity.

Error Messages/Logs

Steps to Reproduce

  1. Start a new conversation in Claude Code
  2. Have an extended conversation with multiple tool calls, file reads, and edits (likely 50+ messages)
  3. Run the /compact command
  4. Observe the error: "Error during compaction:Error: Conversation too long. Press esc twice to go up a few messages and try again."

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

1.0.111

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Activity

  1. PabloLION commented on Sep 12, 2025

    @PabloLION

    I see this too in the recent days. a lot of failures on /compact even when I'm at 25% (barely have no dialogue)

  2. OMorris95 commented on Sep 13, 2025

    @OMorris95

    This has also been happening to me a lot recently. Pressing esc twice and going back messages also doesn't help and attempting to compact still brings the same error.

  3. PabloLION commented on Sep 13, 2025

    @PabloLION

    Pressing esc twice and going back messages also doesn't help

    I forgot this part. It happens more than 80% of the time. And when it happens, even I retry multiple times it still doesn't work.

    And I also observed: when the context goes out of length, it seems a force /clear will happen, and we will be thrown to a new session, losing all the access to the old chat history. I know it stored somewhere in my file system, but it's not in the TUI.

  4. TUstudents commented on Sep 13, 2025

    @TUstudents

    I can confirm this bug in 1.0.111

  5. cahaseler commented on Sep 14, 2025

    @cahaseler

    Also seeing this issue on almost any manual compact, if I then add tons more context to force it to auto-compact at 100% of context, it works just fine. So clearly the issue isn't actually too many messages.

  6. leichti commented on Sep 14, 2025

    @leichti

    Can confirm that as well. See it since a few days quite often, but seems to not effect the automatic compact

  7. OMorris95 commented on Sep 14, 2025

    @OMorris95

    Haven't experienced the issue today, but when I was experiencing it, it was also affecting the auto compact. Currently on v1.0.113, not sure what version I was on when I had the issue yesterday.

  8. PabloLION commented on Sep 14, 2025

    @PabloLION

    On my side it's also fixed. Guess we can close now.
    It seems that in the new /compact does clear the history visually. Bugs are introduced in the implementation and are fixed now.

  9. VirtualMaestro commented on Sep 14, 2025

    @VirtualMaestro

    I got it now.
    OS: Win 11
    Claude Code: 1.0.113
    Terminal: MINGW64 (Git/Bash)

    Image
  10. 117 remaining items

  11. polat-mustafa commented on Feb 10, 2026

    @polat-mustafa

    Issue persists in v3.1.28.
    Found a workaround: run /exit, use /resume to return to the affected chat history, and then run /compact. This seems to clear the bug for now.

  12. phinolex commented on Feb 10, 2026

    @phinolex

    Issue persists in v3.1.28. Found a workaround: run /exit, use /resume to return to the affected chat history, and then run /compact. This seems to clear the bug for now.

    Thanks @polat-mustafa for sharing this workaround! 🙌 The /exit → /resume → /compact sequence is a great temporary fix

  13. ansonphong commented on Feb 12, 2026

    @ansonphong

    This bug is happening many times a day, just started happening recently.

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

    I'll try that work-around. It's getting very annoying.

  14. welfvh commented on Feb 12, 2026

    @welfvh

    Getting this all the time.

  15. orenpa commented on Feb 12, 2026

    @orenpa

    Getting this all the time.

    switching to codex.. can't work with it

  16. vladimir-trifonov commented on Feb 14, 2026

    @vladimir-trifonov
    /clear
    /resume
    /compact
    
  17. junaidtitan commented on Feb 18, 2026

    @junaidtitan

    One pattern I've noticed is that compaction failures correlate with session bloat — sessions packed with duplicate file reads, progress ticks, and large tool outputs are much harder for the summarizer to handle cleanly. I built cozempic to prune that dead weight before compaction triggers. Running cozempic treat on a bloated session typically removes 40-70% of the noise, which in my experience makes compaction succeed where it was failing before.

  18. gonewx commented on Feb 20, 2026

    @gonewx

    Still hitting this regularly. Failed compaction is one of the worst UX moments in Claude Code — you are told "context is low, run /compact" but then compact itself fails, leaving you stuck.

    The real damage is not the error itself — it is losing the session context you spent time building. All the file knowledge, decisions, and debugging steps are effectively gone when you have to start fresh.

    Two things that have helped me:

    1. Run /compact proactively before the context gets too large, not when the system warns you
    2. Use Mantra to capture session states continuously — when compaction fails, I can browse back to any earlier point in the session and start a new one with the relevant context. It is basically insurance against compact failures.

    Would love to see the compact command become more robust, but in the meantime having a session safety net has saved me countless hours of re-explaining context to a fresh session.

  19. Vinix24 commented on Feb 25, 2026

    @Vinix24

    The root problem here isn't compaction itself — it's that compaction is a lossy operation being asked to do lossless work. When it fails, you lose everything.

    I sidestepped this entirely by rotating before compaction becomes necessary. A PreToolUse hook checks context usage on every tool call — at ≥65% it blocks the agent and instructs it to write a structured handover file (task state, files touched, progress, next steps). A PostToolUse hook detects the handover, then a detached script sends /clear via tmux and injects a continuation prompt into the fresh session.

    The 65% threshold is the key insight: that's ~15 points before auto-compact kicks in at ~80%. Enough headroom for the agent to write a clean handover without racing against compaction.

    The fresh session picks up the handover and knows exactly where to resume. No context lost, no "press esc twice" errors, no manual intervention. Works especially well for long multi-file sessions and agent workflows where compaction consistently chokes.

    I open-sourced the setup recently — there's a dry-run replay you can run locally without needing an LLM to see the full lifecycle.

  20. yurukusa commented on Mar 24, 2026

    @yurukusa

    While the compaction error is a core issue, you can protect against state loss with a PreCompact hook:

    HANDOFF="\$HOME/.claude/session-handoff.md"
    {
        echo "# Pre-Compact State (\$(date -Iseconds))"
        [ -d .git ] && echo "Branch: \$(git branch --show-current 2>/dev/null)"
        [ -d .git ] && echo "Last commit: \$(git log --oneline -1 2>/dev/null)"
        [ -d .git ] && echo "Modified:" && git diff --name-only 2>/dev/null | head -5
    } > "\$HANDOFF"
    exit 0

    This runs before compaction happens, so even if compaction fails or loses context, you have a recovery file at `~/.claude/session-handoff.md`.
    Install: `npx cc-safe-setup --install-example session-handoff`
    For CLAUDE.md re-injection after compaction:
    `npx cc-safe-setup --install-example reinject-claudemd`

  21. junaidtitan commented on Apr 3, 2026

    @junaidtitan

    The "Conversation too long" compaction error happens when the session has grown so large that even the compaction prompt itself exceeds the context window. The fix is to prune before compaction ever triggers.

    Cozempic v1.4.1 does this automatically — the guard daemon monitors your session and runs pruning when token usage crosses thresholds. The PreCompact hook also fires a final prune pass right before Claude's native compaction, so it operates on a much smaller input.

    17 strategies target different bloat sources: progress ticks (40-48% savings), thinking blocks, stale file reads, duplicate system-reminders, and the new compact-summary-collapse (85-95% savings on compacted sessions).

    pip install cozempic && cozempic init

    If anyone here is still hitting this, I'd appreciate hearing whether the guard daemon prevents the error from recurring.

  22. claude commented on Apr 27, 2026

    @claude
    Contributor

    This is a duplicate of #2038, which was fixed as of version 2.1.85.

  23. github-actions commented on May 4, 2026

    @github-actions

    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.

  24. locked as resolved and limited conversation to collaborators on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corebugSomething isn't workingduplicateThis issue or pull request already existshas reproHas detailed reproduction stepsmemoryoncallplatform:macosIssue specifically occurs on macOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions