ClaudeFolio
Tutorials

Why Claude Code forgets things mid-session

Edward Kwun··3 min read
Why Claude Code forgets things mid-session

See more of our writing in your Google results.

Key points

  • Long sessions get summarized, and summaries lose detail
  • Project CLAUDE.md, rules, and auto memory are re-read from disk
  • Path-scoped rules and nested CLAUDE.md files get summarized away
  • Instructions given only in chat do not survive compaction
  • /compact shrinks the thread, /clear throws it away
  • Run /context to see where your window actually went

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.

Found this article useful?

Add ClaudeFolio as a preferred source on Google to see our articles first.

FAQ

Why does Claude Code forget things mid-session?
Because long conversations get compacted. Claude Code replaces older history with a summary to free context space, and detail is lost in that summary. Anything you said only in chat can disappear, while CLAUDE.md is re-read from disk.
What is the difference between /compact and /clear?
/compact keeps the conversation and replaces it with a shorter summary, so use it when continuing the same task. /clear discards the conversation entirely, which is what you want when switching to unrelated work.
How do I stop Claude Code from losing my instructions?
Put them in your project-root CLAUDE.md, which is re-injected from disk after compaction. Instructions typed in chat, or kept in path-scoped rules, are summarized away and may not come back.

Related posts

Comments