Claude Code Custom Slash Commands
Overview
Custom Slash Commands are user-defined prompt templates that allow developers to automate repetitive workflows within Claude Code. By mapping Markdown files to terminal commands, users can encapsulate complex instructions into simple, reusable shortcuts.
Configuration
Commands are stored as .md files in specific directories. The filename determines the command name.
Scoping
| Scope | Directory | Access |
|---|---|---|
| Global | ~/.claude/commands/ | Available in any project on the machine. |
| Local | .claude/commands/ | Specific to the current repository; can be shared via Git. |
Syntax and Features
1. Variables and Arguments
Commands can accept dynamic user input using placeholders:
$ARGUMENTS: Captures the entire string following the command.$1,$2, …: Captures specific positional arguments.
2. Shell Execution (!)
You can execute bash commands and pipe their output directly into the prompt context:
Analyze the following git status:
!git status3. File Context (@)
Explicitly reference files to ensure Claude focuses on the correct code:
Refactor the functions in @src/utils.js using the logic in $ARGUMENTS.Evolution: Commands vs. Skills
The Skills system is the successor to basic slash commands.
- Commands: Require explicit manual invocation (e.g.,
/refactor). - Skills: Leverage YAML metadata for Dynamic Discovery, allowing Claude to autonomously suggest or use them based on the conversation context.
- Unified Interface: Modern Skills also appear as slash commands in the terminal.
Practical Applications
- Spec Generation:
/spec "User authentication using JWT"→ Generates a technical specification. - Database Seeding:
/seed 10 users→ Executes a script to populate a dev database. - PR Review:
/review→ Runs a predefined analysis of staged changes.