Compaction failed, looped or got stuck. What the message means and what to do
In the reports and docs behind this page, compaction failures usually come from something compaction can’t shrink: one huge file or tool output, images piled up in the history, or what’s sent with every request (rules files, MCP tool definitions, attachments). Summarizing the conversation doesn’t make those smaller, so the agent compacts again, or gives up, or hangs. The rest are bugs that come and go by version, so note yours first.
Below, each tool’s messages are mapped to their cause and fix, from the vendors’ own docs and changelogs and from bug reports on GitHub and Cursor’s forum. Then the settings, by name, and what to do when a session can’t compact at all.
An AI drafted this page from the sources below and another AI checked it. No person has run these steps: nobody here has reproduced these errors. Counterparts is ours: Mike LaPeter runs Counterparts.
First, three checks for any tool
- See what fills the window. Claude Code:
/context. Cursor: click the context ring by the prompt. If the conversation is the small part, compacting won’t help: trim rules files, turn off MCP servers you aren’t using (Claude Code:/mcp disable <name>), drop attachments. - Look for one big thing. A log, a PDF, a long diff or a pile of screenshots in the history is the usual cause of a loop. Start clean without it: in Claude Code,
/clearor a new session (claude --resumeor/resumereopens the old conversation later), or compact with a focus that leaves it out. - Note your version before you search for the message: Claude Code
claude --version, Codexcodex --versionor “About Codex”, Cursor “About Cursor”. Several of the rows below say “before vX”.
Claude Code
Checked against Anthropic’s error reference, troubleshooting page, settings reference and changelog on November 20, 2026, when the newest version was 2.1.329.
| You see | What it means | What to do |
|---|---|---|
Autocompact is thrashing: the context refilled to the limit... | Compaction worked, but a file or tool output filled the window again right away, several times in a row, so Claude Code stopped. | Read the file in smaller pieces; |
Context limit reached · /compact or /clear to continue | The conversation plus attachments is over the model’s window. With |
|
Prompt is too long · automatic compaction failed: <error> | The automatic compaction hit another error, such as an unavailable model or a failed sign-in. | Fix the named error first; |
Prompt is too long · this conversation is a single exchange and cannot be compacted (or A single-exchange conversation cannot be compacted), and /compact answering Not enough messages to compact. | One exchange fills the window: your prompt plus what Claude Code sends with every request. There’s nothing earlier to summarize. |
|
Context is 94k tokens past the 200k-token compaction window — run /compact to reduce usage. (in /context) | The conversation is past a compaction window that sits below the model’s window, such as the 200K boundary on 1M-token models. |
|
Request too large (max 32MB)... | Images and attachments built up in the request. |
|
Prompt is too long right after you stopped Claude mid-compaction | The conversation is unchanged and still needs compacting. |
|
| On an LLM gateway, Bedrock or Foundry: the same “too long” error every turn instead of a compaction, or compacting over and over | Older versions didn’t recognize some providers’ “too long” wording (fixed in v2.1.217 for Bedrock, v2.1.228 for the Claude apps gateway, v2.1.325 for many third-party gateways and Foundry), or compacted repeatedly behind a gateway that named a different model (fixed in v2.1.301). | Update first. If Claude Code warns it doesn’t recognize your model ID and assumes the wrong window, |
Compaction failing or repeating with a PreCompact hook installed | A hook’s output is added to the compaction instructions. Before v2.1.314, very large output could make compaction fail or repeat; it’s now cut at 10,000 characters per hook. | Update, then start with |
Compacted while idle, before the prompt cache expired (terminal) or Compacted using a summary written while you were away (VS Code, Desktop) | Idle compaction, working as designed. | Nothing, or turn it off (next section). |
Idle compaction. Since v2.1.299 in the terminal (v2.1.314 in VS Code and the desktop app’s Code tab), Claude Code compacts a long conversation you’ve stepped away from, so your next message sends a summary instead of re-sending the whole conversation after the one-hour prompt cache expires. The docs list the conditions: an interactive session, auto-compact on, the one-hour prompt cache, at least 200,000 tokens of context by default, and about an hour idle with the computer awake. It costs detail. In two r/ClaudeCode threads, several people said they turned it off, and others said to check whether idle compaction was really the cause first, and one wrote that after a long session was compacted “from say 300k to 90k”, the next question put it “in amnesia mode and it goes on to rediscover everything” (comment). For a desktop or VS Code session, the docs say to set idleCompaction in the settings on the machine or WSL distribution where the session runs. An open report on GitHub says a summary written before you turned it off can still be applied when you come back (#108089).
A different wording. One r/ClaudeCode user saw “This chat is too long to continue, and compacting it automatically didn’t help. You can try compacting again, rewind to an earlier point, or start a new chat.” (post). The version they gave, 2.42304.0, isn’t a Claude Code 2.1.x number, and the pages of Anthropic’s docs we read don’t list that wording. If you see a message like it in a claude.ai chat rather than in Claude Code, see when a Claude chat gets too long. Replies suggested /context before compacting. Separately, an open report says Claude’s desktop app shows nothing when an automatic compaction fails (#103708), and in another, a Code tab session on Fable 5.2 compacted eight times in 23 minutes; a commenter traced it to the desktop app’s bundled Claude Code not recognizing the model and assuming a 200K window, and suggested running that model from the standalone CLI until the desktop app’s bundled version catches up (#108785).
Codex
Checked against OpenAI’s Codex docs and the Codex source at release 0.171.0 (the newest stable release on November 20, 2026). OpenAI’s docs don’t have an error reference for compaction, so the causes below come from GitHub issues, with the app and CLI versions their reporters gave.
| You see | What’s been reported | What to do |
|---|---|---|
Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying. | The request is over the model’s window. One user saw it in place of the automatic compaction they used to get (forum). | Start a new thread, as the message says, with a note of where things stand. |
Error running remote compact task: {"detail":"Bad Request"}, or “Compacting context” with “Reconnecting 1/2”, Broken pipe, then 408 Request Timeout | Image-heavy chats: one reporter measured a 74 MB request before compression on Codex desktop 26.1007 (#55076). A commenter on another stuck chat pointed to images in the history too (comment). | Stop retrying the same chat. Start a new one and open old images only when the next step needs them. The reporter on #55076 got the same chat working again by hand-editing its saved history, which OpenAI doesn’t document; we haven’t tried it, so this page gives no steps for it. |
Error running remote compact task: The 'gpt-5.5' model is not supported when using Codex with a ChatGPT account. | An older chat compacts on the retired model it was started on, even after you switch (#54226, open, Codex desktop on Windows). | New threads work. Two users on the issue report recovering old threads by hand-editing the session file, and the opener says that didn’t work for them. OpenAI doesn’t document it and we haven’t tried it, so this page gives no steps for it. |
Error running remote compact task: unexpected status 401 Unauthorized: Incorrect API key provided: sk-svcac... | Reported by several ChatGPT-signed-in users at once on September 25, 2026, with no API key set anywhere; one linked an OpenAI status incident. Closed within the hour as a duplicate (#48232). | Check status.openai.com before changing your setup. |
| Compacting again and again, with little progress | Something sent with every request is too big to compact, such as a large connected-apps tool catalog (#61679, open). | Turn off apps or MCP servers you don’t need for the task; start a new thread. |
Context compacted, then “What would you like me to work on in this repository?” | Compaction succeeded but the task didn’t carry over (#57806, open). | Keep the task in a file the next turn can read (see below). |
Codex settings, from its config reference: model_auto_compact_token_limit sets the token count that triggers automatic compaction (unset uses the model’s default), compact_prompt replaces the instructions for the summary, and /compact compacts on demand. The config reference lists PreCompact and PostCompact hook events too. OpenAI’s troubleshooting page says that if a chat appears stuck, check whether it’s waiting for an approval, and otherwise start a new chat with a smaller, more focused prompt.
Cursor
Cursor’s docs say it “compresses older parts of the conversation into a summary” when the window gets close to full, and show the breakdown behind the context ring. In the CLI, /summarize (alias /compress) does it on demand. Cursor’s docs have no error list for summarizing, so these come from staff replies on Cursor’s forum. We didn’t check Cursor’s current version; the versions are the reporters’.
| You see | What Cursor staff found | What to do |
|---|---|---|
| A loop of “Summarizing chat context”, “Planning next moves” and “Reconnecting”, then “An unexpected error occurred” | What was sent with every request was about 1.08 million tokens, more than double what the model accepts, so summarizing couldn’t help, even in a new chat. Cursor later changed it to stop sooner with a message that the conversation is too long (forum). | Check the context breakdown on an empty chat, then trim rules files ( |
| “Chat context summarized” over and over, no answer | AGENTS.md files inside skill folders were loaded in full with every request (forum). | Rename them SKILL.md and give each a |
/summarize finishes in a second and the context stays full |
| On Grok 4.7, set Context to 256K and run it again, or wait: staff say automatic summarizing still runs when the window fills. |
| A plan stuck on “building” after a summarize | Build was clicked while the summarize was still running (forum). | Wait for the summary to finish before Build. If a plan is already stuck on building, send any short message in that chat and let it finish. |
When it can’t compact: save, start clean, carry a note
When the fixes above don’t work, start over from a note. A session that can’t compact often can’t write its own summary either. The conversation isn’t lost: Claude Code keeps it in ~/.claude/projects/ and Codex in ~/.codex/sessions/, and your files and uncommitted changes are in the folder. In Claude Code, /resume reopens the old conversation to look back at it, though it comes back just as full. To get a note out of it, a new session can read the old transcript (a .jsonl file under ~/.claude/projects/) without editing it and write the note, as in the Codex routine below (we haven’t tried it). In Codex, a new chat can read the old session file under ~/.codex/sessions/ and write the note from it, without editing it (one user’s routine; we haven’t tried that either).
Some of the messages above suggest rewinding. That opens Claude Code’s rewind menu, where some choices also undo file edits made since that point, so this page sticks to /compact, /clear and /resume.
- Save the state. Commit, even a work-in-progress commit. If the session still answers, ask it to write a short note of where things stand. One commenter’s routine: “ask for a short handoff note in a file, then start a new session” (comment).
- Start clean.
/clearor a new chat. If the cause was something loaded every time, fix that first, or the new chat fills up too. - Carry the note over. Name the note in the first prompt of the new session. Handing off when a coding agent hits its limit has the note, field by field, and the prompts for both sides.
A note helps after a compaction that “worked”, too. One Cursor user wrote that after a summary it “completely forgot the tasks it had already done” and started over, so near a full window they have it write the remaining tasks to a TODO file with the context for each (V2EX, in Chinese, our translation).
The settings, by name
Claude Code, from the settings reference:
| Setting | What it does |
|---|---|
autoCompactEnabled (/config Auto-compact) | Default on. Off stops automatic compaction and idle compaction; |
idleCompaction (/config Idle compaction, v2.1.302+) | Default on. |
CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS | The context size at which idle compaction applies. Default 200,000, lowest 100,000. |
autoCompactWindow, /autocompact 500k, --autocompact | How full the window gets before automatic compaction, at least 100,000 tokens. |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | The percentage of the auto-compact window at which compaction runs. It can only move compaction earlier. |
DISABLE_AUTO_COMPACT=1 | Turns off automatic and idle compaction for the session, and overrides |
DISABLE_COMPACT | Turns off all compaction, |
Turning auto-compact off doesn’t stop the window filling. It moves the failure to Context limit reached, so you’d run /compact or /clear yourself. To steer what a summary keeps, run /compact with a focus, or add a “Compact Instructions” section to CLAUDE.md. For Codex, the settings are model_auto_compact_token_limit and compact_prompt (above). For which rules and files Claude Code reloads after a compaction, see Claude Code memory.
Where Counterparts fits
Counterparts, the memory we make, is Claude’s memory of you and your work together, in Claude’s own words. Each Claude Code session you start with it opens with a short “who I am, who you are, where we left off” that Claude wrote itself. After compaction, Counterparts puts your memory back: the hook re-delivers the wake, and what was said before the compaction is still written up. It doesn’t change when Claude Code compacts, and it can’t rescue a session that won’t; the handoff note above carries the exact state of the task.
It runs in Claude Code (and in Claude Desktop on macOS). There’s no Codex or Cursor version, so for those the note above is the whole answer. In Claude Code (Node 22.15 or newer), install it from a terminal, then restart Claude Code:
npm install -g counterparts@latest
counterpartsFor the Claude desktop app on a Mac, also quit it, run counterparts install --host claude-desktop, reopen it, and set the counterparts tools to Always allow.
On macOS or Linux you can install it as a plugin instead: /plugin marketplace add mlapeter/counterparts, then /plugin install counterparts@counterparts. It’s free and open source, with no account or API key, and the memory stays on your computer. Counterparts for Claude Code has the details.
What we haven’t tested
This page is a research summary. Nobody here has triggered these errors or tried the fixes. The Claude Code rows come from Anthropic’s docs and changelog as of version 2.1.329; the Codex and Cursor rows come from bug reports and staff replies, which describe one person’s setup at one version. Reddit comments were read through the Arctic Shift archive, not opened live. Bugs in these tools are fixed most weeks, so check your version against the changelog before you work around one.
Questions people ask
What does “Autocompact is thrashing” mean in Claude Code?
Compaction worked, but a file or tool output filled the context window again right after, several times in a row, so Claude Code stopped retrying. Anthropic’s fix list: have Claude read the file in smaller pieces, run /compact with a focus that drops the large output (for example /compact keep only the plan and the diff), move the big read to a subagent, or /clear if you don’t need the earlier conversation. If it comes back after /clear, run /context: when the rows other than Messages add up to more, what loads at startup is too big.
How do I turn off idle compaction in Claude Code?
Set "idleCompaction": false in ~/.claude/settings.json, or change the Idle compaction row in /config (v2.1.302 or later). The key needs v2.1.290 or later; on older versions, turn off autoCompactEnabled (or set DISABLE_AUTO_COMPACT=1), which also turns off ordinary auto-compaction. An open bug report (#108089) says a summary written before you turned it off can still be applied when you come back.
Why did Claude Code compact a session that was only at 13% context?
Usually a setting that moves compaction earlier. The meter shows a share of the model’s whole window, but compaction runs at the auto-compact window, which can be as low as 100,000 tokens (10% of a 1M window). Check, in the environment Claude Code starts from: CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (a lower value compacts earlier), CLAUDE_CODE_AUTO_COMPACT_WINDOW, CLAUDE_CODE_DISABLE_1M_CONTEXT (holds 1M models to 200K), and the window /autocompact reports. In an open report (#109439) of compaction at about 12%, a commenter showed the numbers fit CLAUDE_AUTOCOMPACT_PCT_OVERRIDE set to 12 and said to check that first. If you remove it from a settings file, restart Claude Code: the commenter says a value already loaded stays in effect until then. Idle compaction is the other cause: it applies from 200,000 tokens by default (100,000 at the lowest), so on a 1M window it can run at 20%. Look for the “Compacted while idle” line, and if it keeps happening, file a report with your version.
Claude Code says “Prompt is too long · automatic compaction failed”. What now?
Read what comes after the colon. It names the error the compaction itself hit, such as an unavailable model or an authentication failure, and /compact fails the same way until you fix that. Behind a custom ANTHROPIC_BASE_URL, set the model’s context window or update to v2.1.299 or later.
Codex is stuck on “Compacting context” and keeps reconnecting. Can I save the chat?
Not the chat itself, but what’s in it. Reports on GitHub tie the hang to very large requests, mostly from images in the history, or to an old model the chat was started on. OpenAI’s troubleshooting page says to start a new chat with a smaller, more focused prompt. The old chat stays on disk under ~/.codex/sessions/, so one commenter’s routine is to have the new chat read that file and write a short handoff (goal, decisions, what’s done, next step), re-attaching only the images the next step needs. A few users report reviving a stuck chat by hand-editing its session file; OpenAI doesn’t document that and we haven’t tried it, so this page gives no steps for it.
Cursor keeps showing “Summarizing chat context” and never answers. Why?
In one case Cursor traced, what was sent with every request (rules files such as AGENTS.md or CLAUDE.md, MCP tools, attachments) was over twice the model’s window, so summarizing the conversation couldn’t help, and a new chat didn’t either. Open the context ring’s breakdown on an empty chat and trim the biggest category. Cursor says it now stops sooner with a message that the conversation is too long.
Compaction worked, but the agent forgot what it was doing. Is that the same problem?
It’s a common report after compaction, in Codex (an open issue where the agent asks “What would you like me to work on in this repository?”) and in Cursor. Keep the task in a file the agent can reread, such as a short handoff note. For Claude Code, our Claude Code memory guide covers which rules and files come back after /compact and which don’t.
Does Counterparts fix compaction?
No. Counterparts, the memory we make, doesn’t change how Claude Code compacts or stop a compaction from failing. After compaction, Counterparts puts your memory back: the hook re-delivers the wake, and what was said before the compaction is still written up. It has no Codex or Cursor version.
Questions? Ask in r/AIMemorySystems.
References
- Anthropic docs: Error reference, Troubleshooting, Settings reference: idleCompaction, autoCompactEnabled, Environment variables, Model configuration: auto-compact window, Explore the context window, How Claude Code works, Hooks: PreCompact, Manage sessions, Changelog
- Claude Code issues: #108089, #103708, #108785, #109439
- OpenAI docs: Configuration reference, Developer commands, Troubleshooting; Codex source at rust-v0.171.0
- Codex issues: #55076, #54226, #48232, #61679, #57806; OpenAI forum: ran out of room
- Cursor docs: Prompting: context usage, CLI slash commands; Cursor forum: 170370, 164211, 173036, 169734, 175612
- Reported by users (Reddit read through the Arctic Shift archive): r/ClaudeCode 1xse2po, 1xtmqf8, 1x84g8h; r/codex 1xfldeq; V2EX 1226477