All insights

Coding agents

Claude Code Auto-Compact: What It Does and How It Differs From API Compaction

Learn what Claude Code auto-compact does, how to adjust its window, what historical failure reports do—and don’t—show, and how separate beta compaction features work in the Claude API.

Illustration for Claude code auto-compact

Claude Code auto-compact summarizes session history to free context as a conversation grows. It is a Claude Code session-management feature; it is not the same thing as compaction in an application you build with the Claude API. Anthropic documents manual compaction with /compact and lets you tune the auto-compact window with /autocompact—for example, /autocompact 500k. Don’t assume one fixed trigger applies to every setup. (Claude Code context-window guide; Claude Code commands)

What auto-compact does—and what not to assume

A session’s context can include instructions, files Claude reads, responses, and other content. When a long session compacts, Claude Code summarizes conversation history to fit the context window. Anthropic notes that what happens to different kinds of content depends partly on how they were loaded. Treat the summary as a continuity aid, not a guarantee that every earlier detail or instruction will remain intact. (Claude Code context-window guide)

The trigger is adjustable: the current documentation gives /autocompact with a token count as a way to set how full the context window gets before automatic compaction. For deliberate compaction, /compact summarizes the conversation; /context shows what is using the window. Anthropic also documents guiding what a summary emphasizes by adding a “Compact Instructions” section to CLAUDE.md or giving /compact a focus, such as /compact focus on the API changes. (Claude Code context-window guide; How Claude Code works)

Keeping task state reliable

For a long coding task, keep important state somewhere you can inspect rather than relying only on chat history. One practical workflow is to record the goal, decisions, blockers, and verification steps in project files, then ask Claude to restate the goal, changed files, remaining work, and checks to run after compaction. Compare that recap with your plan and git diff before continuing. This is workflow advice from a Claude Code compaction guide, not a guarantee that a summary is complete.

Reported failures and current status

A GitHub issue opened in January 2026 was originally about Claude.ai web and desktop, not Claude Code. Later comments in that thread separately describe Claude Code problems. For example, one commenter reported that /compact failed after a context-limit message on Claude Code v2.1.45 in a macOS terminal in February 2026. These are historical, individual reports—not proof that all users or versions were affected. The thread does not establish Claude Code’s current status or a confirmed fix. (GitHub issue #18866)

Does Claude Code auto-compact apply to the production Claude API?

Not as the same Claude Code setting. Claude Code is the layer that manages the context its model sees. Anthropic separately documents two API compaction approaches, and its overview marks both as beta: on-demand compaction, where your application requests a summary, and threshold compaction, where the API compacts when a configured token trigger is reached. Each has its own beta header and integration flow. (Anthropic compaction overview)

For on-demand compaction, the API returns a signed compaction block. Anthropic’s instructions say to send that block in later requests exactly as returned. They also say to check model support through the Models API using the relevant beta header and the model’s capabilities.compaction field. These are API-specific requirements; they do not mean that Claude Code’s auto-compact setting controls an API application. (On-demand compaction documentation)

So API compaction is a documented option to evaluate for a production integration, but it is beta and model support must be checked for the particular API feature. Don’t choose a model solely because Claude Code has auto-compact; verify the API capability and consider the rest of your application’s requirements.

Bottom line

Claude Code auto-compact summarizes session history to make room, and /autocompact lets you tune its window. Use /compact for a deliberate summary and /context to inspect context usage; preserve important task state in project files and check a recap rather than assuming nothing was lost. For production API work, assess Anthropic’s separate beta compaction flows and verify model eligibility instead of assuming Claude Code behavior transfers to the API.

Sources

Explore the context window — Claude Code Docs

Commands — Claude Code Docs

How Claude Code works — Claude Code Docs

Compaction overview — Claude Platform Docs

Compaction on demand — Claude Platform Docs

Compaction at a token threshold — Claude Platform Docs

Compacting Claude Code Sessions

Auto-compact issue and user reports

Contact us