Files

233 lines
4.9 KiB
Markdown
Raw Permalink Normal View History

2025-10-28 12:28:48 -05:00
---
name: Slash Command Creator
2025-10-28 12:48:17 -05:00
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.
2025-10-28 12:28:48 -05:00
---
# Slash Command Development
## When to Use This Skill
Use this skill when:
- Creating custom slash commands for Claude Code
- Building reusable prompt templates
2025-10-28 12:48:17 -05:00
- User repeats similar prompts 3+ times
- Automating repetitive tasks
- Converting manual workflows to commands
2025-10-28 12:28:48 -05:00
Do NOT use this skill for:
2025-10-28 12:48:17 -05:00
- Creating full plugins (use claude-plugins skill)
2025-10-28 12:28:48 -05:00
- Setting up hooks (use claude-hooks skill)
- Complex multi-file operations (use subagents)
## Quick Start
2025-10-28 12:48:17 -05:00
Create a command file in `.claude/commands/`:
2025-10-28 12:28:48 -05:00
```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
2025-10-28 12:48:17 -05:00
| Location | Scope | Use For |
|----------|-------|---------|
| `.claude/commands/` | Project (team) | Team workflows, standards |
| `~/.claude/commands/` | User (personal) | Personal productivity |
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Essential Syntax
2025-10-28 12:28:48 -05:00
### Basic Structure
```markdown
---
description: Brief description for /help
---
Prompt content here
$ARGUMENTS
```
2025-10-28 12:48:17 -05:00
**File name = Command name**: `review.md``/review`
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### Frontmatter Options
2025-10-28 12:28:48 -05:00
```yaml
---
2025-10-28 12:48:17 -05:00
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
2025-10-28 12:28:48 -05:00
---
```
2025-10-28 12:48:17 -05:00
### Arguments
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
$ARGUMENTS # All arguments
$1, $2, $3 # Positional arguments
@$1 or @file.js # Load file content
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
**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
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
### Bash Execution
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
Prefix with `!` to execute before processing:
2025-10-28 12:28:48 -05:00
```markdown
---
2025-10-28 12:48:17 -05:00
description: Git workflow helper
allowed-tools: Bash(git:*)
2025-10-28 12:28:48 -05:00
---
!git status
!git diff --stat
2025-10-28 12:48:17 -05:00
Based on above, suggest next steps.
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
**Important**: Must include `allowed-tools` with Bash patterns.
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Quick Examples
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### Simple Review Command
2025-10-28 12:28:48 -05:00
```markdown
---
2025-10-28 12:48:17 -05:00
description: Review code quality
2025-10-28 12:28:48 -05:00
---
2025-10-28 12:48:17 -05:00
Review @$1 for:
1. Logic errors
2. Code style
3. Performance issues
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
Provide specific fixes.
```
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### Multi-Step Workflow
2025-10-28 12:28:48 -05:00
```markdown
---
2025-10-28 12:48:17 -05:00
description: Commit and push changes
2025-10-28 12:28:48 -05:00
allowed-tools: Bash(git:*)
---
!git status
!git diff
2025-10-28 12:48:17 -05:00
1. Review changes
2. Create commit message
3. Commit and push
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
Ask confirmation before push.
2025-10-28 12:28:48 -05:00
```
For more examples, see [examples.md](examples.md)
2025-10-28 12:48:17 -05:00
## Best Practices
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### ✓ Do
- Clear descriptions under 100 chars
- Specific tool permissions
- Meaningful command names (kebab-case)
- Self-documenting prompts
- Include argument hints
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
### ✗ Avoid
- Vague descriptions ("Helper", "Utils")
- Wildcard permissions (`allowed-tools: *`)
- Short cryptic names (`/gt`, `/rs`)
- Hardcoded secrets or paths
- Missing frontmatter
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Testing
2025-10-28 12:28:48 -05:00
```bash
2025-10-28 12:48:17 -05:00
# List all commands
2025-10-28 12:28:48 -05:00
/help
2025-10-28 12:48:17 -05:00
# Test with arguments
2025-10-28 12:28:48 -05:00
/mycommand arg1
/mycommand @file.js
```
2025-10-28 12:48:17 -05:00
## Common Issues
2025-10-28 12:28:48 -05:00
| Problem | Solution |
|---------|----------|
2025-10-28 12:48:17 -05:00
| 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 |
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
For detailed troubleshooting, see [troubleshooting.md](troubleshooting.md)
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Security
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
**Limit permissions**:
2025-10-28 12:28:48 -05:00
```yaml
2025-10-28 12:48:17 -05:00
# ✓ Specific
allowed-tools: Bash(git status:*), Bash(git diff:*)
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
# ✗ Too broad
2025-10-28 12:28:48 -05:00
allowed-tools: *
```
2025-10-28 12:48:17 -05:00
**No secrets**:
2025-10-28 12:28:48 -05:00
```markdown
2025-10-28 12:48:17 -05:00
# ✗ Bad
!curl -H "API-Key: sk-abc123..."
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
# ✓ Good
!curl -H "API-Key: $MY_API_KEY"
2025-10-28 12:28:48 -05:00
```
## Command Template
```markdown
---
description: [Clear, concise description]
argument-hint: [Expected arguments]
allowed-tools: [Specific patterns if needed]
---
[Command prompt template]
$ARGUMENTS
```
2025-10-28 12:48:17 -05:00
## 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
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
💡 **Tip**: Start with manual prompts, identify repetition, then create commands. Commands are for workflows you use 3+ times.
2025-10-28 12:28:48 -05:00
---
2025-10-28 12:48:17 -05:00
**Remember**: Slash commands = reusable prompts. Keep them simple, specific, and secure.