Create Custom Slash Commands
Claude Code supports custom slash commands, which you can create to quickly execute specific prompts or tasks.
For more details, see the Slash Commands reference page.
Create Project-Specific Commands
Suppose you want to create reusable slash commands for your project that all team members can use.
Create the Commands Directory in Your Project
mkdir -p .claude/commandsCreate a Markdown File for Each Command
echo "Analyze the performance of this code and suggest three specific optimizations:" > .claude/commands/optimize.mdUse the Custom Command in Claude Code
> /optimizeTips:
- The command name is derived from the filename (e.g.,
optimize.mdbecomes/optimize) - You can organize commands in subdirectories (e.g.,
.claude/commands/frontend/component.mdcreates/component, shown as “(project:frontend)” in the description) - Project commands are available to everyone who clones the repository
- The Markdown file content becomes the prompt sent to Claude when the command is invoked
Add Command Arguments Using $ARGUMENTS
Suppose you want to create flexible slash commands that can accept additional input from the user.
Create a Command File with the $ARGUMENTS Placeholder
echo 'Find and fix issue #$ARGUMENTS. Follow these steps:
1. Understand the issue described in the ticket
2. Locate the relevant code in our codebase
3. Implement a solution that addresses the root cause
4. Add appropriate tests
5. Prepare a concise PR description' > .claude/commands/fix-issue.mdUse the Command with an Issue Number
In a Claude session, use the command with an argument.
> /fix-issue 123This replaces $ARGUMENTS with “123” in the prompt.
Tips:
- The
$ARGUMENTSplaceholder is replaced with any text that follows the command - You can place
$ARGUMENTSanywhere in the command template - Other useful applications: generating test cases for specific functions, creating documentation for components, reviewing code in specific files, or translating content into a specified language
Create Personal Slash Commands
Suppose you want to create personal slash commands that work across all your projects.
Create the Commands Directory in Your Home Folder
mkdir -p ~/.claude/commandsCreate a Markdown File for Each Command
echo "Review this code for security vulnerabilities, focusing on:" > ~/.claude/commands/security-review.mdUse Your Personal Custom Command
> /security-reviewTips:
- Personal commands are shown with “(user)” in their description when listed via
/help - Personal commands are only available to you and are not shared with your team
- Personal commands work across all your projects
- You can use these commands to maintain a consistent workflow across different codebases