cheat sheet

Claude Code Slash Commands

Complete reference for every built-in Claude Code slash command — session control, context management, configuration, tools, MCP, and authoring custom commands with arguments.

Claude Code Slash Commands

What it is

Slash commands are shorthand triggers typed at the Claude Code interactive prompt as /<name>. They invoke built-in features (session control, context inspection, configuration), call user-defined Markdown commands (.claude/commands/<name>.md), or, when a plugin/skill registers them, hand off to the skill's instructions. They are the primary way to issue meta-instructions to Claude Code without consuming those instructions as part of a task prompt — the harness intercepts the slash, expands the command body, and routes the resulting message into the session.

How slash commands resolve

When you type /foo, Claude Code resolves the name in priority order: built-in first, then project commands in .claude/commands/, then user commands in ~/.claude/commands/, then plugin-registered skills. The first match wins. Tab-completion lists all matches across all sources.

text
> /<TAB>
/help    /exit    /clear    /compact    /config    /model    /memory
/mcp     /cost    /status   /doctor     /review    /deploy   /pr-review

Output: (none — autocomplete dropdown opens)

Session control

Session-control commands manage the lifecycle of the current REPL — exiting, clearing, compacting, and resetting state.

CommandWhat it does
/helpShow available commands and keyboard shortcuts
/exit or /quitEnd the session
/clearDiscard all conversation history and start blank
/compactSummarize conversation history to free context window space
/resetAlias for /clear
/initGenerate a CLAUDE.md from the current project
text
> /clear

Output:

text
Session cleared. Starting fresh.
text
> /compact

Output:

text
Compacted 61,970 tokens of history into a 4,210-token summary.
Context window: 22,550 / 200,000 (11%) used.

Use /compact instead of /clear when you want Claude to remember what it has done so far but the conversation is getting long. /clear wipes everything; /compact keeps a condensed summary.

Context and memory

These commands operate on Claude's persistent memory (CLAUDE.md files) and on the running context window.

CommandWhat it does
/memoryOpen the global ~/.claude/CLAUDE.md file in $EDITOR
/memory projectOpen the project-level CLAUDE.md
/contextShow a summary of current context window usage
/add-dir <path>Extend filesystem access to another directory
text
> /context

Output:

text
Context window: 84,310 / 200,000 tokens used (42%)
  System prompt + tools: 18,200
  CLAUDE.md (project + global): 4,140
  Conversation:               61,970
text
> /add-dir ~/Code/shared

Output:

text
Added /home/alice/Code/shared to filesystem scope.

Configuration

Configuration commands inspect or modify settings without leaving the session. /config opens the active settings.json; /model swaps the active model; /permissions lists effective allow and deny rules.

CommandWhat it does
/configOpen or show the active settings (project + user)
/modelShow the active model
/model <id>Switch model for the rest of the session
/permissionsShow current tool permission rules
text
> /model

Output:

text
Active model: claude-sonnet-4-6
text
> /model claude-opus-4-7

Output:

text
Active model is now claude-opus-4-7.

Supported model IDs include claude-opus-4-7, claude-sonnet-4-6, and claude-haiku-4-5. Use the full versioned ID (e.g. claude-haiku-4-5-20251001) to pin a specific snapshot.

Bug reporting and status

These commands surface diagnostic information about the current session and your account.

CommandWhat it does
/bugReport a bug to Anthropic with session context attached
/statusShow account status, usage tier, and active model
/costShow estimated cost of the current session
/versionShow installed claude-code version
text
> /cost

Output:

text
Session cost: $0.23
  Input tokens:  48,320
  Output tokens: 6,140
  Cache hits:    31,200 (saves ~$0.09)
text
> /status

Output:

text
Account:      alice@example.com
Plan:         Pro
Active model: claude-sonnet-4-6
This month:   $14.27 of $100 cap

Doctor and diagnostics

/doctor runs an environment health check — API key, Node version, network connectivity, MCP server liveness. Useful when something is failing and you need a quick "is it me or the network" answer.

text
> /doctor

Output:

