Guides / Claude Code context.

1191 words | Esment

Claude Code context.

What takes up Claude Code’s context window, what survives /compact, what each new session starts with, and how to keep knowledge between sessions.

╌╌╌╌

Long Claude Code sessions tend to go the same way. The first hour is sharp. Then Claude asks something you already answered, ignores a rule you gave early on, or redoes work it finished an hour ago. Nothing is broken: the context window filled up and was compacted, and what you said in conversation did not all survive. Knowing what lives where makes this predictable.

What fills the context window

Anthropic’s documentation lists it: the context window “holds your conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills, and system instructions” (Claude Code docs). Every file Claude reads and every command output it sees stays in the window until something removes it. A few large test logs can use more space than the whole conversation.

Run /context to see the breakdown for your session. Two things cost less than people expect: MCP tool definitions are deferred and loaded on demand, so “only tool names and server instructions consume context until Claude uses a specific tool”, and skills show only their descriptions until one is used.

Loaded whenSurvives /compactIn the next session
Your messages and Claude’s repliesAs you talkAs a summaryNo
Files read, command outputWhen Claude uses a toolAs a summary at bestNo
Project-root CLAUDE.mdSession startYes, re-read from diskYes
Nested CLAUDE.md, path-scoped rulesWhen Claude touches matching filesReload on demandYes, on demand
Auto memory (MEMORY.md)Session start, first 200 lines or 25KBYesYes
SkillsDescriptions at start, body when usedBody only if used againDescriptions
A subagent’s workIn its own windowOnly its summary was hereNo

What compaction keeps and what it drops

As the window approaches its limit, Claude Code compacts: it replaces the conversation with a summary. Per the docs, “the summary keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost.” That sentence explains most of the moments when Claude seems to forget a rule.

The project-root CLAUDE.md is the exception. After /compact, “Claude re-reads it from disk and re-injects it into the session” (memory docs). So an instruction that disappeared after compaction was almost always given only in conversation. Anthropic’s advice is direct: put persistent rules in CLAUDE.md rather than relying on conversation history.

Rules load into every chat; the chat itself does not carry over; search and a memory server reach back only when the agent uses themCHAT 1CHAT 2CHAT 3RULES,AGENTS.MDLOADED INTO EVERY CHAT, AUTOMATICALLYTHE CHATITSELFCHATSEARCHIF THE AGENT SEARCHESMEMORYSERVERSAVERECALLWHEN THE AGENT CALLS IT · OTHER TOOLS CAN USE IT TOO

Steer what compaction keeps

  • Compact on your terms. Run /compact after finishing a subtask instead of waiting for the automatic one in the middle of the next.
  • Give it a focus: /compact focus on the API changes tells the summary what matters.
  • Add a “Compact Instructions” section to CLAUDE.md with what every summary must keep, such as the current goal and decisions made.
  • Start fresh for unrelated work. /clear empties the window; a new task rarely needs the last one’s file reads.
  • Send exploration to subagents. They work in their own window and return a summary, so their file reads never enter yours.

What a new session remembers

“Each new session starts with a fresh context window, without the conversation history from previous sessions.” Two built-in things carry over: your CLAUDE.md files, which you write, and auto memory, notes Claude writes itself in ~/.claude/projects/<project>/memory/. Only the first 200 lines or 25KB of its MEMORY.md index load at start; topic files are read when needed. Auto memory is machine-local, so it does not follow you to another computer or a cloud session.

claude --continue and --resume reopen an old session with its full history, which brings back the conversation but also its size. Resuming is for picking up the same task, not for carrying knowledge into new ones.

Where CLAUDE.md stops being enough

CLAUDE.md is the right home for things a person has reviewed: how to build, how to test, conventions. Anthropic suggests keeping each file under 200 lines, because “longer files consume more context and reduce adherence”, and every line is paid for in every session. Decisions, findings and the state of work in progress change too often for that, and they pile up fast. Our comparison of CLAUDE.md and a memory server goes through what belongs where.

A memory server holds the rest outside the window, and Claude fetches only what the current task needs. The weak point is the same as with any tool: Claude has to decide to call it. Hooks close that gap. A SessionStart hook can add context when a session begins, a UserPromptSubmit hook can add it alongside each prompt, and a PreCompact hook runs just before compaction. Because hooks run at fixed moments whatever the model intends, recall stops depending on Claude remembering to look.

How Esment handles it

Esment is our memory engine, so take this as a description from the people who build it. Claude Code connects to it over MCP in one click from the Mac app, and the optional Claude Code hooks card sets up hooks for you. When a session starts, Esment adds a short brief of what matters: the current project, recent decisions, pinned facts. On each prompt it adds the memories relevant to that prompt. Before compaction it asks the summary to keep the memory block intact, and right after a compaction it does not add the brief again, since the model already has it. When a session ends, Esment reads the transcript and saves the facts and decisions worth keeping, which are then there for the next session, and for Cursor, ChatGPT or any other assistant you connect.

The result is that CLAUDE.md can stay short and reviewed, the conversation can be compacted or cleared without losing what was decided, and a new session starts from what you know instead of from nothing. Connecting Claude takes a few minutes, and sharing memory between Claude Code and Cursor covers using both.

Give Claude Code a memory →

Common questions

In:

How do I see how much context Claude Code is using?

Out:

Run /context in the session. It shows what is using space: system instructions, CLAUDE.md, memory, tools, skills and the conversation.

In:

Does Claude Code forget after /compact?

Out:

Partly. Compaction replaces the conversation with a summary that keeps your requests and key code, but detailed instructions given early in the conversation may be lost. The project-root CLAUDE.md is re-read from disk after compaction, so rules written there survive.

In:

Does Claude Code remember previous sessions?

Out:

Not the conversation. Each session starts with a fresh context window. CLAUDE.md files and auto memory carry over, and a memory server connected over MCP can bring back decisions and facts from earlier sessions.

In:

What is the difference between /compact and /clear?

Out:

/compact replaces the conversation with a summary and keeps working on the same task. /clear empties the conversation entirely, which suits starting unrelated work. CLAUDE.md and auto memory load again either way.

Written by the team that builds Esment, so we are not a neutral party. Tools change quickly: check each one before you rely on it.

Get the next chapter by email.

One email per new chapter. Nothing else.

0.00