Part 2 · Lesson 7 of 16
Claude Code Slash Commands
Your first /command. Build a custom one.
12 min
Step 1 of 6 · What are slash commands?
Inside a Claude Code session you mostly talk to the agent in plain natural language. But some actions are about controlling the session itself — clearing context, switching models, opening settings — and for those you don't want the model to think, you want it to act instantly.
That's what slash commands are for. A slash command is a special instruction that starts with / and runs immediately. It's only recognized at the start of your message, and any text after the command name is passed to it as arguments. Type / on its own to see every command available to you.
Step 2 of 6 · Key built-in slash commands
Claude Code ships with a long list of built-ins. These are the ones you'll reach for most as a beginner:
/help— Show help and the list of available commands./clear— Start a new conversation with empty context. (Aliases:/reset,/new.)/compact— Free up context by summarizing the conversation so far, while continuing the same conversation./context— Visualize how much of the context window you're using right now./config— Open settings to change theme, model, and other preferences./init— Generate a starterCLAUDE.mdso the agent understands your project./agents— Manage subagents that Claude can delegate side tasks to./model— Switch the AI model for this session./exit— Exit the CLI. (Alias:/quit.)
Step 3 of 6 · Try a slash command (/help)
Let's run our first slash command. Open your terminal, navigate into your playground folder, and launch Claude Code:
claudeOnce the prompt is ready, type:
/helpPress Enter. You'll immediately see a formatted list of every available command and the keyboard shortcuts for your session — no AI round-trip required.
Step 4 of 6 · Reset vs compact your context
As a conversation grows, Claude carries everything you've said. A long chat eats context tokens, which makes the agent slower and pricier. You have two very different tools for this, and people mix them up constantly:
/clear(aliased to/resetand/new) wipes the slate. It starts a brand-new conversation with empty context — perfect when you switch to an unrelated task. Your project memory (CLAUDE.md) is kept; the chat history is not./compactkeeps you in the same conversation but replaces the long history with a short summary of the key facts, freeing up room while preserving your train of thought.
A simple rule: switching tasks → /clear; same task, running low on room → /compact.
/compactStep 5 of 6 · Build your own custom command
The real power is writing your own. In Claude Code, a custom command is just a Markdown file in .claude/commands/. The file name becomes the command name.
Create a file at .claude/commands/review.md in your project:
Review the staged git changes for bugs, unclear
names, and missing tests. List findings as a
short checklist — do not edit any files.Now, inside a Claude Code session in that project, run:
/reviewClaude runs the instructions in that file as if you'd typed them. Anything after the command name is passed along as arguments, so you can write commands that take input. Custom commands are now part of the broader skills system (a .claude/skills/review/SKILL.md would do the same thing) — but a single .claude/commands/*.md file is the fastest way to start.
Step 6 of 6 · Checkpoint & Recap
Recap
- Slash commands are instant, session-control instructions prefixed with
/, recognized only at the start of a message. /helplists every command;/contextshows how full the window is./clear(alias/reset) starts a fresh conversation;/compactsummarizes the current one to free space.- A custom command is just a Markdown file in
.claude/commands/— its filename becomes the/command.
Frequently asked questions
How do I reset Claude Code's context?
Run /clear (also available as /reset or /new). It starts a brand-new conversation with empty context while keeping your project's CLAUDE.md memory. If you instead want to stay in the same conversation but free up room, use /compact, which summarizes the history rather than discarding it.
What's the difference between /clear and /compact?
/clear throws the conversation away and starts over with nothing in context. /compact keeps the conversation going but compresses the earlier history into a short summary. Use /clear when you switch to an unrelated task; use /compact when you're deep in one task and running low on context.
How do I create a custom slash command in Claude Code?
Add a Markdown file under .claude/commands/ in your project — for example .claude/commands/review.md. The file name becomes the command (/review), and its contents are the instructions Claude runs. Custom commands are part of the skills system, so a .claude/skills/<name>/SKILL.md works the same way with extra options.
Does /bug fix bugs?
No. /bug is an alias of /feedback — it submits a bug report about Claude Code itself (with session context) to Anthropic. To fix a bug in your code, just describe it to the agent in plain language.