Huny's Dev Blog
huny.dev

Claude Code Auto-Compaction: Preserve Work Constraints When Context Is Summarized

Understand what Claude Code reloads or summarizes during auto-compaction, configure the window, and verify work before continuing.

Hun Jang
Hun Jang Dec 5, 2026

When Claude Code automatically compacts a long session, it replaces the conversation with a summary. Work can continue, but details supplied only in chat are not guaranteed to survive verbatim. Put important constraints in project instructions, and recheck the goal and verification state before and after compaction.

A generated conceptual illustration of a long work history folded into a smaller bundle. It is not a product screenshot.

Documentation checked: December 5, 2026. The commands below explain the official documentation; Claude Code was not run in this environment to verify them.

What auto-compaction does and what survives

The context contains not only conversation, but also files read, tool output, and instructions. As space fills, Claude Code replaces conversation history with a structured summary. Official context guide

According to the documentation, system instructions, the project-root CLAUDE.md and unscoped rules, and auto memory are among the items re-injected after compaction. Conversation is summarized, so individual details are not guaranteed to survive. Compaction alone does not undo code or changes written to disk, but it also does not prove the model currently understands those files correctly.

Information
After compaction
Practical check
Root CLAUDE.md and unscoped rules
Re-injected from disk
Check content and scope
Decisions and errors in conversation
Summarized
Recheck paths, open issues, and failed tests
Repository files
Files remain on disk
Inspect git diff and run tests

Consult the official survival rules for your environment and version.

Manual compaction and the automatic window

Use /context to inspect context use, and give /compact a focus at a natural task boundary. This illustrative command asks the summary to retain specific information:

/autocompact adjusts the window used for automatic compaction. In the current documentation, /autocompact 500k saves a value for the current model in user settings for this and later sessions. /autocompact auto returns to the model-specific automatic value. Higher-priority managed settings or an environment variable can cause a different value to apply. Settings and precedence

For one launch, use claude --autocompact 500k. In scripts, CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 takes precedence over the command and flag when the value is valid. Numeric parsing differs: environment value 200 means 200 tokens and is subject to the minimum, whereas /autocompact 200 means 200,000 tokens. The effective window cannot exceed the model context limit.

Defaults vary by version, model, and runtime. The official documentation says some native 1M models use an approximately 400K window by default, with compaction potentially occurring around 367K. Scheduled tasks and resumed sessions are among the exceptions. Check /autocompact in your session rather than assuming one threshold applies everywhere. Idle compaction is separate, so that number is not the only possible trigger.

Checks before and after compaction

  1. Put lasting repository rules in an appropriately scoped CLAUDE.md. Do not put secrets there.
  1. Record the current goal, changed files, failed tests, and remaining work in a working note. You can also focus the summary as in the /compact example above.
  1. After compaction, ask for the goal, next steps, and constraints, and compare them against the working note.
  1. Inspect git status and git diff, then rerun tests appropriate to the changes. A summary saying tests passed does not prove the current code passes.

A large file or tool response can refill the window immediately after compaction and cause repeated compactions. Consult the official troubleshooting guide and reduce the amount of input. This article describes a workflow based on official documentation; it does not measure cost savings or recall accuracy for a particular model.

한국어: Claude Code 자동 압축: 컨텍스트 요약 후 중요한 작업 조건 지키기Claude Code 자동 압축: 컨텍스트 요약 후 중요한 작업 조건 지키기

추천 글