Files
2025-10-28 12:48:17 -05:00

4.9 KiB

name, description
name description
Slash Command Creator 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/:

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

---
description: Brief description for /help
---

Prompt content here

$ARGUMENTS

File name = Command name: review.md/review

Frontmatter Options

---
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

$ARGUMENTS          # All arguments
$1, $2, $3          # Positional arguments
@$1 or @file.js     # Load file content

Examples:

/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:

---
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

---
description: Review code quality
---

Review @$1 for:
1. Logic errors
2. Code style
3. Performance issues

Provide specific fixes.

Multi-Step Workflow

---
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

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

# 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

Security

Limit permissions:

# ✓ Specific
allowed-tools: Bash(git status:*), Bash(git diff:*)

# ✗ Too broad
allowed-tools: *

No secrets:

# ✗ Bad
!curl -H "API-Key: sk-abc123..."

# ✓ Good
!curl -H "API-Key: $MY_API_KEY"

Command Template

---
description: [Clear, concise description]
argument-hint: [Expected arguments]
allowed-tools: [Specific patterns if needed]
---

[Command prompt template]

$ARGUMENTS

Additional Resources

Need more?

💡 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.