3.3 Custom Slash Commands
Course: Claude Code - Essentials Section: Basic Input & Interaction Video Length: 2-5 minutes Presenter: Daniel Treasure
Opening Hook
The real power unlocks when you create your own commands. Instead of typing the same 10-sentence prompt every time you review a PR, you type /review-pr. That's the difference between Claude Code and an AI that really fits your workflow.
Key Talking Points
- Two Levels of Custom Commands
- Project Commands -
.claude/commands/(shared via git, team uses them) - Personal Commands -
~/.claude/commands/(just you, all projects) -
Can override: project commands take precedence over personal ones
-
What a Custom Command Is
- A
SKILL.mdfile with frontmatter (metadata) + instructions - Lives in a directory named after the command
-
Callable with
/command-namein any Claude Code session -
Real-World Examples
/review-pr- standardized PR review with your team's checklist/refactor-ts- TypeScript refactoring with your code style rules/bug-hunt- systematic debugging approach specific to your codebase/test-coverage- generate tests for uncovered lines-
/write-docs- documentation template for your project -
Anatomy of a Custom Command ```yaml
name: review-pr description: Review a pull request with focus on security and performance user-invocable: true allowed-tools: Read, Grep
Review the following PR changes: 1. Check for security issues 2. Check for performance regressions 3. Verify test coverage 4. Recommend improvements ```
- Arguments and Substitutions
$ARGUMENTS- everything the user passed to the command$ARGUMENTS[0]- first argument$ARGUMENTS[1]- second argument-
Example:
/fix-issue 123→ Claude knows the issue number -
Scope: Project vs. Personal
- Project (
.claude/commands/): Enforce team standards - Personal (
~/.claude/commands/): Your personal shortcuts -
Both can exist simultaneously (project takes priority)
-
Advanced Features (briefly mention, not deep-dive)
disable-model-invocation: true- only you can invoke itcontext: fork- runs in isolated subagentallowed-tools- restrict what Claude can do in this commanduser-invocable: false- Claude invokes it automatically when relevant
Demo Plan
Live Walkthrough (3-5 minutes):
-
Show Project Structure
bash cd /path/to/project ls -la .claude/commands/ # Shows existing custom commands (if any) # Or: mkdir -p .claude/commands/ -
Create a Simple Custom Command (2-3 minutes)
-
Create a new command directory:
bash mkdir .claude/commands/review-code -
Create
SKILL.md:bash touch .claude/commands/review-code/SKILL.md -
Edit the file (show in editor): ```yaml --- name: review-code description: Review code for quality, readability, and best practices user-invocable: true allowed-tools: Read, Grep ---
Review the following code: 1. Is the code readable and maintainable? 2. Are there any obvious bugs or logic errors? 3. Does it follow our code style conventions? 4. Are there performance issues? 5. Is error handling sufficient? 6. Are there security concerns? ```
-
Test the Command (45 seconds)
- Back in Claude Code session:
bash claude - Type:
/review-code src/components/Button.tsx - Claude executes the custom command with the file
-
Show Claude following the checklist
-
Show Personal Commands Location (30 seconds)
- Explain:
~/.claude/commands/is your personal directory - Example personal command:
/quick-test(personal testing shortcut) -
Say: "This works in ALL your projects, but only for you"
-
Show Command with Arguments (Optional, 30 seconds)
- Create a command that uses
$ARGUMENTS: - Example:
/refactor-to-async $ARGUMENTS[0](refactor specific function) - Show:
/refactor-to-async loginFunction
Code Examples & Commands
Minimal Project Command
.claude/commands/review-code/
└── SKILL.md
SKILL.md content:
---
name: review-code
description: Thorough code review with focus on quality
user-invocable: true
---
Review this code for:
1. Readability and maintainability
2. Security vulnerabilities
3. Performance issues
4. Best practices for this language
5. Test coverage gaps
Command with Arguments
---
name: refactor-function
description: Refactor a function to be more readable
user-invocable: true
---
Refactor $ARGUMENTS[0] to:
1. Follow modern syntax and best practices
2. Reduce complexity
3. Improve type safety
4. Add comments explaining the logic
Usage:
/refactor-function loginHandler
Team-Level Command (Project Commands)
.claude/commands/pr-review/
└── SKILL.md
.claude/commands/security-audit/
└── SKILL.md
.claude/commands/write-test/
└── SKILL.md
All committed to git, all team members use the same checklist.
Personal Commands (Your Shortcuts)
~/.claude/commands/quick-explain/
└── SKILL.md
~/.claude/commands/find-todo/
└── SKILL.md
~/.claude/commands/performance-check/
└── SKILL.md
Works in every project you touch.
Gotchas & Tips
- Gotcha: Directory name = command name
- Directory:
.claude/commands/my-command/ - Usage:
/my-command - Must use lowercase and hyphens
-
Underscores don't work in command invocation
-
Gotcha: SKILL.md must be in the command directory
- Right:
.claude/commands/review/SKILL.md - Wrong:
.claude/commands/SKILL.md -
Wrong:
.claude/review/SKILL.md -
Tip: Start simple, evolve
- First command: simple checklist (no arguments)
- Second: add one
$ARGUMENTSvariable -
Advanced: add
allowed-tools,context: fork, etc. -
Tip: Project commands in git = team standard
- Team does code reviews the same way
- New team members learn your process
-
PR checklist is code (can be versioned)
-
Tip: Personal commands for your habits
- Your debugging workflow
- Your refactoring style
- Your documentation template
-
Lives in
~/.claude/commands/, ignored by git -
Gotcha: Custom commands don't override built-in ones
- Can't create
/help,/clear,/configas custom commands - Built-ins always take priority
-
Name your commands thoughtfully to avoid confusion
-
Tip: Use descriptions that matter
- Good: "Review code for security, performance, and readability"
- Bad: "Review code"
-
Claude uses descriptions to decide when to auto-invoke
-
Gotcha: Relative paths in commands
$ARGUMENTS[0]might be a relative path- Test thoroughly with different working directories
-
Use absolute paths or validate input in the SKILL.md
-
Tip: Combine with shell commands (!)
- Advanced: use
!prefix in command body to run shell commands - Example:
/testcommand runs!npm testto get live results - See 3.4 (Bash Mode) for deeper dive
Lead-out
Custom commands are where Claude Code starts to feel like it's built for you, not the other way around. In the next video, bash mode, you'll see how to run actual shell commands from within Claude Code—which is how commands can execute your tests, builds, and scripts automatically.
Reference URLs
- Official Docs - Skills & Custom Commands: https://code.claude.com/docs/en/skills (section: "Creating Your First Skill")
- Official Docs - Skill Locations: https://code.claude.com/docs/en/skills (section: "Skill Locations")
- Official Docs - String Substitutions: https://code.claude.com/docs/en/skills (section: "String Substitutions")
Prep Reading
- Official: Skills documentation - comprehensive guide to SKILL.md structure
- Recent Articles: "Inside the Development Workflow of Claude Code's Creator" - Boris Cherny uses custom commands heavily
- Context: from docs: Custom commands live alongside code in version control (team practice)