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

[BUG] Compact Conversation Infinite Loop

Open Andre-Profitt opened this issue 6 months ago • 15 comments

Environment

Platform (select one): Claude Code (CLI tool) Claude CLI version: 1.0.31 (Claude Code) Operating System: macOS Sequoia 15.4.1 Terminal & VSCode

Bug Description Claude Code is retaining context from previous projects even when starting a new project. The tool appears to be "stuck" with old context that should have been cleared.

/clear does not change the 0% until auto-compact function

Expected Behavior When starting a new project, Claude Code should begin with a fresh context without any information from previous projects. Actual Behavior Claude Code continues to reference or use context from previous projects even when starting fresh & auto-compact is stuck on a loop

Additional Context

MacBook Pro 16-inch, 2019 2.3 GHz 8-Core Intel Core i9 16 GB RAM Using VSCode with Claude Code integration Issue occurs in the terminal

Auto-compact stores context that persists across sessions No command to clear this compacted memory Deleting ~/.claude directory doesn't reset it Only workaround is disabling auto-compact entirely Feature request: Add /reset-context command or --fresh flag

Andre-Profitt avatar Jun 21 '25 00:06 Andre-Profitt

This Issue is related to Issue: https://github.com/anthropics/claude-code/issues/2283, https://github.com/anthropics/claude-code/issues/2387, and https://github.com/anthropics/claude-code/issues/2222

LarsArtmann avatar Jun 21 '25 00:06 LarsArtmann

[!TIP] WORK AROUND: Disable auto-compact via claude config set -g autoCompactEnabled false and /compact manually.

It's not great but at least it works (for me).

LarsArtmann avatar Jun 21 '25 00:06 LarsArtmann

Tip

WORK AROUND: Disable auto-compact via claude config set -g autoCompactEnabled false and /compact manually.

It's not great but at least it works (for me).

It didn't work for me :/

fabiobroldao avatar Jun 21 '25 01:06 fabiobroldao

It didn't work for me :/

