claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

MAJOR BUG: Claude Code Stuck in Infinite Compaction Loop Making it Basically Useless!

Open pm0code opened this issue 5 months ago • 15 comments

✽ Compacting conversation… (esc to interrupt) and since it is wasting so much time and cycles on compacting, this happens a lot sooner that it should:  Claude usage limit reached. Your limit will reset at 12pm (America/Los_Angeles).

Issue Summary

Claude Code v1.0.83 is stuck in an infinite loop attempting to "compact" the conversation, preventing task completion and wasting computational resources. consequently, i am getting, " Approaching Opus usage limit" and "Approaching usage limit. resets at x pm" a lot faster than what I am used to for the past 3 months that I have been using claude code.

Environment

  • Claude Code Version: v1.0.83 (latest)
  • OS: Windows 11 + WSL2 Ubuntu
  • Session Duration: Multiple hours
  • Task: Creating test files

Bug Description

Expected Behavior

Claude should:

  1. Read the required files to understand test patterns
  2. Identify missing test files
  3. Create the missing test files
  4. Complete the task

Actual Behavior

Claude is stuck in an infinite loop where it:

  1. Reads the same 5 test files repeatedly: - x_strategy_test.go (746 lines) - y_timeseries_strategy_test.go (746 lines) - z_markov_model_strategy_test.go (647 lines) - w_strategy_test.go (795 lines) - v_strategy_test.go (810 lines)
  2. After reading files, attempts to "compact" the conversation
  3. Returns to step 1, reading the same files again
  4. Never progresses to actually creating the missing test files

Pattern Observed

Read x_strategy_test.go → Read y_timeseries_strategy_test.go → Read z_markov_model_strategy_test.go → Read w_range_strategy_test.go → Read v_flow_imbalance_strategy_test.go → [Compaction attempt] → [Loop restarts]

Reproduction Steps

  1. Start a conversation about creating missing test files
  2. Claude identifies need to read existing test files for patterns
  3. Claude reads 5 test files successfully
  4. Claude enters compaction loop
  5. Loop continues indefinitely without task progress
  • User Experience: User must manually interrupt and restart

Evidence of Loop

The conversation history shows:

  • Same 5 files read multiple times
  • No actual test file creation despite having all needed information
  • Pattern recognition completed but no execution
  • Todo list shows task as "in_progress" but no progress made

Suspected Cause

Appears to be a context management issue where:

  1. Claude tries to compact/summarize conversation to fit context window
  2. Compaction process loses critical task state
  3. Claude re-reads files to "recover" context
  4. Process repeats infinitely

Workaround Attempts

  • User interrupted with: "Please continue the conversation from where we left it off"
  • Claude acknowledged but resumed the same loop pattern

Requested Fix

  1. Immediate: Break loop detection - if same files read >2 times, force task execution
  2. Long-term: Fix compaction logic to preserve task state and progress
  3. Safety: Add loop detection to prevent infinite patterns

Additional Context

  • The task is straightforward: create 3 test files following established patterns
  • All required information was successfully gathered in first read
  • No technical blockers exist - purely a control flow issue
  • System has sufficient context from the 5 example files

Severity: CRITICAL

This bug prevents completion of any complex multi-step task that triggers compaction, making Claude Code unusable for production software development tasks.


Recommendation: The compaction/context management system needs urgent review. When compaction occurs, task state and progress markers must be preserved to prevent re-reading already processed files.

pm0code avatar Aug 18 '25 02:08 pm0code

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2283
  2. https://github.com/anthropics/claude-code/issues/3288
  3. https://github.com/anthropics/claude-code/issues/2391

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Aug 18 '25 02:08 github-actions[bot]

