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 4 months ago • 14 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