text
✅ API key found (ANTHROPIC_API_KEY)
✅ Node.js 22.2.0
✅ npm 10.7.0
✅ @anthropic-ai/claude-code 1.3.0
✅ API connectivity: OK
✅ MCP servers: 3 connected, 0 disconnected

MCP server management

MCP commands manage Model Context Protocol servers — adding, removing, listing, and inspecting them. The same operations are also available via claude mcp ... on the command line for use in scripts.

CommandWhat it does
/mcpList connected MCP servers and their status
/mcp add <name> <command>Add a new MCP server
/mcp remove <name>Remove an MCP server
/mcp restart <name>Restart an MCP server
/mcp tools <name>List tools exposed by a specific server
text
> /mcp

Output:

text
Connected MCP servers:
  github      (8 tools)   ✅
  postgres    (3 tools)   ✅
  memory      (2 tools)   ✅

See MCP Servers for full configuration details.

Mode switching

CommandWhat it does
/vimToggle vim keybindings in the input prompt
/fastToggle Fast mode (lower latency, slightly weaker model)
/thinkForce the next response to use extended thinking
/no-thinkDisable extended thinking for the next response
text
> /vim

Output:

text
Vim mode enabled. Press Escape for normal mode.

Subagent commands

Subagent commands spawn an isolated agent for a specific task — see Subagents for full details on the underlying Task tool.

CommandWhat it does
/agentsList configured subagent definitions
/agents create <name>Open an editor to define a new subagent
/planRun the next prompt with a Plan-mode subagent (read-only)
text
> /agents

Output:

text
Configured agents:
  general-purpose   — generic research and edits
  plan              — read-only planning
  reviewer          — security-focused PR review (project)

User-defined slash commands

Claude Code supports custom commands defined as Markdown files in ~/.claude/commands/ (global) or .claude/commands/ (project). Each .md file becomes a /command-name command, with the filename (minus .md) serving as the trigger.

Create a custom command

The command body is the user message that gets injected into the session when the slash is typed. Frontmatter is optional but lets you set description and constrain the tools the command may use.

bash
mkdir -p ~/.claude/commands

Output: (none — exits 0 on success)

markdown
---
description: "Security-focused diff review"
---

Review the staged git diff for:

1. Security issues (secrets, injection, XSS)
2. Missing error handling
3. Test coverage gaps
4. Code style inconsistencies

Be concise. Report findings as a bulleted list grouped by severity:
Critical, Warning, Info.

Save the above as ~/.claude/commands/review.md. Now /review is available in every Claude Code session.

text
> /review

Output:

text
**Critical**
- None

**Warning**
- auth/login.py:47 — password compared with == instead of hmac.compare_digest (timing attack)

**Info**
- utils/format.py — new function `format_currency` has no test coverage
- README.md — installation instructions not updated for new dependency

Project-level command

Place the file in .claude/commands/ in your project root. The command only appears when you are inside that project.

markdown
---
description: "Run the pre-deploy checklist"
---

Run the full pre-deploy checklist for this project:

1. `npm run build` — confirm clean build
2. `npm run test` — confirm all tests pass
3. `python scripts/validate_frontmatter.py` — confirm content is valid
4. Report a summary: pass/fail per step, plus any warnings.

Arguments with $ARGUMENTS

Commands support an $ARGUMENTS substitution. Whatever text follows the slash command is interpolated into $ARGUMENTS before the body is sent.

markdown
---
description: "Extract a function into its own helper"
---

Extract the function or block described by "$ARGUMENTS" into its own well-named
helper function. Place the helper just above the call site. Add type hints.
Do not change behavior. Show the diff before applying.

Usage:

text
> /extract the date-parsing logic in process_invoice()

Output:

text
Proposed diff:
  src/invoices.py
  +  def _parse_invoice_date(raw: str) -> date:
  +      return datetime.strptime(raw, "%Y-%m-%d").date()
  ...
Apply? [y/N]

Frontmatter schema

User commands accept the following optional frontmatter keys:

KeyTypeEffect
descriptionstringShown in /help and tab-completion
allowedToolslistRestrict tools for this command's execution
disallowedToolslistBlock tools for this command's execution
modelstringRun this command with a specific model
subagentstringRun via the named subagent (e.g. plan)
markdown
---
description: "Read-only architecture audit"
allowedTools: [Read, Glob, Grep]
model: claude-opus-4-7
---

