Skip to content
ClaudeClaude

Context Management in Claude Code

Context is Claude's working memory, and managing it well is key to productive sessions. Learn when to use /compact vs /clear and practical tips for keeping your context window lean. Take the full course: claude.com/courses

May 18, 20263mWatch on YouTube ↗

At a glance

WHAT IT’S REALLY ABOUT

Optimize Claude Code memory using compaction, clearing, tools, subagents

  1. Claude’s context window is finite and fills up with prompts, file reads, tool calls, and tool results, so active optimization is necessary.
  2. Automatic or manual compaction (/compact) summarizes prior work and removes unnecessary tool outputs to free space, but it may lose some detail.
  3. Use /clear to fully reset when switching to a new feature to avoid bias from prior work, and use /context to inspect what’s consuming memory.
  4. Persist cross-session knowledge in claude.md so Claude doesn’t need to rediscover project facts repeatedly.
  5. Reduce avoidable context usage by being explicit in prompts, disabling unrelated MCP servers, using skills for lighter tool loading, and delegating research-like tasks to subagents with separate context.

IDEAS WORTH REMEMBERING

5 ideas

Treat context like scarce RAM: every interaction consumes it.

Prompts, file reads, tool calls, and their results all add to the context window, so long sessions can hit limits unless you manage what’s retained.

Use /compact when you must continue a feature but are running out of context.

Compaction summarizes what matters and drops low-value tool outputs, freeing space while preserving a workable memory of the current effort.

Use /clear when starting a new feature to prevent carryover bias.

Clearing removes prior conversation state entirely, which helps ensure the next feature’s approach isn’t influenced by outdated assumptions or irrelevant history.

Check /context to identify the biggest context “spenders.”

The context view provides size, category breakdowns, and a visual overview so you can target what to trim or avoid generating further.

Put durable, reusable facts in claude.md instead of re-teaching them every session.

Storing stable project knowledge (conventions, architecture notes, key commands) reduces repeated exploration and keeps future sessions efficient.

WORDS WORTH SAVING

5 quotes

Context is Claude's working memory. Every file it reads, every command it runs, every message you send, it all takes up space in the context window.

Unknown

And since there's only a finite amount you can put in the context window, it becomes extremely important to optimize this as much as possible.

Unknown

Compaction will summarize important details and remove the unnecessary tool call results and free up a lot of space in your context window.

Unknown

You don't want the previous conversation to present bias in anything new that you want to create.

Unknown

The irony behind writing a smaller prompt is that i- in the long run, it will take up more context.

Unknown

Context window as working memoryAutomatic vs manual compaction (/compact)Full reset with /clearInspecting usage with /contextclaude.md for persistent project memoryPrompt specificity vs context consumptionMCP servers, skills, and tool loadingSubagents with separate context windows

High quality AI-generated summary created from speaker-labeled transcript.

Get more out of YouTube videos.

High quality summaries for YouTube videos. Accurate transcripts to search & find moments. Powered by ChatGPT & Claude AI.