CLClaude Lessons Try the free lessons

Claude Lessons / Guides

Claude Code Slash Commands: Every Command Explained

Slash commands are the fastest way to control a Claude Code session without writing a full sentence of instructions. Some ship with the CLI and cover housekeeping like clearing context or checking cost; others you write yourself to turn a multi-step ritual — "run the review checklist," "open a PR the way we always do it" — into three characters. This guide covers the built-in commands worth memorizing, then walks through writing your own with arguments and frontmatter.

Illustration of managing the Claude Code context window with slash commands

What a slash command actually is

Type a regular message and Claude treats it as a task to reason about. Type a message that starts with / and Claude Code intercepts it as a control instruction — clear the conversation, switch a setting, run a specific fixed prompt — before any model call happens for most built-ins. That distinction matters: slash commands are fast and predictable because many of them don't depend on the model interpreting your intent correctly.

Type / alone in a session to see the full menu with autocomplete, including any custom commands you or your team have defined. You don't need to memorize spelling — the typeahead does that part.

Session and context commands

These are the ones you'll reach for constantly once a session has been running a while:

CommandWhat it does
/clearWipes the conversation and starts a fresh context window — use between unrelated tasks
/compactSummarizes the conversation so far to free up context space while keeping the gist
/contextShows what's currently consuming your context window, broken down by category
/costReports token usage and estimated cost for the current session
/resumeReopens a previous session by name or picks from a list of recent ones
/rewindJumps the conversation and/or your files back to an earlier checkpoint
/exportExports the current conversation to a file

If context management feels like the actual skill here, it is — this is the same discipline behind keeping a session sharp, covered from the delegation angle in our subagents guide.

Configuration and setup commands

CommandWhat it does
/initGenerates a starter CLAUDE.md by scanning your project
/modelSwitches the model for the session (e.g. Sonnet vs. Opus)
/permissionsViews and edits what tools Claude can use without asking
/mcpManages MCP server connections and authentication — see our MCP guide
/agentsLists and manages available subagents
/hooksViews configured hooks — see our hooks examples guide
/output-styleChanges how Claude formats its responses (e.g. more concise, explanatory)
/statuslineConfigures a custom terminal status line
/memoryOpens CLAUDE.md files for editing directly
/add-dirGrants the session access to an additional directory outside the project root
/doctorDiagnoses installation and configuration problems

Commands are muscle memory — build it hands-on

Claude Lessons has 38 free interactive lessons that simulate a real Claude Code workspace, including lessons on context management and session hygiene — practice the workflow, not just the command list.

Start the free interactive lessons

Workflow commands

CommandWhat it does
/reviewRuns a structured code review of your current changes
/pr-commentsPulls review comments from an open pull request into the conversation
/todosShows the task list Claude is tracking for the current work
/bugReports a Claude Code bug directly from the session
/vimToggles vim key bindings for the input prompt
/ideConnects to a supported IDE for inline diffs and diagnostics
/login / /logoutSwitches or clears the authenticated account
/helpLists every available command, including custom ones

You don't need all of these on day one. /clear, /compact, /review, /model, and /help cover most daily use; the rest earn their place as your workflow gets more specific.

Write your own custom command

A custom command is a Markdown file whose filename becomes the command name and whose body becomes the prompt Claude runs. No code, no plugin system to learn — just a file:

mkdir -p .claude/commands
cat > .claude/commands/security-check.md << 'EOF'
---
description: Review the current diff for common security issues
allowed-tools: Read, Grep, Glob
---

Review the current git diff for SQL injection, hardcoded secrets,
missing input validation, and unsafe deserialization. Report each
finding with the file, line, and a suggested fix. If nothing is
found, say so explicitly — don't invent issues.
EOF

Save that, restart the session if .claude/commands/ didn't already exist, and /security-check shows up in the menu. Typing it runs the body above as if you'd pasted it in yourself — same context, same tools, same session.

Arguments: making a command reusable

A command that only ever runs the exact same prompt is limited. Accept input the way a shell script would, with $ARGUMENTS for the whole string after the command name, or $1, $2 for individual positional values:

---
description: Investigate and summarize a GitHub issue by number
argument-hint: [issue-number]
allowed-tools: Bash(gh issue view:*), Read, Grep
---

Fetch issue #$1 with `gh issue view $1`, then search the codebase
for the relevant code and summarize the likely cause in under
150 words.

Call it with /investigate-issue 482 and $1 resolves to 482. The argument-hint field shows placeholder text in the autocomplete menu so teammates know what to type without opening the file.

Frontmatter fields worth knowing

None of these are required — a bare Markdown file with no frontmatter works fine as a command — but each solves a real problem once you hit it:

Inside the body, !`command` runs a shell command and inlines its output before Claude sees the rest of the prompt — handy for pulling in git diff or git log automatically instead of asking Claude to run it as a separate step.

Personal vs. project vs. namespaced commands

LocationScopeNotes
.claude/commands/Project, sharedCommit to git so your whole team gets the same commands
~/.claude/commands/Personal, all projectsYour own shortcuts, not shared

Subdirectories create a namespace: a file at .claude/commands/frontend/component.md becomes /frontend:component. Use this once you have enough commands that a flat list gets confusing — grouping by area (frontend, release, review) keeps the autocomplete menu scannable.

Slash commands vs. subagents vs. skills vs. hooks

All four customize Claude Code's behavior, but they answer different questions:

A rough rule: if you have to remember to type something, it's a command. If you want it to happen automatically, it's a hook. If you want isolation from your main context, it's a subagent. Commands and subagents combine well — a custom command's body can explicitly tell Claude to delegate to a named subagent.

FAQ

What is a slash command in Claude Code?

A slash command is a control you type at the start of a message, like /clear or /review, that tells Claude Code to perform an action on the session itself rather than treating the text as a task. Some are built in; you can also write your own custom ones.

How do I create a custom slash command?

Create a Markdown file in .claude/commands/ (shared with your team via git) or ~/.claude/commands/ (personal, every project). The filename becomes the command name, optional YAML frontmatter can set a description, argument-hint, allowed-tools, and model, and the file body is the prompt Claude runs, with $ARGUMENTS or $1, $2 standing in for whatever you type after the command.

What's the difference between a slash command and a subagent?

A slash command runs in your current context, using whatever the session already has loaded. A subagent spawns a separate, isolated context window and returns only a summary. Use a slash command for a quick, repeatable action in the current conversation; use a subagent when you want verbose work kept out of your main context.

Can slash commands take arguments?

Yes. Anything you type after the command name is available in the command's body as $ARGUMENTS (the whole string) or as $1, $2, $3 for individual positional arguments, the same way a shell script reads its parameters.

Why isn't my custom slash command showing up?

Most often the .claude/commands/ or ~/.claude/commands/ directory didn't exist when the session started, and a running session only watches directories that existed at launch. Restart the session. Also check the file has a .md extension and that YAML frontmatter, if present, is valid.

Reading the command list ≠ having the workflow

The fastest way to make commands, context management, and delegation second nature is reps. Practice them in a simulated Claude Code workspace — free, in your browser, with instant feedback.

Practice hands-on in the free interactive lessons