✻Founding-member pricing: every lesson for $19/mo. The first 3 lessons are free. Start lesson 1 →
Unit 1 · Claude Code Foundations · Lesson 5 of 40

Context Management: /context, /compact & /clear

Keep Claude sharp by managing the context window: read /context, steer /compact with focus instructions, and use /clear between unrelated tasks.

ACADEMY10 min+70 XP4-question quiz

🎯 By the end of this lesson you'll be able to

  • Read the /context grid and know what's using space
  • Compact with focus instructions
  • Know when to /clear instead of compacting
  • Use /btw for side questions that don't pollute history

Context is a budget

Every message, file read and command output takes up room in the context window. A focused context gives you sharper answers, faster turns and lower cost. A cluttered one gives you a confused agent that remembers the wrong things. Claude Code does a lot of this management for you, and auto-compaction kicks in when space runs low, but knowing three commands puts you in control.

/context: see what's in there

/context shows a grid of what's using space: system prompt and tools, memory files like CLAUDE.md, skills, MCP tools and the conversation. Use /context all for per-item detail, such as which CLAUDE.md files loaded and what each MCP tool costs.

✓
When to check

Check /context when a session feels slow or "forgetful", after connecting a new MCP server, or when your CLAUDE.md has grown. It's also the quickest way to confirm a file you expected actually loaded.

/compact: summarize and keep going

/compact replaces the conversation so far with a summary, freeing room while preserving the thread. Its superpower is focus instructions: tell it what matters.

text
/compact keep the final schema design and the list of failing tests; drop the exploration

After compaction, Claude Code re-reads your project-root CLAUDE.md, so standing instructions survive.

/clear: start fresh

/clear starts a brand-new, empty conversation. Use it between unrelated tasks. Finished the auth bug and moving on to the CSS refactor? /clear. Old context about auth would only distract. You can name the session you're leaving, as in /clear oauth-migration, and resume it later.

◎Compact or clear?pick the best fit
You're mid-way through a long refactor and context is 85% full.
You still need the thread. Summarize and keep going, with focus instructions.
You just merged a bug fix and are starting an unrelated feature.
The old task's details would only distract. Start fresh.
You corrected Claude twice and it's still going in circles.
After two failed corrections, a clean session with a better prompt usually beats more corrections.

/btw: the side-question trick

Need a quick answer ("what's the flag for verbose output again?") without stuffing it into your main thread? /btw asks a side question that isn't added to the conversation history.

text
/btw what's the difference between git merge --squash and rebase?

Habits of context pros

  • One task per session. Use /clear liberally. It's free.
  • Delegate heavy reading. "Use a subagent to find every caller of chargeCard" keeps hundreds of lines of search results out of your main context.
  • Don't paste giant logs. Save them to a file and let Claude grep it, or pipe them in: cat build.log | claude -p "why did this fail?"
  • **Keep CLAUDE.md lean.* It loads on *every request (Lesson 7).
⇄Flashcards4 cards
⌨Type the command+15 XP

Write the command that compacts the conversation while keeping the API design decisions

❯

Check your understanding

?Lesson quiz10 XP per correct answer · +25 for a perfect score
QUESTION 1 OF 4

When should you use /clear instead of /compact?

Why: /clear is for fresh starts. /compact keeps a summarized thread for the same task.
QUESTION 2 OF 4

What makes /compact far more useful?

Why: Focus instructions steer the summary so the important decisions survive.
QUESTION 3 OF 4

What does /btw do?

Why: Side questions stay out of your main thread.
QUESTION 4 OF 4

What's re-read automatically after compaction?

Why: Standing instructions in the project-root CLAUDE.md come back after compaction.
0 / 4 correct
Academy lesson

Unlock lesson 5 and the next 35

You've finished the free lessons. Join the Academy for $19/month to unlock every lesson, quiz, terminal simulation and puzzle, plus the final exam and your certificate of completion.

  • All 40 lessons across 9 units
  • 165+ quiz questions
  • Final exam + certificate
  • New lessons as Claude Code evolves
  • XP, streaks and badges
  • Cancel anytime

Already a member? Log in to continue.

Key takeaways

  • Context is a budget: focused context means sharper, cheaper turns.
  • /context shows usage; /compact summarizes with focus; /clear starts fresh.
  • Delegate heavy reading to subagents to protect your main thread.
  • One task per session is the simplest, strongest habit.

Nice work. Lesson 5 done?

Mark it complete to earn +70 XP, keep your streak alive and unlock badges.

Written by Curtis Cornell from Anthropic's public Claude Code documentation. Last reviewed November 14, 2026. Claude Code changes fast; if something here differs from your version, the official docs win.

Start lesson 1 free →