Slash commands and context management

Master Claude Code's built-in slash commands and the context window: when to /clear, when to /compact, and how to keep long sessions sharp.

Lesson 3.2โฑ 7 min read๐Ÿš— Daily driverโ“ 3-question quiz
The short answer

Claude Code has a context window: a limited working memory that fills up as you chat, read files and run tools. Use /clear to start fresh between unrelated tasks, /compact to summarise a long session, and /context to see what is using space.

What is the context window?

Everything in your session (your messages, Claude's replies, file contents, command output) sits in Claude's context window. It's large, but not infinite, and very long, noisy sessions can make Claude less focused.

Analogy: it's a desk. The more papers piled on it, the harder it is to find the one that matters.

The essential slash commands

  • /help: see available commands
  • /clear: wipe the conversation and start fresh (CLAUDE.md is still loaded)
  • /compact: summarise the conversation so far to free up space; you can add focus instructions, e.g. /compact keep the API decisions
  • /context: visualise what's using your context
  • /model: switch the model
  • /memory: view and edit memory files
  • /permissions: manage allow/deny rules
  • /resume: pick up a previous session

/clear vs /compact

  • /clear when you switch to an unrelated task. Old context would only distract.
  • /compact when you're mid-task and the session is getting long, but you need the gist of what's been decided.
Watch out: summaries lose detail. Exact numbers, IDs and decisions can get blurred. Before compacting, ask Claude to write key facts to a notes file (or CLAUDE.md) so they survive.

Claude Code also auto-compacts when the context gets close to full.

Pro habits for long sessions

  • One task per session where possible.
  • Use @ mentions instead of letting Claude read the whole repo.
  • Delegate noisy exploration to a subagent (Level 4) so only the summary returns.
  • Keep a scratchpad file of findings for big investigations.

Check yourself

Three quick questions to check it stuck.

Ask the tutor

Stuck on something in this lesson? Ask the AI tutor. It answers from this lesson and points you to others that help. Answers are written by AI and can be wrong. Do not include personal details, passwords or company secrets.

Frequently asked

What is the difference between /clear and /compact in Claude Code?

/clear starts a completely fresh conversation, ideal between unrelated tasks. /compact summarises the current conversation to free up space while keeping the gist, ideal mid-task.

Why does Claude Code get worse in long sessions?

The context window fills with old messages and tool output, which dilutes attention. Clearing, compacting, and delegating exploration to subagents keeps it sharp.

How do I see what is using my Claude Code context?

Run /context inside a session to see a breakdown of what is consuming the context window.