Create effective slash commands for Claude Code that enable users to trigger reusable prompts with /command-name syntax. Slash commands expand as prompts in the current conversation, allowing teams to standardize workflows and operations. This skill teaches you to structure commands with XML tags, YAML frontmatter, dynamic context loading, and intelligent argument handling.
- Create
.claude/commands/ directory (project) or use ~/.claude/commands/ (personal) - Create
command-name.md file - Add YAML frontmatter (at minimum:
description) - Write command prompt
- Test with
/command-name [args]
File: .claude/commands/optimize.md
```markdown
---
description: Analyze this code for performance issues and suggest optimizations
---
Analyze the performance of this code and suggest three specific optimizations:
```
Usage: /optimize
Claude receives the expanded prompt and analyzes the code in context.
All generated slash commands should use XML tags in the body (after YAML frontmatter) for clarity and consistency.
- What the command does and why it matters
```markdown
What needs to happen and why this matters.
Context about who uses this and what it accomplishes.
```
or - How to execute the command
```markdown
Sequential steps to accomplish the objective:
- First step
- Second step
- Final step
```
- How to know the command succeeded
```markdown
Clear, measurable criteria for successful completion.
```
- When loading dynamic state or files
```markdown
Current state: ! git status
Relevant files: @ package.json
```
(Note: Remove the space after @ in actual usage)
- When producing artifacts that need checking
```markdown
Before completing, verify:
- Specific test or check to perform
- How to confirm it works
```
- When running tests is part of the workflow
```markdown
Run tests: ! npm test
Check linting: ! npm run lint
```
- When creating/modifying specific files
```markdown
Files created/modified:
./path/to/file.ext - Description
```
```markdown
---
name: example-command
description: Does something useful
argument-hint: [input]
---
Process $ARGUMENTS to accomplish [goal].
This helps [who] achieve [outcome].
Current state: ! relevant command
Files: @ relevant/files
- Parse $ARGUMENTS
- Execute operation
- Verify results
- Operation completed without errors
- Output matches expected format
```
Simple commands (single operation, no artifacts):
- Required:
, , - Example:
/check-todos, /first-principles
Complex commands (multi-step, produces artifacts):
- Required:
, , - Add:
(if loading state), (if creating files), (what gets created) - Example:
/commit, /create-prompt, /run-prompt
Commands with dynamic arguments:
- Use
$ARGUMENTS in or tags - Include
argument-hint in frontmatter - Make it clear what the arguments are for
Commands that produce files:
- Always include
tag specifying what gets created - Always include
tag with checks to perform
Commands that run tests/builds:
- Include
tag with specific commands - Include pass/fail criteria in
The skill should intelligently determine whether a slash command needs arguments.
User provides specific input:
/fix-issue [issue-number] - Needs issue number/review-pr [pr-number] - Needs PR number/optimize [file-path] - Needs file to optimize/commit [type] - Needs commit type (optional)
Pattern: Task operates on user-specified data
Include argument-hint: [description] in frontmatter and reference $ARGUMENTS in the body.
Self-contained procedures:
/check-todos - Operates on known file (TO-DOS.md)/first-principles - Operates on current conversation/whats-next - Analyzes current context
Pattern: Task operates on implicit context (current conversation, known files, project state)
Omit argument-hint and don't reference $ARGUMENTS.
In tag:
```markdown
Fix issue #$ARGUMENTS following project conventions.
This ensures bugs are resolved systematically with proper testing.
```
In tag:
```markdown
- Understand issue #$ARGUMENTS from issue tracker
- Locate relevant code
- Implement fix
- Add tests
```
In tag:
```markdown
Issue details: @ issues/$ARGUMENTS.md
Related files: ! grep -r "TODO.*$ARGUMENTS" src/
```
(Note: Remove the space after the exclamation mark in actual usage)
For structured input, use $1, $2, $3:
```markdown
---
argument-hint:
---
Review PR #$1 with priority $2 and assign to $3.
```
Usage: /review-pr 456 high alice
Project commands: .claude/commands/
- Shared with team via version control
- Shows
(project) in /help list
Personal commands: ~/.claude/commands/
- Available across all your projects
- Shows
(user) in /help list
File naming: command-name.md β invoked as /command-name
Required - Describes what the command does
```yaml
description: Analyze this code for performance issues and suggest optimizations
```
Shown in the /help command list.
Optional - Restricts which tools Claude can use
```yaml
allowed-tools: Bash(git add:), Bash(git status:), Bash(git commit:*)
```
Formats:
- Array:
allowed-tools: [Read, Edit, Write] - Single tool:
allowed-tools: SequentialThinking - Bash restrictions:
allowed-tools: Bash(git add:*)
If omitted: All tools available
Command file: .claude/commands/fix-issue.md
```markdown
---
description: Fix issue following coding standards
---
Fix issue #$ARGUMENTS following our coding standards
```
Usage: /fix-issue 123 high-priority
Claude receives: "Fix issue #123 high-priority following our coding standards"
Command file: .claude/commands/review-pr.md
```markdown
---
description: Review PR with priority and assignee
---
Review PR #$1 with priority $2 and assign to $3
```
Usage: /review-pr 456 high alice
Claude receives: "Review PR #456 with priority high and assign to alice"
See [references/arguments.md](references/arguments.md) for advanced patterns.
Execute bash commands before the prompt using the exclamation mark prefix directly before backticks (no space between).
Note: Examples below show a space after the exclamation mark to prevent execution during skill loading. In actual slash commands, remove the space.
Example:
```markdown
---
description: Create a git commit
allowed-tools: Bash(git add:), Bash(git status:), Bash(git commit:*)
---