Files
claude-plugins/claude-code/skills/claude-commands/SKILL.md
2025-10-28 12:48:17 -05:00

233 lines
4.9 KiB
Markdown

---
name: Slash Command Creator
description: Create custom slash commands for Claude Code with argument handling, bash execution, and file references. Use PROACTIVELY when users repeat similar prompts 3+ times, mention "create a command", "reusable prompt", "/something", or "slash command". Triggers BEFORE user asks explicitly to suggest command creation for repeated workflows. NOT for complex multi-file operations.
---
# Slash Command Development
## When to Use This Skill
Use this skill when:
- Creating custom slash commands for Claude Code
- Building reusable prompt templates
- User repeats similar prompts 3+ times
- Automating repetitive tasks
- Converting manual workflows to commands
Do NOT use this skill for:
- Creating full plugins (use claude-plugins skill)
- Setting up hooks (use claude-hooks skill)
- Complex multi-file operations (use subagents)
## Quick Start
Create a command file in `.claude/commands/`:
```bash
mkdir -p .claude/commands
cat > .claude/commands/review.md << 'EOF'
---
description: Review code for common issues
---
Review the following code for:
- Bugs and logic errors
- Code style issues
- Performance problems
- Security vulnerabilities
$ARGUMENTS
EOF
```
**Usage**: `/review @src/main.js`
## Command Locations
| Location | Scope | Use For |
|----------|-------|---------|
| `.claude/commands/` | Project (team) | Team workflows, standards |
| `~/.claude/commands/` | User (personal) | Personal productivity |
## Essential Syntax
### Basic Structure
```markdown
---
description: Brief description for /help
---
Prompt content here
$ARGUMENTS
```
**File name = Command name**: `review.md``/review`
### Frontmatter Options
```yaml
---
description: Generate unit tests for a function # Required
argument-hint: <file-path> <function-name> # Autocomplete
allowed-tools: Read(*), Bash(git:*) # Permissions
model: claude-haiku-4 # Model override
---
```
### Arguments
```markdown
$ARGUMENTS # All arguments
$1, $2, $3 # Positional arguments
@$1 or @file.js # Load file content
```
**Examples**:
```bash
/compare REST GraphQL # $1="REST", $2="GraphQL"
/review @src/main.js # Loads main.js content
/explain @src/a.js @src/b.js # Loads both files
```
### Bash Execution
Prefix with `!` to execute before processing:
```markdown
---
description: Git workflow helper
allowed-tools: Bash(git:*)
---
!git status
!git diff --stat
Based on above, suggest next steps.
```
**Important**: Must include `allowed-tools` with Bash patterns.
## Quick Examples
### Simple Review Command
```markdown
---
description: Review code quality
---
Review @$1 for:
1. Logic errors
2. Code style
3. Performance issues
Provide specific fixes.
```
### Multi-Step Workflow
```markdown
---
description: Commit and push changes
allowed-tools: Bash(git:*)
---
!git status
!git diff
1. Review changes
2. Create commit message
3. Commit and push
Ask confirmation before push.
```
For more examples, see [examples.md](examples.md)
## Best Practices
### ✓ Do
- Clear descriptions under 100 chars
- Specific tool permissions
- Meaningful command names (kebab-case)
- Self-documenting prompts
- Include argument hints
### ✗ Avoid
- Vague descriptions ("Helper", "Utils")
- Wildcard permissions (`allowed-tools: *`)
- Short cryptic names (`/gt`, `/rs`)
- Hardcoded secrets or paths
- Missing frontmatter
## Testing
```bash
# List all commands
/help
# Test with arguments
/mycommand arg1
/mycommand @file.js
```
## Common Issues
| Problem | Solution |
|---------|----------|
| Command not found | Check `.claude/commands/`, restart Claude |
| Arguments not working | Use `$ARGUMENTS`, not `${ARGUMENTS}` |
| Bash not executing | Add `allowed-tools: Bash(...)` |
| File not loading | Use `@` prefix, verify path |
For detailed troubleshooting, see [troubleshooting.md](troubleshooting.md)
## Security
**Limit permissions**:
```yaml
# ✓ Specific
allowed-tools: Bash(git status:*), Bash(git diff:*)
# ✗ Too broad
allowed-tools: *
```
**No secrets**:
```markdown
# ✗ Bad
!curl -H "API-Key: sk-abc123..."
# ✓ Good
!curl -H "API-Key: $MY_API_KEY"
```
## Command Template
```markdown
---
description: [Clear, concise description]
argument-hint: [Expected arguments]
allowed-tools: [Specific patterns if needed]
---
[Command prompt template]
$ARGUMENTS
```
## Additional Resources
**Need more?**
- [Complete Examples](examples.md) - 10+ working commands
- [Command Patterns](patterns.md) - Reusable templates
- [Troubleshooting Guide](troubleshooting.md) - Problem solutions
- [Official Docs](https://docs.claude.com/en/docs/claude-code/slash-commands)
- [Plugin Development](../claude-plugins/SKILL.md) - Package commands
💡 **Tip**: Start with manual prompts, identify repetition, then create commands. Commands are for workflows you use 3+ times.
---
**Remember**: Slash commands = reusable prompts. Keep them simple, specific, and secure.