Why does a Claude Code session stop with 'Autocompact is thrashing' after reading a huge log file, and how do you recover?
answer
- compaction worked, then refilled
- stops after a few attempts
- smaller reads, focused summary
- keep the big read elsewhere
basics
~20 sAuto-compaction succeeded, but an oversized file or tool output refilled the window after each summary, so Claude Code stopped retrying. Read in smaller chunks, run /compact with focus that drops the output, or use a subagent.
solid answer
~50 sThe error `Autocompact is thrashing: the context refilled to the limit...` means automatic compaction did its job, but a file or tool output immediately filled the window again, several times in a row. Rather than spend API calls on a loop that makes no progress, Claude Code stops auto-compacting after a few attempts and shows this error. The documented recovery is to ask Claude to read the oversized file in smaller pieces, such as a line range or one function; to run `/compact` with focus text that leaves the large output out, like `/compact keep only the plan and the diff`; or to move the large-file work to a subagent so it fills a separate window. Turning auto-compact off does not help, because a full window then simply stops the turn with the context-limit error.
go deeper
Recall that the thrashing error means one output is too big for the window, and that reading the file in smaller pieces is the first fix.
Explain the loop: compaction succeeds, the same oversized input refills the window, and Claude Code stops after a few attempts instead of looping.
Recover without losing the task: ranged reads, /compact with focus that drops the output, or a subagent for the scan, and check whether a model fallback shrank the window.
Treat repeated thrashing as a workflow signal: teams that scan logs or data dumps should default to search-first reads and delegated scans rather than tuning compaction settings.
## What the error means Claude Code compacts automatically as a conversation nears its limit: it clears older tool outputs, then summarizes the history. Normally that frees a large share of the window and the session continues. **Thrashing** is the case where it does not stay free: 1. the window fills, and auto-compaction summarizes the history; 2. the next step brings back something huge, such as a whole multi-megabyte log or an unfiltered command output; 3. the window is full again almost at once, and compaction runs again; 4. after a few rounds Claude Code stops and shows `Autocompact is thrashing: the context refilled to the limit...`. The important detail is that **compaction succeeded each time**. Nothing is wrong with the summarizer or your settings. The input is too big for the window in one piece, and Claude Code refuses to keep paying for summaries that are immediately undone. ## Recovery, in the order the docs give it - **Read in smaller chunks.** Ask Claude to read a specific line range, a single function, or a filtered view instead of the whole file. A search for the error string followed by a ranged read near each hit uses a fraction of the window. - **Compact with a focus that drops the output.** `/compact keep only the plan and the diff` tells the summary what matters, so the large output is not carried forward even as a description. - **Move the large-file work to a subagent.** A subagent reads in its own context window, and only its final report returns to yours, so a huge log costs the main session only the size of the report. ## What does not help | Tempting fix | Why it fails | |---|---| | `DISABLE_AUTO_COMPACT=1` | With the automatic pass off, a full window ends the turn with `Context limit reached · /compact or /clear to continue` | | A higher auto-compact window | The window is capped at the model's context size; the file still does not fit | | Retrying the same prompt | The same read refills the window the same way | | `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` | It can only make compaction trigger earlier, which does not shrink the input | `/clear` does free the window, but it also discards the summary of the work so far. Use it only if you would rather restart the task than continue it. ## A model fallback can shrink the window If a session falls back to another model, the effective window can drop, for example from 1M to 200K tokens, and content that fitted before suddenly does not. Since Claude Code 2.1.286 the thrashing error and the model fallback notice say when a fallback dropped the context window from 1M to 200K, so check the message before assuming the file itself grew. ## A worked recovery Say Claude was asked to find why a nightly job failed and pulled a very large application log into the conversation in one piece. 1. Do not repeat the request. Ask instead for a search for `ERROR` and the job name, then a read of fifty lines around each hit. 2. If the window is still crowded from the failed attempts, run `/compact keep only the job name, the failure time and the plan`. 3. If the scan needs to cover many files, ask Claude to hand the search to a subagent and report only the matching lines and timestamps. 4. Once the cause is found, record the useful command, such as the search pattern, in CLAUDE.md if the team will need it again. ## Preventing it - Prefer searches and ranged reads over whole-file reads of logs, generated code and data dumps. - Run `/context` before a big exploratory step to see how much free space remains. - Delegate broad scans to a subagent from the start when you expect large outputs. - Keep large reference material out of always-loaded files, so less of the window is spoken for before the read even starts. The broader design question of when an agent should compact is a context-engineering topic. In Claude Code, the practical rule is that compaction can only reclaim what is already in history; it cannot make a single input smaller than the window.
- Why does a Claude Code subagent stop the main session from thrashing on a huge file?The subagent reads the file in its own context window, and only its final message comes back to the parent, plus a small metadata trailer. The main window grows by the size of the report, not the file, so there is nothing oversized left to refill it after compaction.
- How does the Claude Code error look when the window fills with auto-compact turned off?The turn stops with `Context limit reached · /compact or /clear to continue`. When you turned auto-compact off in user settings, the line adds that auto-compact is off and points to `/config`. The hint is not shown when `DISABLE_AUTO_COMPACT` or `DISABLE_COMPACT` is what turned it off.
- Thrashing means the summarization request itself failed
- Claude Code keeps retrying compaction until the conversation fits
- Setting DISABLE_AUTO_COMPACT=1 lets the session work through the large file
- Raising the auto-compact window gives the oversized file room to fit
- /clear is the only way to recover from thrashing
Assumes Claude Code 2.1.286, the release whose thrashing error started saying when a model fallback dropped the window from 1M to 200K.