
Table of Contents
What this lesson is about
Claude Code comes with a set of built-in slash commands — short instructions that begin with a forward slash (/) and give you instant control over your session without interrupting your workflow. In this lesson you will learn what each command does, when to reach for it, and how two of them — /compact and /cost — can save you both money and frustration on longer working sessions.
Core concept: keyboard shortcuts for your session
If you have ever used a keyboard shortcut — pressing Ctrl+S to save instead of clicking File → Save — you already understand the idea behind slash commands. The long way works perfectly well. But when you are in the middle of something and need to act quickly, reaching for the shortcut keeps your hands on the keyboard and your mind on the task.
Slash commands work the same way. Instead of navigating through menus or settings panels to do things like check how much your session has cost, switch to a different model, or clear the conversation history, you type a single short command and it happens immediately.
They are not complicated. They do not require technical knowledge. They are simply fast, reliable shortcuts that put session control at your fingertips.
The complete reference: all key built-in commands
The table below covers every important built-in slash command you need to know. Each one is explained in plain English alongside guidance on when to reach for it.
| Command | What it does | When to use it |
|---|---|---|
/help | Displays a list of all available commands with brief descriptions | When you cannot remember a command or want to see what is available |
/clear | Wipes the entire conversation history and starts a completely fresh session | When you are done with one task and starting something completely unrelated |
/compact | Summarises the conversation history into a compressed overview and continues the session | When the session is getting long and you want to free up space without losing context |
/cost | Shows how many tokens the session has used and what it has cost so far | Any time you want to check your spend, especially on long or complex sessions |
/model | Switches the AI model being used — for example, from Sonnet to Haiku or Opus | When you want to trade off speed versus capability, or control costs mid-session |
/review | Asks Claude to review what has been done in the session so far and summarise the work | When you want a checkpoint summary before moving to the next phase of a task |
/bug | Opens a bug report so you can flag unexpected or incorrect behaviour to Anthropic | When Claude behaves in a way that seems wrong or broken |
/exit | Closes the Claude Code session | When you are finished and want to end the session cleanly |
The two most important commands: /cost and /compact
These two commands are worth understanding in depth, because they directly affect how efficiently — and how affordably — you work in Claude Code.
/cost — keeping track of what you are spending
Claude Code charges based on tokens — the units used to measure text. Every word you type, every word Claude generates, and everything in the conversation history that Claude has to keep in mind all counts towards your token usage. The more tokens used, the more the session costs.
The /cost command gives you an instant snapshot of where you stand. Type it at any point and Claude will display:
- How many tokens have been used so far in the session
- An estimate of the cost in dollars based on the current model’s pricing
This is particularly useful on longer working sessions, when you are working through a complex multi-step task, or when you want to confirm that a session has stayed within budget before continuing.
/cost
Claude’s response will look something like:
Session usage:
Input tokens: 14,320
Output tokens: 8,105
Estimated cost: $0.18
Model: claude-sonnet-4-20250514
Make it a habit to run /cost at natural breaks in your session — after completing a major task, before starting a new phase, or whenever you are curious. Awareness of your usage is the simplest form of cost control.
/compact — summarising history to keep going
Every conversation you have with Claude takes up space in what is called the context window — the amount of text Claude can hold in its working memory at one time. Think of the context window like a whiteboard in a meeting room. It has a finite amount of space. As the conversation grows longer, the whiteboard fills up. Once it is full, older content starts dropping off the edge to make room for new content — and Claude begins to lose access to earlier parts of your conversation.
/compact solves this problem before it becomes a crisis. When you run /compact, Claude reads everything in the conversation history, writes a compressed summary of the key decisions, context, and outcomes, and replaces the full history with that summary. The session continues uninterrupted — Claude still knows what has been agreed and what has been accomplished — but the whiteboard has been cleared and rewritten in shorthand, freeing up space for the next phase of work.
/compact
After running /compact, Claude will confirm that it has summarised the session and is ready to continue. You can immediately carry on from where you left off.
How /compact differs from /clear
These two commands both deal with conversation history, but they do very different things. Choosing the wrong one can cause you to lose important context.
/compact | /clear | |
|---|---|---|
| What happens to history | Summarised and compressed | Deleted entirely |
| Does Claude remember the session? | Yes — in compressed form | No — completely fresh start |
| When to use it | Mid-task, when the session is long but you are not finished | When you are starting something completely new and unrelated |
| Risk of losing context | Very low | Total — all history is gone |
A scenario for each
Use /compact when: You are three hours into a long planning session. Claude has helped you draft a project brief, outline a budget, and write three emails. The session is getting lengthy. You are not finished — you still need to create a summary document — but you are worried about the context window filling up. Running /compact keeps all that accumulated context in a compressed form and lets you continue.
Use /clear when: You just finished helping a colleague with a personal HR document using Claude Code. Now you want to start a completely different task — researching a new supplier. There is no reason for Claude to remember anything from the previous conversation, and in fact keeping it would just add noise. /clear wipes the slate completely so you start fresh.
How to use /model to switch between models mid-session
Claude Code gives you access to more than one AI model. Each model has a different balance of speed, capability, and cost.
| Model | Best for | Relative cost |
|---|---|---|
| Haiku | Simple tasks, quick answers, high-volume repetitive work | Lowest |
| Sonnet | Most everyday tasks — strong capability at reasonable cost | Moderate |
| Opus | Complex reasoning, nuanced writing, difficult analysis | Highest |
You can switch between these at any point in your session using /model:
/model
Claude will present the available models and ask you to choose. Once you select one, all subsequent messages in the session will use that model.
When switching models is useful
Imagine you are working on a large research task. You start with Sonnet — capable enough for most of the work. Partway through, you hit a complex analytical question that needs deeper reasoning. You switch to Opus for that section. Once you have your answer, you switch back to Sonnet — or even Haiku — to handle the simpler formatting and filing tasks at the end.
This approach — using the right model for each phase of a task rather than the same model throughout — is one of the most effective ways to manage costs without sacrificing quality where it matters.
A real session: slash commands in practice
The following is a realistic sequence of slash commands woven into a working session. It shows how these commands fit naturally into the flow of real work.
[Start of session — beginning a new project]
You: I need to draft a sponsorship proposal for an event we are hosting
in Cape Town in August. The sponsor is a fintech company.
Let's start with an outline.
Claude: [produces outline]
You: Good. Now expand section two into full paragraphs.
Claude: [produces expanded section]
You: /cost
Claude: Session usage — Input: 4,210 tokens | Output: 2,890 tokens
Estimated cost: $0.04 | Model: claude-sonnet-4-20250514
You: Let's keep going. Expand sections three and four.
Claude: [produces more content]
[The session has grown long — time to compress before the final push]
You: /compact
Claude: I've summarised the session. We have a complete sponsorship proposal
outline with sections one through four expanded. Ready to continue.
You: Now write the executive summary and the closing call to action.
Claude: [produces final sections]
[Final check before wrapping up]
You: /cost
Claude: Session usage — Input: 12,440 tokens | Output: 7,320 tokens
Estimated cost: $0.14 | Model: claude-sonnet-4-20250514
You: Save the full proposal to a file called
"sponsorship-proposal-cape-town-august.md" in a folder
called "events/proposals".
Claude: [saves the file and confirms the path]
You: /exit
Notice how the slash commands do not interrupt the work — they slot in naturally at the right moments. /cost at the midpoint gives you a sense of where you are. /compact before the final push keeps the context clean. /exit closes things neatly when you are done.
Practical Exercise
In this exercise you will practise using slash commands during a real working session.
a. Open Claude Code and start a new session. Give Claude a small but real task — something that will take three or four exchanges. For example:
Help me write a short welcome message for new staff joining my team.
It should be warm, practical, and no longer than two paragraphs.
Work through the task with Claude for at least three exchanges, refining the output.
b. Once you have had a few exchanges, type /cost and read the output. Note the token counts and the estimated cost. Then type /review and read Claude’s summary of what has been accomplished so far in the session.
c. Now start a second, completely unrelated task in the same session — something like asking Claude to suggest three names for a new internal newsletter. Before you begin, decide which command is appropriate: should you use /compact (to preserve context from the previous task) or /clear (because you want a completely fresh start)? Type your chosen command, then proceed with the new task. At the end, type /exit to close the session cleanly.
Common problems and how to fix them
I typed a slash command but nothing happened
Make sure you are typing the command at the beginning of a new message with no leading spaces. The command must start with / as the very first character. If you type /cost with a space before the slash, Claude will treat it as a regular message rather than a command.
/compact produced a summary that missed something important
The summary /compact creates is generated by Claude based on what it considers most relevant. If it omitted something you know you will need later, simply tell Claude directly after the compact:
One thing the summary missed: we agreed that the budget ceiling is
R150,000 and the deadline is 15 August. Please keep that in mind
going forward.
Claude will incorporate that correction into its working context immediately.
/clear wiped something I needed
Unfortunately, /clear cannot be undone — the history is gone once you run it. This is why it is worth pausing before using /clear to confirm you genuinely have no further use for the session content. If you were working on something important, consider running /review first to have Claude produce a summary, then save that summary to a file before clearing.
/model does not show the model I want
The models available to you depend on your Claude Code subscription tier. If Opus does not appear as an option, your current plan may not include access to it. Check your account settings or contact Anthropic support to confirm which models are available on your plan.
I used /compact but the session still feels slow or repetitive
/compact compresses the conversation history, but if the session has been running for a very long time with large amounts of generated content, the summarised version may still be substantial. If the session continues to feel sluggish after compacting, consider whether it makes sense to run /clear and start the next phase as a fresh session — copying any essential context into your opening message manually.
What you have learned in this lesson
- Slash commands are keyboard-shortcut-style controls that give you instant access to session management functions in Claude Code
/helplists all available commands;/exitcloses the session cleanly/costshows token usage and estimated spend at any point — a simple habit that keeps you in control of costs/compactcompresses the conversation history into a summary so you can continue working without losing context; it is the right choice when you are mid-task and the session is growing long/clearwipes the entire conversation and starts fresh — the right choice when you are starting something completely unrelated and have no need for the previous session’s content/modellets you switch between Haiku, Sonnet, and Opus mid-session so you can match the model’s capability and cost to each phase of your work/reviewgives you a checkpoint summary of what has been accomplished in the session so far- Slash commands fit naturally into the flow of real work — use them at logical pauses rather than as an interruption