@claude:: This has become a major productivity killer. it just came back from a compact and is showing already 11%: =============================== Previous Conversation Compacted =============================== ● Compact summary (ctrl+r to expand) ⎿  Read internal/abc.go (776 lines) ⎿  Read internal/xyz.go (633 lines) ⎿  Read internal/gag.go (500 lines) ⎿  Read ../../../../.claude/agents/shared/coordination_session.json (49 lines) ⎿  Read internal/fhfh.go (791 lines) ⎿  Todo list read (13 items)

● I'll continue fixing the pattern_aware_signal_service_test.go by properly handling the RuleEngine requirement for sql.DB. Let me create a proper solution using pgx/stdlib to get a sql.DB connection.

╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │ >  │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ⏵⏵ bypass permissions on (shift+tab to cycle) Context left until auto-compact: 11%

pm0code avatar Aug 18 '25 20:08 pm0code

Bump

cruftyoldsysadmin avatar Aug 22 '25 11:08 cruftyoldsysadmin

Anybody plan fix that awful bug? We paid 200 bucks per month its not 2$ with all of respects

nttylock avatar Aug 24 '25 20:08 nttylock

Found a workaround. Not sure how detrimental it is to context awareness, but deleting/renaming the settings.local file in the .claude folder fixed the context issues for me. I am guessing the file just got too large for Claude to be able to effectively read because of all the bash commands it stored away that weren't reusable in most cases.

if you want to YOLO it, you can use "claude --dangerously-skip-permissions" to bypass permission prompts (the ones that when saved to the project, fill up the setting.local.json file and ultimately cause the context issue)

But that is absolute last resort and very dangerous to do. Hence the flag name....

Codewow avatar Aug 25 '25 11:08 Codewow

Found a workaround. Not sure how detrimental it is to context awareness, but deleting/renaming the settings.local file in the .claude folder fixed the context issues for me. I am guessing the file just got too large for Claude to be able to effectively read because of all the bash commands it stored away that weren't reusable in most cases.

if you want to YOLO it, you can use "claude --dangerously-skip-permissions" to bypass permission prompts (the ones that when saved to the project, fill up the setting.local.json file and ultimately cause the context issue)

But that is absolute last resort and very dangerous to do. Hence the flag name....

Worked like a charm. Good find. It was frustrating as hell. 😂

sayyied avatar Aug 25 '25 16:08 sayyied

I'm in the same situation and my settings.local file is only 38 lines. I doubt that's the root cause.

timkjr avatar Aug 25 '25 20:08 timkjr

Found a workaround. Not sure how detrimental it is to context awareness, but deleting/renaming the settings.local file in the .claude folder fixed the context issues for me. I am guessing the file just got too large for Claude to be able to effectively read because of all the bash commands it stored away that weren't reusable in most cases.

if you want to YOLO it, you can use "claude --dangerously-skip-permissions" to bypass permission prompts (the ones that when saved to the project, fill up the setting.local.json file and ultimately cause the context issue)

But that is absolute last resort and very dangerous to do. Hence the flag name....

I followed this method, but it still doesn't work. Is there any other way to solve it?

huozhilin avatar Aug 28 '25 03:08 huozhilin

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 04 '25 10:12 github-actions[bot]

I'm seeing it with Opus 4.5 - within a single conversation it will compact multiple times before returning to the user

leaanthony avatar Dec 08 '25 10:12 leaanthony

It's hell

QuentinScDS avatar Dec 08 '25 13:12 QuentinScDS

I am seeing this as well, I'm on version 2.0.67

Sea-Chels avatar Dec 13 '25 03:12 Sea-Chels

Image

I faced a problem with Cloud Code also, while it is working I clicked "ctrl+c" to stop the process and add an additional prompt, but Claude Code stuck in this status for more than 2 hours.

Gratefully, this issue didn't occur on a critical process.

v2.0.65 Opus 4.5

MBajily avatar Dec 13 '25 19:12 MBajily

I was able to get out of infinite compaction loop by disabling a few MCP servers that is reported as consuming many tokens in /doctor and coming back to the same thread and resuming conversation.

kaovilai avatar Dec 23 '25 13:12 kaovilai