[BUG] Frequent premature compaction + infinite loop + prompt freezing with Opus 4.6 on 1M context

Status Closed — not planned
Reported on v2.1.89
Maintainer reply None cached
Activity 8 comments · opened Apr 1, 2026 · closed Jul 22, 2026

Preflight Checklist

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

What's Wrong?

Claude Code Version: 2.1.89
Model: claude-opus-4-6 (1M context)
OS: Debian 6.1.164-1
Platform: CLI

Bug Description:
Conversation is being compacted every 5–10 minutes despite context window never exceeding ~100K tokens. This has been ongoing for 1+ hour. The session is also unusually slow, and the prompt randomly freezes requiring Esc to unblock.

Expected Behavior:
Compaction should only trigger when approaching the context limit, not at <10% usage.

Actual Behavior:

  • Compaction triggers every 5–10 minutes at low token usage (~100K / 1M)
  • Session is significantly slower than normal
  • Prompt occasionally freezes and requires Esc + Enter to recover
  • Behavior consistent with the infinite compaction loop reported in #6004, #4878

Steps to Reproduce:

  1. Start Claude Code with claude-opus-4-6 on 1M context
  2. Begin a multi-file coding session
  3. Observe repeated compaction at low token usage within minutes

What Should Happen?

Conversation compaction should only trigger when the context window is close to its limit (e.g., 90–95% of the 1M token budget). With a 1M context window and only ~100K tokens used, compaction should not occur at all. The session should remain responsive, and the prompt should never freeze or require manual interruption (Esc) to recover.

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce:

  1. Start Claude Code with claude-opus-4-6 on 1M context
  2. Begin a multi-file coding session
  3. Observe repeated compaction at low token usage within minutes

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.89

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

7 Comments

Wishbringer71 · 6 months ago

behavior worsened between 2.1.92 and 2.1.96.
only 4 prompts and again contextwindow is full and compact necessary.
Seems some background tasks in claude code self are blowing it up

compact starts here at around 190k, far less then modell opus(1M) can handle

junaidtitan · 5 months ago

The premature compaction on 1M context is likely a threshold miscalculation — Claude Code's default assumes 200K. Cozempic auto-detects 1M context windows and adjusts thresholds accordingly (also configurable via --context-window or COZEMPIC_CONTEXT_WINDOW). Its guard daemon prunes session bloat proactively so compaction triggers far less frequently. pip install cozempic && cozempic guard — repo at https://github.com/Ruya-AI/cozempic. Curious if this fixes the frequency for you.

schultzparks-ux · 4 months ago

I get repeated "Auto compact is thrashing errors" in Cowork. my last one was prompted by just typing /setup-cowork.

this is nuking my credits. I think there might be a skill I downloaded that is not updated properly that is causing this. I might try wiping my desktop app?

Try sending your message again. If it keeps happening, share feedback so we can investigate.

Autocompact is thrashing: the context refilled to the limit within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output is likely too large for the context window. Try reading in smaller chunks, or use /clear to start fresh.
You can restart the conversation from an earlier message.

github-actions[bot] · 2 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

ammar-bay · 2 months ago

Im facing this issue on version 2.1.226 (Claude Code), was anyone able to fix this or found a workaround? When I check context usage with /context I get this

<img width="428" height="374" alt="Image" src="https://github.com/user-attachments/assets/30ad0cf6-ac71-4f2d-b6a5-cfc8acd6cbae" />

I have tried /clear and checked all the possible files I could but still same issue
Autocompact is thrashing: the context refilled to the limit within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output is likely too large for the context window. Try reading in smaller chunks, or use /clear to start fresh.

I tried with claude --safe-mode as well but still same issue, on vs code extension as well CLI.

ammar-bay · 2 months ago

I think the issue is with how it handle auto compact, that has corrupted for one of my projects, it is working fine on other projects and, when I tried with auto compact disable on current project, its working fine and I am also monitoring the usage and that looks normal as well.

ammar-bay · 2 months ago

I found the root cause, somehow this got added by claude code to my settings.local.json
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "5"
},

Showing cached comments. Read the full discussion on GitHub ↗