Slash Commands
Slash commands are shortcuts that trigger specific behaviors. Some are built-in; you can create your own.
Built-in Commands
Section titled “Built-in Commands”| Command | Description |
|---|---|
/help | Show all available commands |
/compact | Summarize context to save tokens |
/clear | Clear conversation history |
/model | Switch to a different model |
/config | View or modify settings |
/context | Show context window usage |
/mcp | Manage MCP server connections |
Using Built-in Commands
Section titled “Using Built-in Commands”Plan Mode
Section titled “Plan Mode”For complex tasks, use plan mode by pressing Alt+M to cycle through modes:
> add a user notification systemClaude will:
- Ask clarifying questions using the AskUserQuestion tool
- Present options for you to choose
- Create a detailed implementation plan
- Wait for your approval before executing
/compact - Save Tokens
Section titled “/compact - Save Tokens”When your conversation gets long:
> /compactClaude summarizes the conversation, keeping important context while reducing token usage. Use this proactively—don’t wait until you hit limits.
/model - Switch Models
Section titled “/model - Switch Models”Change models without restarting:
> /model haiku # Quick, cheap queries> /model sonnet # Default, balanced> /model opus # Complex reasoningCustom Slash Commands
Section titled “Custom Slash Commands”Create your own commands for repetitive workflows.
Creating a Custom Command
Section titled “Creating a Custom Command”-
Create the commands directory
Terminal window mkdir -p .claude/commands -
Create a command file
Each
.mdfile becomes a command:Terminal window touch .claude/commands/review.md -
Write the command prompt
Review my staged changes for:1. Code quality issues2. Potential bugs3. Security concerns4. Missing tests5. Documentation needsBe thorough but concise. Prioritize by severity. -
Use your command
> /review
Command File Structure
Section titled “Command File Structure”Directory.claude/
Directorycommands/
- review.md
- deploy.md
- test.md
- doc.md
Example Commands
Section titled “Example Commands”/review - Code Review
Section titled “/review - Code Review”Review the code changes I'm about to commit.
Check for:1. **Bugs**: Logic errors, edge cases, null handling2. **Security**: Input validation, SQL injection, XSS3. **Performance**: N+1 queries, unnecessary loops, memory leaks4. **Style**: Naming, formatting, consistency with codebase5. **Tests**: Are changes tested? Should new tests be added?
Provide feedback in order of severity. Be specific about fileand line numbers./deploy - Deployment Checklist
Section titled “/deploy - Deployment Checklist”Run through the deployment checklist:
1. [ ] All tests pass2. [ ] No linting errors3. [ ] Database migrations are ready4. [ ] Environment variables documented5. [ ] CHANGELOG updated6. [ ] Version number bumped
For each item, check and report status. Flag any blockers./test - Test Generation
Section titled “/test - Test Generation”Generate comprehensive tests for the current file or function.
Include:- Happy path tests- Edge cases (empty input, large input, null)- Error conditions- Boundary conditions
Use pytest with fixtures where appropriate.Follow existing test patterns in the codebase./doc - Documentation
Section titled “/doc - Documentation”Generate documentation for the specified code:
1. Module-level docstring explaining purpose2. Function/method docstrings with: - Description - Args with types - Returns with type - Raises (if applicable) - Example usage3. Type hints if missing
Use Google-style docstrings. Be concise but complete./pr - Pull Request Description
Section titled “/pr - Pull Request Description”Generate a pull request description based on my changes.
Include:## SummaryBrief description of what changed and why.
## Changes- Bullet list of specific changes
## TestingHow the changes were tested.
## Screenshots(Note if UI changes need screenshots)
## Checklist- [ ] Tests added/updated- [ ] Documentation updated- [ ] No breaking changes (or documented if yes)Commands with Variables
Section titled “Commands with Variables”Commands can use $ARGUMENTS to accept input:
Explain the following code in detail:
$ARGUMENTS
Focus on:1. What it does2. How it works3. Why it's implemented this way4. Any potential issuesUsage:
> /explain the authentication middleware in app/middleware.pyCommands with Selection
Section titled “Commands with Selection”Commands can reference selected code:
Optimize this code for performance:
$SELECTION
Consider:- Time complexity- Space complexity- Database queries- Memory allocations
Show before/after with benchmarks if possible.Sharing Commands
Section titled “Sharing Commands”Commands in .claude/commands/ are part of your repo. Share them with your team:
git add .claude/commands/git commit -m "Add team slash commands"For personal commands that shouldn’t be shared:
# Add to .gitignoreecho ".claude/commands/personal-*.md" >> .gitignoreBest Practices
Section titled “Best Practices”1. Be Specific
Section titled “1. Be Specific”# GoodReview code for SQL injection vulnerabilities.Check all database queries for parameterized inputs.
# BadReview code for security.2. Include Context
Section titled “2. Include Context”# GoodGenerate tests using pytest.Follow patterns in tests/conftest.py.Use fixtures from tests/fixtures/.
# BadGenerate tests.3. Set Expectations
Section titled “3. Set Expectations”# GoodProvide 3-5 specific suggestions.Prioritize by impact.Include code examples.
# BadGive me feedback.