Custom Slash Commands¶
Create your own commands to automate repetitive tasks.
What You'll Learn¶
- What slash commands are
- Creating project-specific commands
- Creating personal commands
- Command arguments and templates
What Are Slash Commands?¶
Slash commands are shortcuts that expand into prompts. Instead of typing the same instructions repeatedly, create a command:
Command Locations¶
Commands are markdown files stored in two places:
| Location | Scope | Path |
|---|---|---|
| Project | Shared with team | .claude/commands/ |
| User | Personal only | ~/.claude/commands/ |
Creating Your First Command¶
Step 1: Create the Directory¶
Step 2: Create a Command File¶
Create .claude/commands/review.md:
Review the code changes in this branch for:
1. **Logic Errors** - Check for bugs, edge cases, and incorrect assumptions
2. **Security Issues** - Look for vulnerabilities, injection risks, secrets
3. **Performance** - Identify inefficient algorithms or unnecessary operations
4. **Code Style** - Ensure consistency with project conventions
5. **Test Coverage** - Note any untested code paths
For each issue found, specify:
- File and line number
- Description of the problem
- Suggested fix
Start by checking what files have changed.
Step 3: Use It¶
Claude executes your review prompt.
Command Arguments¶
Use $ARGUMENTS to accept input:
Example: Generate Command¶
Create .claude/commands/generate.md:
Generate a new $ARGUMENTS following our project conventions.
1. Look at existing similar files for patterns
2. Create the new file with proper structure
3. Add any necessary imports
4. Include basic tests
Ensure it follows our naming conventions and code style.
Use it:
> /generate React component called UserProfile
> /generate Express route for /api/products
> /generate Python class for EmailService
The text after /generate becomes $ARGUMENTS.
Real-World Command Examples¶
Code Review Command¶
.claude/commands/review-pr.md:
Review the changes in this pull request critically.
Check for:
- Bugs and logic errors
- Security vulnerabilities
- Performance issues
- Missing error handling
- Test coverage gaps
- Breaking changes
Be specific about issues. For each problem:
1. Quote the problematic code
2. Explain why it's an issue
3. Suggest a fix
If everything looks good, say so briefly.
Documentation Command¶
.claude/commands/document.md:
Add documentation to $ARGUMENTS:
1. Add JSDoc/docstring comments to all public functions
2. Include parameter descriptions and return values
3. Add usage examples where helpful
4. Note any important edge cases or limitations
Match the documentation style used elsewhere in this project.
Test Command¶
.claude/commands/add-tests.md:
Add comprehensive tests for $ARGUMENTS:
1. Identify all public functions and methods
2. Write tests for the happy path
3. Add edge case tests (null, empty, boundary values)
4. Include error condition tests
5. Follow existing test patterns in this project
Use the same test framework and mocking patterns as other tests.
Debug Command¶
.claude/commands/debug.md:
Help me debug: $ARGUMENTS
1. Identify the source of the problem
2. Explain why it's happening
3. Suggest a fix
4. Recommend how to prevent similar issues
If you need more information, ask specific questions.
Refactor Command¶
.claude/commands/refactor.md:
Refactor $ARGUMENTS with these goals:
- Improve readability
- Reduce complexity
- Better separation of concerns
- More consistent naming
Keep the same behavior - no functional changes.
Show me the changes and explain the improvements.
Quick Fix Command¶
.claude/commands/fix.md:
Fix: $ARGUMENTS
Make the minimal change needed to resolve this issue.
Don't refactor or improve other things - just fix this specific problem.
Personal Commands¶
Store personal commands in ~/.claude/commands/:
Daily Standup¶
~/.claude/commands/standup.md:
Review my git activity since yesterday and generate a standup:
1. What I completed (merged PRs, closed issues)
2. What I'm working on (current branch, open PRs)
3. Any blockers (failing tests, review needed)
Keep it concise - 2-3 bullet points per section.
Project Context¶
~/.claude/commands/context.md:
Give me context for this project:
1. What does this project do?
2. What's the tech stack?
3. What are the main entry points?
4. What should I know before making changes?
Be concise - I just need to get oriented.
Command Best Practices¶
Be Specific¶
# Vague
Review the code.
# Specific
Review for security issues, focusing on:
- SQL injection in database queries
- XSS in rendered output
- Authentication bypass
Include Examples¶
Generate a unit test following this pattern:
describe('functionName', () => {
it('should handle normal input', () => {
expect(functionName(normalInput)).toBe(expectedOutput);
});
it('should handle edge cases', () => {
expect(() => functionName(null)).toThrow();
});
});
Make Them Composable¶
Create focused commands that can be used in sequence:
> /analyze # Understand the code
> /suggest # Get improvement ideas
> /implement # Make the changes
> /test # Add tests
Keep Them Updated¶
Commands should evolve with your workflow. Review and improve them regularly.
Listing Available Commands¶
Shows all available commands, including custom ones.
Try It Yourself¶
Exercise: Create a Personal Toolkit¶
-
Create the commands directory:
-
Create a
/explaincommand: -
Create a
/simplifycommand: -
Try them out:
Exercise: Project Commands¶
- In a project, create
.claude/commands/ - Add commands specific to that project:
/deploy- deployment checklist/pr- PR preparation checklist/onboard- new developer orientation- Commit them so your team can use them too
What's Next?¶
Learn about hooks for automation in 02-hooks.
Summary:
- Slash commands are markdown files that expand into prompts
- Store in .claude/commands/ (project) or ~/.claude/commands/ (personal)
- Use $ARGUMENTS to accept input
- Create focused, specific commands for common tasks
- Commands can be shared with your team via version control
Learning Resources¶
Featured Video¶
Edmund Yong: 800+ Hours Learning Claude Code - Commands (Popular tech channel)
Deep dive into creating custom slash commands for automated workflows and team standardization.
Additional Resources¶
| Type | Resource | Description |
|---|---|---|
| 🎬 Video | MCP + Custom Workflows | All About AI - Command automation |
| 📚 Official Docs | Slash Commands Guide | Official command documentation |
| 📖 Tutorial | Best Practices | Command patterns from Anthropic |
| 🎓 Free Course | Claude Command Suite | 148+ pre-built commands free |
| 💼 Commercial | AI Coding Course | Custom workflow automation |