Sad :(

  • Did you restart Claude Code afterwards?
  • Other possible things to check is /status or directly the local CLAUDE.md & the user CLAUDE.md at ~/.claude/CLAUDE.md if they would be huge that may be the trigger.

Could you share more about your experience, @fabiobroldao, so that we can get closer to identifying the root cause and enable the Claude team to resolve this issue for everyone.

LarsArtmann avatar Jun 21 '25 01:06 LarsArtmann

I just updated to the latest version of Claude Code, and restarted a conversation. It seemed to not respect the global config. Try:

[!TIP] /config and then disable Auto-compact directly in Claude Code.

LarsArtmann avatar Jun 21 '25 01:06 LarsArtmann

I just updated to the latest version of Claude Code, and restarted a conversation. It seemed to not respect the global config. Try:

Tip

/config and then disable Auto-compact directly in Claude Code.

I restarted the mac and it worked!!! No problems! I believe that some environment variable or even with node, was stuck!

fabiobroldao avatar Jun 21 '25 01:06 fabiobroldao

uhhh so I made a different account on my computer downloaded claude code again and I'm not having ANY issues at all anymore.

this was seriously unusable & I was getting API errors which are fixed now too.

I can't keep making a new user account on my computer just to work with claude but I do find it interesting

Andre-Profitt avatar Jun 21 '25 20:06 Andre-Profitt

I am on a Mac, running VS Code/Cursor as IDE for hosting terminal, and I recently installed Serena. That match anyone else's patterns for this?

NellInc avatar Jun 21 '25 22:06 NellInc

I am on a Mac, running VS Code/Cursor as IDE for hosting terminal, and I recently installed Serena. That match anyone else's patterns for this?

I don't know what Serena is. Any way I, I am on MacOS 15.5 (24F74) and run Claude Code from JetBrains IDEs Terminals and Item2.

LarsArtmann avatar Jun 22 '25 01:06 LarsArtmann

These API errors are driving me nuts also.

https://imgur.com/a/1oedVFy

This is a showstopper. What am I paying 200 bucks a month for? Get it together, Anthropic.

NellInc avatar Jun 22 '25 13:06 NellInc

I had to create a new user profile on my computer re install everything and then it worked... not an ideal workaround but it does work. ZERO issues in 12h!

I know it sucks but it starts working again like a charm. Then I just /clear after I'm done working on a certain task

Andre-Profitt avatar Jun 22 '25 13:06 Andre-Profitt

I had to create a new user profile on my computer re install everything and then it worked... not an ideal workaround but it does work. ZERO issues in 12h!

I know it sucks but it starts working again like a charm. Then I just /clear after I'm done working on a certain task

I tried this and it kinda worked for a while, but then the same problem came back again. This is awful. I was so productive all month and now I'm screwed.

NellInc avatar Jun 24 '25 20:06 NellInc

This is happening to me often, it just compacts for >10m and never stops

z-br avatar Jun 24 '25 20:06 z-br

I experienced the same infinite auto-compact loop making Claude Code unusable. After extensive debugging, I identified Zen MCP Server as the trigger in my setup. Solution: claude mcp remove zen The auto-compact bug disappeared immediately after removing Zen MCP. @NellInc mentioned issues after installing Serena MCP. Both are Python-based MCP servers with extensive tool sets. This suggests the bug isn't specific to one MCP server but rather how Claude Code handles certain MCP implementations. Workaround: Remove problematic MCP servers until Claude Code implements better MCP metadata handling.

YenK260 avatar Jun 25 '25 08:06 YenK260

This infinite autocompact loop is happening to me too, and also all my mcp servers just dissappeared from my Claude Code - aaaaaaagh - I'm using Warp terminal

calrizien avatar Jun 26 '25 22:06 calrizien

I'm experiencing the same situation.

I have tried restarting my Mac, uninstalling Claude Code, clearing caches, and deleting all related files, but nothing has changed. Even when I start a new session, it always begins with Context low (100% remaining). I'm not using MCP.

I'm using Ghostty

haryoiro avatar Jul 02 '25 08:07 haryoiro

Same situation here. Ubuntu 24.02. Tried everything I can think of -- including make an entire new user on the machine and completely removing and re-installing Claude Code. Nothing seems to fix it.

christabone avatar Jul 02 '25 15:07 christabone

@LarsArtmann Did you ever happen to make any progress on fixing this? Looking at all the open issues it seems like you've been experiencing this issue the longest.

christabone avatar Jul 02 '25 15:07 christabone

@christabone

[!TIP] What I can recommend trying:

  1. Update to the latest version of Claude Code
  2. Check your ~/.claude/CLAUDE.md and make sure it's less then 20k chars
  3. Check your CLAUDE.md in the project your working on and make sure it's less than 50k chars
  4. Use the latest version of node
  5. Restart you computer
  6. If it still persists just disable autoCompact via /config on every claude startup. And use manual /compact [Message] <-- Works better anyway if you instruct it what to follow
  7. Backup the ~/.claude/ folder and start fresh

I hope that helps!

LarsArtmann avatar Jul 16 '25 11:07 LarsArtmann

@LarsArtmann Thanks so much for taking the time to reply! Interestingly, it started working about a week after I last posted. Not sure why? I tried most of the things from your list initially and even went so far as to make a new user on the Linux machine I was using (still didn't fix it). Super confused, but at least it's back now and working.

christabone avatar Jul 16 '25 12:07 christabone

infinite auto-compac

That was it for me too.

sanirasheed avatar Aug 06 '25 14:08 sanirasheed

How to disable this shit, this breaks the task context!

tripolskypetr avatar Aug 07 '25 16:08 tripolskypetr

https://streamable.com/6g1u7w My experience

benlrichards avatar Aug 16 '25 12:08 benlrichards

opencode is working hooked up to my claude pro max plan! https://opencode.ai/

benlrichards avatar Aug 16 '25 14:08 benlrichards

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 12:08 Codewow

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 07 '25 10:12 github-actions[bot]