Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for developing custom slash commands for Claude Code plugins from the official Anthropic repository.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: Command Development3description: This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.4version: 0.2.05---67# Command Development for Claude Code89## Overview1011Slash commands are frequently-used prompts defined as Markdown files that Claude executes during interactive sessions. Understanding command structure, frontmatter options, and dynamic features enables creating powerful, reusable workflows.1213**Key concepts:**14- Markdown file format for commands15- YAML frontmatter for configuration16- Dynamic arguments and file references17- Bash execution for context18- Command organization and namespacing1920## Command Basics2122### What is a Slash Command?2324A slash command is a Markdown file containing a prompt that Claude executes when invoked. Commands provide:25- **Reusability**: Define once, use repeatedly26- **Consistency**: Standardize common workflows27- **Sharing**: Distribute across team or projects28- **Efficiency**: Quick access to complex prompts2930### Critical: Commands are Instructions FOR Claude3132**Commands are written for agent consumption, not human consumption.**3334When a user invokes `/command-name`, the command content becomes Claude's instructions. Write commands as directives TO Claude about what to do, not as messages TO the user.3536**Correct approach (instructions for Claude):**37```markdown38Review this code for security vulnerabilities including:39- SQL injection40- XSS attacks41- Authentication issues4243Provide specific line numbers and severity ratings.44```4546**Incorrect approach (messages to user):**47```markdown48This command will review your code for security issues.49You'll receive a report with vulnerability details.50```5152The first example tells Claude what to do. The second tells the user what will happen but doesn't instruct Claude. Always use the first approach.5354### Command Locations5556**Project commands** (shared with team):57- Location: `.claude/commands/`58- Scope: Available in specific project59- Label: Shown as "(project)" in `/help`60- Use for: Team workflows, project-specific tasks6162**Personal commands** (available everywhere):63- Location: `~/.claude/commands/`64- Scope: Available in all projects65- Label: Shown as "(user)" in `/help`66- Use for: Personal workflows, cross-project utilities6768**Plugin commands** (bundled with plugins):69- Location: `plugin-name/commands/`70- Scope: Available when plugin installed71- Label: Shown as "(plugin-name)" in `/help`72- Use for: Plugin-specific functionality7374## File Format7576### Basic Structure7778Commands are Markdown files with `.md` extension:7980```81.claude/commands/82├── review.md # /review command83├── test.md # /test command84└── deploy.md # /deploy command85```8687**Simple command:**88```markdown89Review this code for security vulnerabilities including:90- SQL injection91- XSS attacks92- Authentication bypass93- Insecure data handling94```9596No frontmatter needed for basic commands.9798### With YAML Frontmatter99100Add configuration using YAML frontmatter:101102```markdown103---104description: Review code for security issues105allowed-tools: Read, Grep, Bash(git:*)106model: sonnet107---108109Review this code for security vulnerabilities...110```111112## YAML Frontmatter Fields113114### description115116**Purpose:** Brief description shown in `/help`117**Type:** String118**Default:** First line of command prompt119120```yaml121---122description: Review pull request for code quality123---124```125126**Best practice:** Clear, actionable description (under 60 characters)127128### allowed-tools129130**Purpose:** Specify which tools command can use131**Type:** String or Array132**Default:** Inherits from conversation133134```yaml135---136allowed-tools: Read, Write, Edit, Bash(git:*)137---138```139140**Patterns:**141- `Read, Write, Edit` - Specific tools142- `Bash(git:*)` - Bash with git commands only143- `*` - All tools (rarely needed)144145**Use when:** Command requires specific tool access146147### model148149**Purpose:** Specify model for command execution150**Type:** String (sonnet, opus, haiku)151**Default:** Inherits from conversation152153```yaml154---155model: haiku156---157```158159**Use cases:**160- `haiku` - Fast, simple commands161- `sonnet` - Standard workflows162- `opus` - Complex analysis163164### argument-hint165166**Purpose:** Document expected arguments for autocomplete167**Type:** String168**Default:** None169170```yaml171---172argument-hint: [pr-number] [priority] [assignee]173---174```175176**Benefits:**177- Helps users understand command arguments178- Improves command discovery179- Documents command interface180181### disable-model-invocation182183**Purpose:** Prevent SlashCommand tool from programmatically calling command184**Type:** Boolean185**Default:** false186187```yaml188---189disable-model-invocation: true190---191```192193**Use when:** Command should only be manually invoked194195## Dynamic Arguments196197### Using $ARGUMENTS198199Capture all arguments as single string:200201```markdown202---203description: Fix issue by number204argument-hint: [issue-number]205---206207Fix issue #$ARGUMENTS following our coding standards and best practices.208```209210**Usage:**211```212> /fix-issue 123213> /fix-issue 456214```215216**Expands to:**217```218Fix issue #123 following our coding standards...219Fix issue #456 following our coding standards...220```221222### Using Positional Arguments223224Capture individual arguments with `$1`, `$2`, `$3`, etc.:225226```markdown227---228description: Review PR with priority and assignee229argument-hint: [pr-number] [priority] [assignee]230---231232Review pull request #$1 with priority level $2.233After review, assign to $3 for follow-up.234```235236**Usage:**237```238> /review-pr 123 high alice239```240241**Expands to:**242```243Review pull request #123 with priority level high.244After review, assign to alice for follow-up.245```246247### Combining Arguments248249Mix positional and remaining arguments:250251```markdown252Deploy $1 to $2 environment with options: $3253```254255**Usage:**256```257> /deploy api staging --force --skip-tests258```259260**Expands to:**261```262Deploy api to staging environment with options: --force --skip-tests263```264265## File References266267### Using @ Syntax268269Include file contents in command:270271```markdown272---273description: Review specific file274argument-hint: [file-path]275---276277Review @$1 for:278- Code quality279- Best practices280- Potential bugs281```282283**Usage:**284```285> /review-file src/api/users.ts286```287288**Effect:** Claude reads `src/api/users.ts` before processing command289290### Multiple File References291292Reference multiple files:293294```markdown295Compare @src/old-version.js with @src/new-version.js296297Identify:298- Breaking changes299- New features300- Bug fixes301```302303### Static File References304305Reference known files without arguments:306307```markdown308Review @package.json and @tsconfig.json for consistency309310Ensure:311- TypeScript version matches312- Dependencies are aligned313- Build configuration is correct314```315316## Bash Execution in Commands317318Commands can execute bash commands inline to dynamically gather context before Claude processes the command. This is useful for including repository state, environment information, or project-specific context.319320**When to use:**321- Include dynamic context (git status, environment vars, etc.)322- Gather project/repository state323- Build context-aware workflows324325**Implementation details:**326For complete syntax, examples, and best practices, see `references/plugin-features-reference.md` section on bash execution. The reference includes the exact syntax and multiple working examples to avoid execution issues327328## Command Organization329330### Flat Structure331332Simple organization for small command sets:333334```335.claude/commands/336├── build.md337├── test.md338├── deploy.md339├── review.md340└── docs.md341```342343**Use when:** 5-15 commands, no clear categories344345### Namespaced Structure346347Organize commands in subdirectories:348349```350.claude/commands/351├── ci/352│ ├── build.md # /build (project:ci)353│ ├── test.md # /test (project:ci)354│ └── lint.md # /lint (project:ci)355├── git/356│ ├── commit.md # /commit (project:git)357│ └── pr.md # /pr (project:git)358└── docs/359├── generate.md # /generate (project:docs)360└── publish.md # /publish (project:docs)361```362363**Benefits:**364- Logical grouping by category365- Namespace shown in `/help`366- Easier to find related commands367368**Use when:** 15+ commands, clear categories369370## Best Practices371372### Command Design3733741. **Single responsibility:** One command, one task3752. **Clear descriptions:** Self-explanatory in `/help`3763. **Explicit dependencies:** Use `allowed-tools` when needed3774. **Document arguments:** Always provide `argument-hint`3785. **Consistent naming:** Use verb-noun pattern (review-pr, fix-issue)379380### Argument Handling3813821. **Validate arguments:** Check for required arguments in prompt3832. **Provide defaults:** Suggest defaults when arguments missing3843. **Document format:** Explain expected argument format3854. **Handle edge cases:** Consider missing or invalid arguments386387```markdown388---389argument-hint: [pr-number]390---391392$IF($1,393Review PR #$1,394Please provide a PR number. Usage: /review-pr [number]395)396```397398### File References3994001. **Explicit paths:** Use clear file paths4012. **Check existence:** Handle missing files gracefully4023. **Relative paths:** Use project-relative paths4034. **Glob support:** Consider using Glob tool for patterns404405### Bash Commands4064071. **Limit scope:** Use `Bash(git:*)` not `Bash(*)`4082. **Safe commands:** Avoid destructive operations4093. **Handle errors:** Consider command failures4104. **Keep fast:** Long-running commands slow invocation411412### Documentation4134141. **Add comments:** Explain complex logic4152. **Provide examples:** Show usage in comments4163. **List requirements:** Document dependencies4174. **Version commands:** Note breaking changes418419```markdown420---421description: Deploy application to environment422argument-hint: [environment] [version]423---424425<!--426Usage: /deploy [staging|production] [version]427Requires: AWS credentials configured428Example: /deploy staging v1.2.3429-->430431Deploy application to $1 environment using version $2...432```433434## Common Patterns435436### Review Pattern437438```markdown439---440description: Review code changes441allowed-tools: Read, Bash(git:*)442---443444Files changed: !`git diff --name-only`445446Review each file for:4471. Code quality and style4482. Potential bugs or issues4493. Test coverage4504. Documentation needs451452Provide specific feedback for each file.453```454455### Testing Pattern456457```markdown458---459description: Run tests for specific file460argument-hint: [test-file]461allowed-tools: Bash(npm:*)462---463464Run tests: !`npm test $1`465466Analyze results and suggest fixes for failures.467```468469### Documentation Pattern470471```markdown472---473description: Generate documentation for file474argument-hint: [source-file]475---476477Generate comprehensive documentation for @$1 including:478- Function/class descriptions479- Parameter documentation480- Return value descriptions481- Usage examples482- Edge cases and errors483```484485### Workflow Pattern486487```markdown488---489description: Complete PR workflow490argument-hint: [pr-number]491allowed-tools: Bash(gh:*), Read492---493494PR #$1 Workflow:4954961. Fetch PR: !`gh pr view $1`4972. Review changes4983. Run checks4994. Approve or request changes500```501502## Troubleshooting503504**Command not appearing:**505- Check file is in correct directory506- Verify `.md` extension present507- Ensure valid Markdown format508- Restart Claude Code509510**Arguments not working:**511- Verify `$1`, `$2` syntax correct512- Check `argument-hint` matches usage513- Ensure no extra spaces514515**Bash execution failing:**516- Check `allowed-tools` includes Bash517- Verify command syntax in backticks518- Test command in terminal first519- Check for required permissions520521**File references not working:**522- Verify `@` syntax correct523- Check file path is valid524- Ensure Read tool allowed525- Use absolute or project-relative paths526527## Plugin-Specific Features528529### CLAUDE_PLUGIN_ROOT Variable530531Plugin commands have access to `${CLAUDE_PLUGIN_ROOT}`, an environment variable that resolves to the plugin's absolute path.532533**Purpose:**534- Reference plugin files portably535- Execute plugin scripts536- Load plugin configuration537- Access plugin templates538539**Basic usage:**540541```markdown542---543description: Analyze using plugin script544allowed-tools: Bash(node:*)545---546547Run analysis: !`node ${CLAUDE_PLUGIN_ROOT}/scripts/analyze.js $1`548549Review results and report findings.550```551552**Common patterns:**553554```markdown555# Execute plugin script556!`bash ${CLAUDE_PLUGIN_ROOT}/scripts/script.sh`557558# Load plugin configuration559@${CLAUDE_PLUGIN_ROOT}/config/settings.json560561# Use plugin template562@${CLAUDE_PLUGIN_ROOT}/templates/report.md563564# Access plugin resources565@${CLAUDE_PLUGIN_ROOT}/docs/reference.md566```567568**Why use it:**569- Works across all installations570- Portable between systems571- No hardcoded paths needed572- Essential for multi-file plugins573574### Plugin Command Organization575576Plugin commands discovered automatically from `commands/` directory:577578```579plugin-name/580├── commands/581│ ├── foo.md # /foo (plugin:plugin-name)582│ ├── bar.md # /bar (plugin:plugin-name)583│ └── utils/584│ └── helper.md # /helper (plugin:plugin-name:utils)585└── plugin.json586```587588**Namespace benefits:**589- Logical command grouping590- Shown in `/help` output591- Avoid name conflicts592- Organize related commands593594**Naming conventions:**595- Use descriptive action names596- Avoid generic names (test, run)597- Consider plugin-specific prefix598- Use hyphens for multi-word names599600### Plugin Command Patterns601602**Configuration-based pattern:**603604```markdown605---606description: Deploy using plugin configuration607argument-hint: [environment]608allowed-tools: Read, Bash(*)609---610611Load configuration: @${CLAUDE_PLUGIN_ROOT}/config/$1-deploy.json612613Deploy to $1 using configuration settings.614Monitor deployment and report status.615```616617**Template-based pattern:**618619```markdown620---621description: Generate docs from template622argument-hint: [component]623---624625Template: @${CLAUDE_PLUGIN_ROOT}/templates/docs.md626627Generate documentation for $1 following template structure.628```629630**Multi-script pattern:**631632```markdown633---634description: Complete build workflow635allowed-tools: Bash(*)636---637638Build: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/build.sh`639Test: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/test.sh`640Package: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/package.sh`641642Review outputs and report workflow status.643```644645**See `references/plugin-features-reference.md` for detailed patterns.**646647## Integration with Plugin Components648649Commands can integrate with other plugin components for powerful workflows.650651### Agent Integration652653Launch plugin agents for complex tasks:654655```markdown656---657description: Deep code review658argument-hint: [file-path]659---660661Initiate comprehensive review of @$1 using the code-reviewer agent.662663The agent will analyze:664- Code structure665- Security issues666- Performance667- Best practices668669Agent uses plugin resources:670- ${CLAUDE_PLUGIN_ROOT}/config/rules.json671- ${CLAUDE_PLUGIN_ROOT}/checklists/review.md672```673674**Key points:**675- Agent must exist in `plugin/agents/` directory676- Claude uses Task tool to launch agent677- Document agent capabilities678- Reference plugin resources agent uses679680### Skill Integration681682Leverage plugin skills for specialized knowledge:683684```markdown685---686description: Document API with standards687argument-hint: [api-file]688---689690Document API in @$1 following plugin standards.691692Use the api-docs-standards skill to ensure:693- Complete endpoint documentation694- Consistent formatting695- Example quality696- Error documentation697698Generate production-ready API docs.699```700701**Key points:**702- Skill must exist in `plugin/skills/` directory703- Mention skill name to trigger invocation704- Document skill purpose705- Explain what skill provides706707### Hook Coordination708709Design commands that work with plugin hooks:710- Commands can prepare state for hooks to process711- Hooks execute automatically on tool events712- Commands should document expected hook behavior713- Guide Claude on interpreting hook output714715See `references/plugin-features-reference.md` for examples of commands that coordinate with hooks716717### Multi-Component Workflows718719Combine agents, skills, and scripts:720721```markdown722---723description: Comprehensive review workflow724argument-hint: [file]725allowed-tools: Bash(node:*), Read726---727728Target: @$1729730Phase 1 - Static Analysis:731!`node ${CLAUDE_PLUGIN_ROOT}/scripts/lint.js $1`732733Phase 2 - Deep Review:734Launch code-reviewer agent for detailed analysis.735736Phase 3 - Standards Check:737Use coding-standards skill for validation.738739Phase 4 - Report:740Template: @${CLAUDE_PLUGIN_ROOT}/templates/review.md741742Compile findings into report following template.743```744745**When to use:**746- Complex multi-step workflows747- Leverage multiple plugin capabilities748- Require specialized analysis749- Need structured outputs750751## Validation Patterns752753Commands should validate inputs and resources before processing.754755### Argument Validation756757```markdown758---759description: Deploy with validation760argument-hint: [environment]761---762763Validate environment: !`echo "$1" | grep -E "^(dev|staging|prod)$" || echo "INVALID"`764765If $1 is valid environment:766Deploy to $1767Otherwise:768Explain valid environments: dev, staging, prod769Show usage: /deploy [environment]770```771772### File Existence Checks773774```markdown775---776description: Process configuration777argument-hint: [config-file]778---779780Check file exists: !`test -f $1 && echo "EXISTS" || echo "MISSING"`781782If file exists:783Process configuration: @$1784Otherwise:785Explain where to place config file786Show expected format787Provide example configuration788```789790### Plugin Resource Validation791792```markdown793---794description: Run plugin analyzer795allowed-tools: Bash(test:*)796---797798Validate plugin setup:799- Script: !`test -x ${CLAUDE_PLUGIN_ROOT}/bin/analyze && echo "✓" || echo "✗"`800- Config: !`test -f ${CLAUDE_PLUGIN_ROOT}/config.json && echo "✓" || echo "✗"`801802If all checks pass, run analysis.803Otherwise, report missing components.804```805806### Error Handling807808```markdown809---810description: Build with error handling811allowed-tools: Bash(*)812---813814Execute build: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/build.sh 2>&1 || echo "BUILD_FAILED"`815816If build succeeded:817Report success and output location818If build failed:819Analyze error output820Suggest likely causes821Provide troubleshooting steps822```823824**Best practices:**825- Validate early in command826- Provide helpful error messages827- Suggest corrective actions828- Handle edge cases gracefully829830---831832For detailed frontmatter field specifications, see `references/frontmatter-reference.md`.833For plugin-specific features and patterns, see `references/plugin-features-reference.md`.834For command pattern examples, see `examples/` directory.835