Skip to content

Context, Compaction & Resuming

From Inar's intro: the context window is large but finite, and everything competes for it — your instructions, every file read, every command output, every previous turn. Two practical consequences dominate real work.

1. Long sessions degrade, then compact

As a session grows, old detail gets in the way: the agent re-reads stale assumptions, attention spreads thin, and you pay (literally — tokens) to drag history along. Claude Code handles overflow by compacting: summarizing earlier conversation and continuing with the summary plus recent turns.

Compaction is lossy. You can be deliberate instead of letting it happen to you:

/compact focus on the fitting-code changes; the plotting discussion is done

Better still, put the important state in files, not in the conversation:

> Before we continue: write NOTES.md summarizing what we've established —
> the chosen parametrization, why we rejected the first approach, and the
> three open questions.

A conversation is working memory. The repo is long-term memory. Agents that write things down survive compaction; agents that don't, repeat their mistakes after it.

2. Sessions are resumable

Closed the terminal? Crashed? Next morning?

claude --continue        # pick up the most recent session here
claude --resume          # choose from past sessions

Combined with the NOTES.md habit, this makes multi-day agentic projects routine: each session starts by reading the notes, ends by updating them. (You'll recognize this as how humans run long experiments, too — the lab notebook pattern is older than the lab.)

The budget mindset

Cheap Expensive
Pointing at a file path Pasting the file into chat
A subagent reading 40 files The main agent reading 40 files
NOTES.md re-read at session start Re-deriving decisions in every session
Cached, stable system prompt Constantly shuffled instructions

CLAUDE.md is pinned context

A CLAUDE.md file at your project root is read at every session start — it's the place for things that must never fall out of context: conventions, cluster rules, "always run pytest before claiming success." More in Skills, MCP & Plugins.