Skip to content

Context Window Management

The context window is Claude’s working memory (~200K tokens standard; Sonnet 5 supports a native 1M window, and opus[1m] selects 1M for Opus). Everything competes for it: system prompt, CLAUDE.md, auto memory, tool schemas, file reads, tool output, conversation. Managing it well is the #1 skill separating intermediate from pro users.

What Loads at Startup (before you type anything)

Section titled “What Loads at Startup (before you type anything)”
ItemApprox. costNotes
System prompt~4K tokensAlways, invisible
Auto memory (MEMORY.md)variesFirst 200 lines / 25KB
CLAUDE.md filesvariesUser + project + local
Environment info~300cwd, platform, git status
MCP toolssmall if deferredFull schemas load on demand via tool search (ENABLE_TOOL_SEARCH)
Skill descriptions~20-60 eachBodies load only when invoked
/context

Shows a live breakdown of what’s consuming context. Run it when a session feels sluggish or before a big task.

ToolWhat it doesWhen to use
/clearEmpty context, fresh startSwitching to an unrelated task
/compact [focus]Replace history with summaryMid-task, context near full
/rewind → SummarizeCompress only part of the conversationVerbose debugging detour you’re done with
SubagentsVerbose work happens in a separate window; only summary returnsTest runs, doc fetching, log analysis

Rule of thumb: /clear between tasks, /compact within a task.

  • When context nears the limit, Claude Code auto-compacts: summarizes the conversation and continues. You’ll see a “context low” warning first.
  • Microcompaction silently trims old large tool outputs (file dumps, test logs) before resorting to full compaction.
  • What survives compaction: CLAUDE.md, system prompt, memory, the summary. What doesn’t: raw tool outputs, full message history (still in the transcript on disk).

Prompt Caching (why long sessions stay cheap)

Section titled “Prompt Caching (why long sessions stay cheap)”

Claude Code caches the conversation prefix with the API (5-minute TTL). Each turn only pays full price for new tokens. Implications:

  • Rapid iterations are cheap; a session idle >5 min re-reads everything uncached
  • Switching models (/model) invalidates the cache — the picker warns you
  • Big CLAUDE.md files cost you on every cache miss, not just once
  1. Keep CLAUDE.md lean (< ~150 lines); push detail into skills that load on demand
  2. Don’t paste huge files into chat — give paths and let Claude read selectively
  3. Ask for targeted reads: “read only the auth middleware section”
  4. Delegate log-heavy commands to subagents
  5. /context when in doubt; /clear liberally between tasks
  6. Watch the status line — configure it to show context usage (see 05-interactive-mode-shortcuts.md)

Real Case: Long Debugging Session Going Stale

Section titled “Real Case: Long Debugging Session Going Stale”

Symptoms: slow responses, Claude forgetting earlier decisions.

1. /context → 78% used, mostly old test output
2. /rewind → "Summarize up to here" on the point where debugging started
→ early exploration compressed, recent work intact
3. Continue with full precision on the actual fix

Alternative when the task is done: /clear, then start the next task with a one-line recap.

  • Trick: “Window = RAM, transcript = disk.”
  • Clear between tasks, compact within them.”
  • Show: /context before and after a big file read — make tokens visible.
  • They’ll trip on: the 5-minute cache TTL — a long lunch makes the next turn slow (that’s normal).

Learning path:08-sessions-and-checkpointing.md · Index · ➡ 10-plan-mode-and-thinking.md

Written by Fenil Patel