Audit the project architecture and report findings. Read-only — do not edit any file.

Output: (none — file applies when /architecture-audit is invoked)

Skills and slash commands

Skills also surface as slash commands but resolve differently — they ship with full metadata, a SKILL.md file, and (often) bundled scripts. The harness presents them in the same /help menu, but invoking a skill triggers the Skill tool rather than just injecting a Markdown body. See Skills for details.

Keyboard shortcuts

These shortcuts work in the interactive prompt and complement the slash commands.

ShortcutAction
Ctrl+CCancel current input or interrupt running operation
Ctrl+DExit (same as /exit)
Up / DownNavigate input history
TabAutocomplete slash commands and file paths
Shift+EnterInsert a newline without submitting
EscapeClear current input or cancel autocomplete
Cmd+Esc (macOS) / Ctrl+Esc (Win/Linux)Open Claude Code from VS Code

Common pitfalls

  1. Wrong scope for personal commands — putting personal commands in .claude/commands/ commits them to the repo for every contributor; use ~/.claude/commands/ for personal scripts.
  2. $ARGUMENTS typo — only the exact string $ARGUMENTS is interpolated; $ARGS or ${ARGUMENTS} are left literal.
  3. Slash command name collisions — if both project and user commands define /review, the project version wins; rename to avoid silent override.
  4. Stale /doctor results/doctor checks the version on disk, not the running process; if you upgrade mid-session, restart claude before re-checking.
  5. /clear is destructive — there is no undo; use /compact when in doubt.
  6. Custom commands with frontmatter typos — invalid YAML frontmatter is silently ignored; the body still runs but tool restrictions, model overrides, etc., are not applied. Validate with claude /doctor.
  7. MCP commands without a running server/mcp tools <name> fails silently if the server has crashed; check /mcp first to confirm the connection.

Real-world recipes

Bootstrap a project with /init

/init reads the current directory and proposes a CLAUDE.md tailored to the project structure.

text
> /init

Output:

text
Detected: Astro + Tailwind project. Proposed CLAUDE.md:

  # Project: <name>
  ## Stack
  - Astro 4 (static output)
  - Tailwind CSS
  - Pagefind for search
  ...

Write to CLAUDE.md? [y/N]

Reusable PR review with /review

Drop a ~/.claude/commands/review.md once and invoke /review everywhere — see "Create a custom command" above.

Pre-deploy gate with /predeploy

Combine a project command with a hook that blocks pushes if /predeploy reports failures.

markdown
---
description: "Block-on-fail pre-deploy gate"
allowedTools: [Bash(npm test:npm run lint:python scripts/validate_frontmatter.py)]
---

Run npm test, npm run lint, and python scripts/validate_frontmatter.py.
Exit non-zero if any step fails. Output a one-line summary per step.

Quick refactor with /extract

text
> /extract the URL-parsing block in handle_request()

Output:

text
Proposed diff in src/router.py:
  - <inline block, 11 lines>
  + url = _parse_request_url(request.path)
  + def _parse_request_url(path: str) -> URL: ...

Apply? [y/N]

Architecture audit at start-of-week

A read-only audit command, run weekly to surface drift.

markdown
---
description: "Weekly architecture audit"
allowedTools: [Read, Glob, Grep]
model: claude-opus-4-7
---

Audit the project for these issues and produce a single-page report:

1. Files larger than 500 lines that mix concerns
2. Public functions without docstrings
3. Modules that import from deeper layers (layering violations)
4. Circular imports
5. Dead code — exports with zero imports across the repo

Invoke with /audit and pipe the result into your team chat.

Quick reference card

text
Session:    /help   /exit   /clear   /compact   /reset
Context:    /memory   /context   /add-dir
Config:     /config   /model <id>   /permissions
Cost:       /cost   /status   /version
Diagnose:   /doctor   /bug
MCP:        /mcp   /mcp add   /mcp remove
Mode:       /vim   /fast   /think
Agents:     /agents   /plan
Custom:     /your-command   (from .claude/commands/ or ~/.claude/commands/)