Why Claude Code Seems to Forget: The Hidden Auto‑Compact Mechanism Explained

The article demystifies Claude Code's auto‑compact feature, showing how context limits trigger automatic summarization that discards most historic data, which parts survive compression, and practical strategies—including file persistence, directive‑based compaction, child agents, and proactive clearing—to keep critical information alive during long sessions and interview discussions.

Wu Shixiong's Large Model Academy
Wu Shixiong's Large Model Academy
Wu Shixiong's Large Model Academy
Why Claude Code Seems to Forget: The Hidden Auto‑Compact Mechanism Explained

1. What the context contains

A Claude Code session stores several layers: a system prompt (several thousand tokens), environment information (working directory, OS, git status), configuration files such as the project‑root CLAUDE.md , the first part of MEMORY.md , skill descriptions, and MCP tool names. These are injected at session start and occupy roughly ten thousand tokens. Above them lies the dynamic layer that grows with each user query, Claude reply, file content read, and tool call result. The default token limit is 200 k (some models allow up to 1 M). Large tool outputs—e.g., a full npm test log or an entire file—can quickly consume this budget.

Context composition: static base + dynamic growth
Context composition: static base + dynamic growth

2. When auto‑compact triggers and what it does

Auto‑compact activates automatically when the context approaches the token ceiling; it can also be invoked manually with the /compact command. The core action is to replace the lengthy dialogue history with a structured summary. First, it removes the most space‑hungry old tool outputs; if space is still insufficient, it then summarizes the remaining conversation. The summary typically occupies just over one‑tenth of the original token count.

What is kept : high‑density items essential for continuing work—initial requirements, discussed technical concepts, edited files and key code snippets, encountered errors and their fixes, pending tasks, and the current activity.

What is discarded : low‑density, regenerable content—full tool outputs (e.g., complete logs or file texts), exploratory reasoning steps, and verbatim dialogue.

Auto‑compact trigger and compression: what is kept, what is dropped
Auto‑compact trigger and compression: what is kept, what is dropped

3. Post‑compression survival rules

Files that exist on disk are re‑read after compression and therefore survive: the project‑root CLAUDE.md and the automatic memory file MEMORY.md . In contrast, CLAUDE.md files located in sub‑directories and rule files that depend on a specific path are lazily loaded; once compressed they disappear until Claude later accesses the corresponding directory. Unused skill descriptions are also removed from the context, meaning a skill that has not been invoked will no longer be visible to the model until it is referenced again.

4. How to mitigate forgetting

Persist key conclusions and decisions in the project‑root CLAUDE.md or in MEMORY.md so they are re‑injected after every compression.

Give the /compact command a directive (e.g., "keep the detailed algorithm change") to bias the summary toward specific information.

Isolate massive outputs with a child agent; the child returns only a concise summary to the main session, preventing the main context from filling up.

Proactively clear the context with /clear before the token budget is exhausted, then continue in a fresh session.

5. Practical habits for long sessions

Use /clear when switching to an unrelated task to start with a clean context.

Run /context (and /usage) to see which parts consume tokens and to identify large file reads that need trimming.

Offload repetitive, large‑output work to a child agent or preprocess it with a hook that keeps only the useful fragments.

Always write critical decisions to a file immediately; this habit ensures the information lives in the compression‑resistant zone.

6. Interview answer outline

When asked about Claude Code's auto‑compact, answer in four steps:

State the trigger (near the 200 k token limit) and the action (replace history with a summary; manual /compact possible).

Explain what is kept (requirements, key code, errors, tasks) and what is dropped (full tool output, exploratory reasoning, verbatim dialogue).

Describe the survival rule: project‑root CLAUDE.md and MEMORY.md survive; sub‑directory files and unused skills disappear until re‑loaded.

Emphasize proactive management: use /clear, /context, child agents, and persist important info in files.

Also clarify that /compact compresses the current session while keeping history in summarized form, whereas /clear starts a brand‑new session (old history can be recovered with /resume). Note that there is no "micro‑compact" mechanism; the only granularity is the internal step of discarding tool output before summarizing.

Conclusion

Auto‑compact is a clever safety net that trades about 90 % of historic tokens for a concise summary, allowing the session to continue. Understanding precisely what is retained, what is lost, and which artifacts are re‑injected after compression lets users place critical information in the compression‑resistant zone and avoid the illusion that the model has become “dumber”.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Prompt Engineeringinterview preparationContext ManagementClaude Codeauto-compact
Wu Shixiong's Large Model Academy
Written by

Wu Shixiong's Large Model Academy

We continuously share large‑model know‑how, helping you master core skills—LLM, RAG, fine‑tuning, deployment—from zero to job offer, tailored for career‑switchers, autumn recruiters, and those seeking stable large‑model positions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.