You're an hour into a session, Claude Code is going well, and then it starts forgetting. It re-reads a file it already read. It suggests a change you rejected twenty minutes ago. It loses a rule you set at the start. The conversation got long enough that Claude Code summarized the older part of it to make room, and the summary is weirder than the original. Knowing what that process keeps and what it throws away is most of what you need to work around it.
Compaction, and what comes back afterward
When a session approaches the context limit, Claude Code compacts: it replaces the conversation history with a structured summary. It happens automatically, so a full window doesn't end your session, and you can also trigger it with /compact.
Some things are restored from disk rather than summarized, which is the part worth memorizing. Your project-root CLAUDE.md and unscoped rules are re-injected from disk. So is auto memory, and the plan from plan mode. Claude Code also re-reads up to five files, the most recently modified first, though a file over 5,000 tokens comes back as a path reference rather than its content.
Other things do not survive intact. Rules with paths: frontmatter and nested CLAUDE.md files in subdirectories load into message history when a matching file is read, so compaction summarizes them away with everything else. They come back only when Claude reads a matching file again. The docs give the fix directly: if a rule must persist across compaction, drop the paths: frontmatter or move it to the project-root CLAUDE.md.
That explains the most common version of this complaint. An instruction you gave in chat is gone, because chat is exactly what got summarized. An instruction in your project CLAUDE.md is still there, because that file is re-read. If you find yourself re-typing the same correction after every compaction, it belongs in the file, not in the conversation.
/clear and /compact are not the same tool
People use these interchangeably and they do opposite things.
/compact keeps the thread and shrinks it. Use it when you're still working on the same problem and just need room. It takes an argument, which almost nobody uses: /compact focus on the auth bug fix tells the summary what to prioritize instead of letting the automatic pass guess.
/clear throws the conversation away and starts fresh. Use it when you switch to unrelated work. The docs are blunt about why: old conversation crowds out the files you need next and costs tokens on every message. A session that drifted from a database migration to a CSS bug is carrying the migration in every request.
Two more controls worth knowing. /rewind can summarize part of a conversation rather than all of it, with Summarize from here and Summarize up to here. And /autocompact with a token count, like /autocompact 500k, sets how full the window gets before the automatic pass runs, so you can compact earlier and on your terms.
Stop guessing and run /context
There's a command that shows where your window actually went: /context gives a live breakdown by category with optimization suggestions, including which CLAUDE.md and auto memory files loaded.
Run it once on a project you use daily. Most people find something surprising, usually a CLAUDE.md that grew past the point of usefulness, or memory files they forgot they had. The docs recommend targeting under 200 lines per CLAUDE.md, since longer files consume more context and reduce adherence.
The habit that costs the least and helps the most is delegation. Send big research tasks to a subagent so the file contents stay in its window instead of yours. Reading six files to answer one question is how a window fills at speed, and a subagent hands back the answer without the raw material.
And if your model supports it, a larger window changes the arithmetic. Fable models, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. Compaction works the same way at the larger limit; it just arrives later.
Sources
Claude Code docs: Explore the context window - What loads at startup, automatic compaction as the window fills, the table of what survives compaction including project-root CLAUDE.md, unscoped rules, auto memory and plan re-injection from disk, path-scoped rules and nested CLAUDE.md files being summarized away, re-reading up to five recently modified files with the 5,000-token reference cutoff, /compact with focus instructions, /clear between unrelated tasks, /autocompact token settings, /context for a live breakdown, delegating large reads to subagents, and 1 million token context support.






