Claude Code: Part 4 - Slash Commands and Custom Commands
Claude Code: Part 4 - Slash Commands and Custom Commands
The Problem
You type the same instructions to Claude every day: "Run tests", "Check TypeScript errors", "Review changes". Repetitive and wasteful.
The Solution
Slash commands turn repeated instructions into shortcuts. /test
replaces paragraphs of testing instructions.
Built-in Commands
/clear # Fresh start
/compact # Compress history
/help # Show commands
/agents # Manage subagents
/add-dir # Add working directory
/bug # Report bug
/config # Show configuration
/mcp # MCP servers
/review # Request code review
/exit # End session
Custom Commands
Create .claude/commands/test-all.md
:
1. Run pnpm type:check
2. Run pnpm lint
3. Run pnpm test
4. Report issues
Now /test-all
runs everything.
Example Commands
.claude/commands/morning.md
: Daily setup (git pull, tests, status)
.claude/commands/ready.md
: Pre-commit checks
.claude/commands/review.md
: PR preparation
Organization
Group commands by phase (planning/, development/, deployment/) or domain (frontend/, backend/, testing/).
Best Practices
- Be specific: "Check TypeScript errors in src/" not "Check code"
- Include success criteria: "0 test failures, 80% coverage"
- Keep commands under 10 steps
- Use numbered lists for clarity
Sharing Commands
- Team: Commit
.claude/commands/
to git - Personal: Use
~/.claude/commands/
globally
Advanced Features
Commands can include:
- Parameters: "Ask for feature name, create feature/[name]"
- Conditionals: "If production, run security scan"
- Context awareness: "Analyze current file"
Getting Started
- Identify what you repeat daily
- Create
.claude/commands/[name].md
- Keep instructions under 10 steps
- Test and refine
Slash commands eliminate repetitive instructions.
Claude Code Blog Series
Previous: Part 3 - Conversation Management and Context Next: Part 5 - MCP Servers and Tool Integration
Full Series:
- Part 1 - Getting Started and Installation
- Part 2 - CLAUDE.md Configuration Files
- Part 3 - Conversation Management and Context
- Part 4 - Slash Commands and Custom Commands (this post)
- Part 5 - MCP Servers and Tool Integration
- Part 6 - Subagents and Task Delegation
- Part 7 - IDE Integration with VS Code and JetBrains
- Part 8 - Hooks for Automated Quality Checks
- Part 9 - Complete Development Workflows
- Part 10 - Power User CLI Options and Scripting
- Part 11 - Troubleshooting and Recovery