Claude Code commands

Manage Context in Claude Code: /clear, /compact

3 min read

Claude Code sends the whole conversation with every request, so a session left open all day draws usage for the entire history even on a one-line question. Four commands keep that under control.

1. See what’s filling the window

/context

What it does: visualizes current context usage as a colored grid — system prompt, memory files, skills, MCP tool definitions and the conversation. Run it before you guess; MCP servers and an oversized CLAUDE.md are the usual surprises.

2. Start fresh with /clear

/clear

What it does: starts a new conversation with empty context. Your project setup and CLAUDE.md still load; the chat history is gone. /clear also resets the session cost counter, and it costs nothing — unlike compaction.

Use it whenever you switch to unrelated work. Stale context wastes tokens on every subsequent message.

3. Shrink a long task with /compact

/compact focus on the auth refactor decisions and open TODOs

What it does: summarizes the conversation so far and continues with a much smaller context, keeping what you name. Claude Code also auto-compacts as you approach the limit.

Compaction reads everything it summarizes, so it is itself a large request. When you want a clean break rather than continuity, /clear is the cheaper move. You can set standing compaction instructions in your CLAUDE.md under a # Compact instructions heading.

4. Name it, then resume

claude -c    # continue the most recent conversation in this directory
claude -r    # pick an older session from a list

What it does: reopens a session after you close the terminal. Run /rename before you clear so the session is findable, then /resume to come back to it.

Verify it worked

Run /context again after compacting. If the grid barely moved, the space is going to something permanent — memory files, skills or MCP tool definitions — not to your conversation, and /compact will never fix it.

Rule of thumb: /clear between tasks, /compact within one. Everything you meet here is measured in tokens, which is also how it’s billed — track what a session costs. Two other habits help: keep a CLAUDE.md so a cleared session still knows your conventions, and push big searches into a subagent so the output never enters your main window.

Source: Manage costs effectively.

Open the full interactive version (with copy buttons) ↗

← All guides