Claude Code Slash Commands: Complete Reference Guide
Claude Code's slash commands control session state, context management, and built-in workflows. The most important ones: /clear (reset context), /compact (summarise context to free up space), /init (generate CLAUDE.md for a project), and /review (structured code review). Type / in Claude Code to see the full list. This guide explains each command, what it does internally, and when to use it.
Session management commands
/clear
Clears the current conversation context. Claude starts fresh with no memory of the current session.
When to use:
- You've been working on one task and are switching to a different, unrelated task
- The context has become confused or contradictory after a long session
- You want to give Claude a clean state to approach a problem fresh
What it doesn't clear: file system state (files you've written/modified still exist). /clear only resets the conversation history.
/compact
Summarises the current conversation into a compressed context. Frees up context window space for more work.
When to use:
- Claude is warning you that context is getting long
- You've completed one phase of a task and are starting the next
- You want to continue working without starting completely fresh (unlike
/clear)
How it works: Claude generates a summary of the conversation so far and replaces the full history with the summary. Subsequent work continues from the summary context. Some detail is lost in compression — the more specific the earlier work, the more important it is to verify after compacting.
/cost
Shows the token usage and estimated cost for the current session.
When to use: monitoring spend during long sessions, especially before starting a potentially expensive operation.
Project setup commands
/init
Reads your project and generates a CLAUDE.md file with project context, directory structure, dev commands, and conventions.
When to use: first time using Claude Code on an existing project. Run this before starting work — it creates the context file that makes all subsequent Claude Code sessions more productive.
What it generates:
- Project description (inferred from README and code)
- Directory structure with descriptions
- Key commands (install, dev, build, test)
- Technology stack
- Conventions inferred from the code
Always review and edit the generated CLAUDE.md — Claude's inferences are a starting point, not a final document.
/doctor
Checks your Claude Code installation and configuration for issues.
When to use:
- After installing or upgrading Claude Code
- When Claude Code is behaving unexpectedly
- When investigating permission or configuration issues
Outputs a diagnostic report: Node version, SDK version, API key status, configuration files found.
Development workflow commands
/review
Runs a structured code review of your recent changes.
When to use: before committing or creating a pull request. Equivalent to asking a senior developer to review your diff.
What it reviews:
- Correctness (bugs, logic errors)
- Security concerns
- Performance issues
- Code style and conventions
- Missing error handling
- Test coverage gaps
Tip: run /review after a focused coding session, not during — it evaluates the complete diff, not individual lines.
/vim
Enables Vim keybindings in the Claude Code input field.
When to use: if you prefer Vim navigation for editing your prompts. Toggle with /vim to enable, /vim again to disable.
Context and memory commands
/memory
Manages Claude Code's persistent memory files. Claude Code can maintain notes across sessions in ~/.claude/memory/.
When to use:
- After establishing important project preferences you want Claude to remember
- For preferences that apply across multiple sessions (not just the current one)
Output and format commands
/output
Changes the output mode. Options include:
markdown— formatted markdown output (default)plain— plain text without markdown formattingjson— structured JSON output
When to use: when piping Claude Code output to other tools that expect plain text or JSON.
Custom commands (CLAUDE.md slash commands)
You can define project-specific slash commands in your CLAUDE.md:
## Custom commands
/deploy: Run `vercel --prod --yes` after confirming the build passes
/check: Run typecheck, lint, and tests in sequence. Report any failures.
/ship: Run /check, then create a commit, then /deploy
When you type /deploy in Claude Code, it executes the described workflow. This is the most powerful customisation feature — you define repeatable workflows once, then invoke them with a single command.
Examples of useful custom commands:
## Custom commands
/sync: Pull latest from main, rebase current branch, and report any conflicts
/audit: Check for unused dependencies, deprecated APIs, and TODO comments.
Report findings grouped by severity.
/docs: Update the JSDoc comments for any functions modified in the last commit.
/perf: Run the build and report bundle sizes. Flag any that increased by >5%.
/test-coverage: Run tests with coverage. Report any files under 80% coverage.
Keyboard shortcuts (not slash commands but equally important)
| Shortcut | Action |
|---|---|
Ctrl+C |
Cancel current operation |
↑ / ↓ |
Navigate command history |
Ctrl+R |
Search command history |
Tab |
Autocomplete slash commands |
Esc |
Cancel current input |
Frequently asked questions
Does /clear delete any files Claude created?
No. /clear only resets the conversation context — the in-memory history of what Claude has said and done. Any files written to disk, any git commits made, any code changes are permanent until you undo them with git.
How often should I use /compact?
When Claude Code warns you that context is getting long, or when you notice responses becoming less focused. For very long sessions (2+ hours of active work), compact every 1–2 hours of active work. For quick tasks under 30 minutes, you rarely need it.
Can I create global slash commands that work across all projects?
Yes. Add custom commands to ~/.claude/CLAUDE.md (your global Claude Code configuration) and they'll be available in every project session.
What's the difference between /clear and starting a new Claude Code session?
Functionally identical for the conversation context. Starting a new session also reloads CLAUDE.md and .claude/settings.json, which can be useful if you've changed those files.
Where are Claude Code's built-in commands documented?
Type /help in Claude Code for a list of all available commands. The Anthropic documentation at docs.anthropic.com has the full reference.
Related guides
- Setting Up a New Project with Claude Code: The Right Way — CLAUDE.md setup including custom commands
- Claude Code Tips from Power Users — workflow patterns beyond slash commands
Take It Further
Power Prompts 300: Claude Code Productivity Patterns — Section 1 includes 15 custom Claude Code slash command templates for audit, deploy, test coverage, performance, and documentation workflows — copy-paste into your CLAUDE.md.
30-day money-back guarantee. Instant download.