Field notes for Claude Code users
How to control Claude Code context compaction
Auto-compaction is the moment a long Claude Code session summarizes its own history to stay under the context window. You cannot switch it off. What you can do is decide what survives it, when it happens, and where the conversation continues. Here is the full set of controls, what each one actually does, and the one the terminal hides from you.
The short answer (verified 2026-05-17)
There is no setting or flag that disables Claude Code auto-compaction. You control it three ways. First, steer what the summary keeps: run /compact with a focus, or add a Compact Instructions section to CLAUDE.md. Second, compact on purpose, before the window fills, instead of waiting for the wall. Third, fork the session (--fork-session or /branch) at a clean point so the original never has to compact. A true off switch has been requested repeatedly and, as of this writing, not shipped.
Why there is no off switch
The first thing most people try is the obvious one: open ~/.claude/settings.json, add "autoCompactEnabled": false, restart. It does nothing. The key is not in the settings schema, so it is parsed and silently discarded (issue #38483). A follow-up request to add a real autoCompact: false boolean was filed and closed as not planned (issue #42149).
Recent builds do expose an Auto-compact toggle inside the /config Settings panel. It works for the current session, but reports differ on whether it survives a restart, so treat it as a per-session switch rather than a permanent setting. The docs themselves are blunt about the design: Claude Code “manages context automatically as you approach the limit. It clears older tool outputs first, then summarizes the conversation if needed.” That automation is not something you configure away. So controlling compaction does not mean stopping it. It means steering it.
The control panel
Six things touch compaction. Five are real levers. One is the move that looks like a lever and is not. This is the whole panel:
/compact [focus]DocumentedControls
What the summary keeps
Run it yourself and pass a focus, like /compact focus on the API changes. The summary is written around what you named instead of a generic recap.
Compact Instructions in CLAUDE.mdDocumentedControls
Every future compaction
Add a section titled Compact Instructions to CLAUDE.md. It becomes a standing focus the summarizer applies each time it runs, automatic or manual.
/clearDocumentedControls
Whether you summarize at all
Starts a fresh context with nothing carried over. No lossy summary, because there is nothing to summarize. The old conversation stays in /resume.
--fork-session / /branchDocumentedControls
Where the conversation continues
Copies the history into a new session ID and leaves the original intact. Branch at a clean point and the parent never has to ride into a compaction.
/contextDocumentedControls
When you act
Draws a grid of what is filling the window. It does not change compaction, but it is the only built-in way to see the wall before you hit it.
autoCompactEnabled: falseNot availableControls
Nothing
The obvious move, turning it off in settings.json, has no effect. The key is not in the schema and is silently ignored. A real off switch has been requested and not shipped.
Lever one: steer what survives
A compaction is a summary. Left alone, it writes a generic recap and flattens the specifics, the file path you set once, the constraint from turn four, the decision the model made and never restated. The docs give you two ways to aim it: “add a Compact Instructions section to CLAUDE.md or run /compact with a focus.”
# Blind: a generic recap, you do not choose what it keeps /compact # Steered: the summary is written around what you name /compact focus on the auth refactor and the file paths we settled # Standing: applied to every compaction, automatic ones included # CLAUDE.md ## Compact Instructions Always preserve: chosen file paths, the DB schema decisions, and any constraint the user stated explicitly.
One subtlety worth knowing: skills are re-attached on a budget. After a summary, Claude Code re-attaches the most recent invocation of each skill and keeps the first 5,000 tokens of each, within a combined 25,000-token budget, filled most-recent-first. Invoke a lot of skills in one session and the oldest ones get dropped entirely at the boundary. The order you invoke skills quietly decides which ones survive.
Lever two: compact on purpose, before the wall
Automatic compaction fires when the session is already near the limit. By then the summarizer is squeezing a nearly full window into a paragraph, which is the worst possible moment to ask it to be selective. Running /compact yourself at a natural break, a task finished, a test suite green, gives the summarizer a cleaner cut and a smaller pile to compress. /clear is the same idea taken further: when the next task genuinely does not need the old context, drop all of it instead of carrying a summary you will not use.
There is also a failure mode worth recognizing. If a single file or tool output is so large that the context refills immediately after each summary, Claude Code stops auto-compacting after a few attempts and shows a thrashing error instead of looping forever. That is not a bug to fight, it is a signal: something oversized is in the window, and /context will show you what.
Lever three: fork instead of compact
The strongest control is structural. Compaction summarizes a session in place and keeps the same session ID. Forking, with claude --fork-session or the /branch command, copies the history into a new session ID and leaves the original untouched. The branch starts with the full prior context, not a paragraph about it.
That turns a long, doomed session into a chain of shorter ones. When a window approaches the limit, you fork at a clean point and continue on the branch. The parent never compacts, because you never run it into the wall. The work that mattered is carried forward as the model saw it, not as the summarizer rewrote it. The catch with the raw CLI: you have to know when to fork, and the terminal does not tell you the boundary is coming.
The control the terminal hides
The compaction boundary is an event you never see
Compaction is not silent at the protocol layer, only in the UI. The Claude Code SDK fires a system event with subtype compact_boundary the instant it decides to compact. The event carries two fields: a trigger (auto when the SDK decided, manual when you typed /compact) and a pre_tokens integer counting how much context was live at that moment. The terminal computes all of this and then shows you the finished summary. The event is discarded.
A host built on the Agent Client Protocol can forward the raw event instead. The open-source Fazm bridge, which runs the real Claude Code agent loop, does exactly that. In acp-bridge/src/patched-acp-entry.mjs (lines 99 to 105) the boundary is forwarded verbatim:
// acp-bridge/src/patched-acp-entry.mjs (lines 99-105)
if (subtype === "compact_boundary") {
await acpClient.sessionUpdate({
sessionId: sid,
update: {
sessionUpdate: "compact_boundary",
trigger: item.value.compact_metadata?.trigger ?? "auto",
preTokens: item.value.compact_metadata?.pre_tokens ?? 0,
},
});
}And every boundary is logged on the host side, in acp-bridge/src/index.ts around line 4381: Compact boundary: trigger=auto, preTokens=178432. None of this is invented data. The numbers come straight from the SDK. The only choice the host makes is whether to render them or throw them away.
What you can do about compaction depends on whether you can see it
Compaction is a status line that flickers and a summary that quietly replaces your history. You learn it happened when the model forgets a path you set an hour ago.
- No event you can hook before the summary lands
- The pre_tokens count is computed and then discarded
- You react after the loss, never before it
One-click fork: the boundary becomes a branch point
Once the boundary is visible, forking should not be a session-id dance. In the Fazm bridge it is one request. The handleForkSession handler in acp-bridge/src/index.ts (around line 3959) wraps the ACP session/fork RPC. An in-place fork swaps the current chat onto a new branch under the same window, while the parent session is left on disk and stays recoverable from the conversation history list. The branch carries the full prior context. No summary, no paragraph, no retyping.
That is the honest shape of controlling compaction. Nothing built on Claude Code can delete the boundary, because the SDK owns when it fires, and Fazm does not pretend otherwise. What changes is that the boundary stops being a wall you discover and becomes a branch point you choose. You compact deliberately, with a focus, or you fork before you ever need to. The terminal gives you the levers. A host that surfaces the event gives you the timing.
Want to see the compaction boundary instead of guessing at it
Fazm wraps Claude Code via the Agent Client Protocol in a native macOS app. Show me how you run long sessions and I will walk through where the boundary fires today and what changes when you fork at it.
Frequently asked questions
Can you turn off Claude Code auto-compaction?
Not as of May 2026. There is no documented setting or CLI flag that disables it. Setting autoCompactEnabled to false in ~/.claude/settings.json has no effect because the key is not in the settings schema and is silently ignored (GitHub issue #38483). A request to add a real autoCompact: false boolean was filed and closed as not planned (issue #42149). Recent builds expose an Auto-compact toggle in the /config Settings panel, but community reports say it does not reliably persist across restarts, so treat it as a per-session switch, not a permanent one. The honest position: you steer compaction, you do not disable it.
What does /compact with a focus actually do?
The docs describe /compact [instructions] as: free up context by summarizing the conversation so far, optionally pass focus instructions for the summary. Without a focus you get a generic recap. With one, like /compact focus on the API changes, the summarizer is told what to keep, so the specific facts you name survive the cut while unrelated history is flattened harder. It is the single most direct control you have over what a compaction preserves.
What is a Compact Instructions section in CLAUDE.md?
It is the standing version of /compact focus. The Claude Code docs say that to control what is preserved during compaction you can add a section titled Compact Instructions to CLAUDE.md, or run /compact with a focus. The CLAUDE.md section applies automatically every time compaction runs, including the automatic ones you did not trigger. If your sessions keep losing the same kind of detail, a file path convention, a constraint, a decision, that is where you pin it.
Does /clear count as controlling compaction?
It sidesteps it. /clear starts a new conversation with an empty context window, so there is nothing to summarize and no lossy paragraph replaces your history. The previous conversation is still available in the /resume picker. Use it when a task is genuinely finished and the next one does not need the old context. It is a blunt instrument: everything goes, not just the dead weight.
What happens to my loaded skills when context compacts?
Skills are re-attached after the summary, but on a budget. Per the Claude Code skills docs, when the conversation is compacted, Claude Code re-attaches the most recent invocation of each skill and keeps the first 5,000 tokens of each. Re-attached skills share a combined budget of 25,000 tokens, filled starting from the most recently invoked skill. If you invoked many skills in one session, the oldest ones can be dropped entirely after compaction. So the order you invoke skills quietly decides which survive.
How is forking a session different from compacting it?
Compaction summarizes the conversation in place: the old turns are replaced by a paragraph and the session ID stays the same. Forking, with claude --fork-session or the /branch command, copies the history into a new session ID and leaves the original unchanged. The branch starts with the full prior context, not a summary of it. Forking before the window fills is the only way to keep a long line of work going without ever paying the compaction tax on it.
Why can I not see compaction coming in the terminal?
Because the terminal renders the result, not the event. The Claude Code SDK fires a system event with subtype compact_boundary the instant it decides to compact, carrying a trigger field (auto or manual) and a pre_tokens count of how much context was live at that moment. The terminal computes that and shows you the summary instead. A host built on the Agent Client Protocol can forward the raw event so you see the boundary before the summary lands. The open-source Fazm bridge does exactly that.
Does wrapping Claude Code in a different host change the model or my plan?
No. A host that runs Claude Code through the Agent Client Protocol uses the same agent loop, the same Claude Pro or Max plan, the same tools and prompts. It cannot remove the compaction boundary either, since the SDK owns when compaction fires. What a host changes is everything around the event: whether the boundary is visible, whether forking is one click, whether sessions survive a restart. The model on the other end of the socket is unchanged.
Related field notes
Claude Code auto-compacting token waste, where the cost really is
The summary is cheap. The expensive part is retyping the facts the model just forgot. What the SDK emits at the boundary, and why fork beats the summary.
Claude Code context in long sessions: what survives and what does not
A long session loses context four different ways. Only one is a prompt problem. Here is what survives each, verified against the docs.
Claude Code context management on a Mac
The lever every guide misses: whether you send the screen as pixels or as an accessibility tree decides your token budget once Claude Code drives a GUI.
Comments (••)
Leave a comment to see what others are saying.Public and anonymous. No signup.