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.
references/plugin-features-reference.md
1# Plugin-Specific Command Features Reference23This reference covers features and patterns specific to commands bundled in Claude Code plugins.45## Table of Contents67- [Plugin Command Discovery](#plugin-command-discovery)8- [CLAUDE_PLUGIN_ROOT Environment Variable](#claude_plugin_root-environment-variable)9- [Plugin Command Patterns](#plugin-command-patterns)10- [Integration with Plugin Components](#integration-with-plugin-components)11- [Validation Patterns](#validation-patterns)1213## Plugin Command Discovery1415### Auto-Discovery1617Claude Code automatically discovers commands in plugins using the following locations:1819```20plugin-name/21├── commands/ # Auto-discovered commands22│ ├── foo.md # /foo (plugin:plugin-name)23│ └── bar.md # /bar (plugin:plugin-name)24└── plugin.json # Plugin manifest25```2627**Key points:**28- Commands are discovered at plugin load time29- No manual registration required30- Commands appear in `/help` with "(plugin:plugin-name)" label31- Subdirectories create namespaces3233### Namespaced Plugin Commands3435Organize commands in subdirectories for logical grouping:3637```38plugin-name/39└── commands/40├── review/41│ ├── security.md # /security (plugin:plugin-name:review)42│ └── style.md # /style (plugin:plugin-name:review)43└── deploy/44├── staging.md # /staging (plugin:plugin-name:deploy)45└── prod.md # /prod (plugin:plugin-name:deploy)46```4748**Namespace behavior:**49- Subdirectory name becomes namespace50- Shown as "(plugin:plugin-name:namespace)" in `/help`51- Helps organize related commands52- Use when plugin has 5+ commands5354### Command Naming Conventions5556**Plugin command names should:**571. Be descriptive and action-oriented582. Avoid conflicts with common command names593. Use hyphens for multi-word names604. Consider prefixing with plugin name for uniqueness6162**Examples:**63```64Good:65- /mylyn-sync (plugin-specific prefix)66- /analyze-performance (descriptive action)67- /docker-compose-up (clear purpose)6869Avoid:70- /test (conflicts with common name)71- /run (too generic)72- /do-stuff (not descriptive)73```7475## CLAUDE_PLUGIN_ROOT Environment Variable7677### Purpose7879`${CLAUDE_PLUGIN_ROOT}` is a special environment variable available in plugin commands that resolves to the absolute path of the plugin directory.8081**Why it matters:**82- Enables portable paths within plugin83- Allows referencing plugin files and scripts84- Works across different installations85- Essential for multi-file plugin operations8687### Basic Usage8889Reference files within your plugin:9091```markdown92---93description: Analyze using plugin script94allowed-tools: Bash(node:*), Read95---9697Run analysis: !`node ${CLAUDE_PLUGIN_ROOT}/scripts/analyze.js`9899Read template: @${CLAUDE_PLUGIN_ROOT}/templates/report.md100```101102**Expands to:**103```104Run analysis: !`node /path/to/plugins/plugin-name/scripts/analyze.js`105106Read template: @/path/to/plugins/plugin-name/templates/report.md107```108109### Common Patterns110111#### 1. Executing Plugin Scripts112113```markdown114---115description: Run custom linter from plugin116allowed-tools: Bash(node:*)117---118119Lint results: !`node ${CLAUDE_PLUGIN_ROOT}/bin/lint.js $1`120121Review the linting output and suggest fixes.122```123124#### 2. Loading Configuration Files125126```markdown127---128description: Deploy using plugin configuration129allowed-tools: Read, Bash(*)130---131132Configuration: @${CLAUDE_PLUGIN_ROOT}/config/deploy-config.json133134Deploy application using the configuration above for $1 environment.135```136137#### 3. Accessing Plugin Resources138139```markdown140---141description: Generate report from template142---143144Use this template: @${CLAUDE_PLUGIN_ROOT}/templates/api-report.md145146Generate a report for @$1 following the template format.147```148149#### 4. Multi-Step Plugin Workflows150151```markdown152---153description: Complete plugin workflow154allowed-tools: Bash(*), Read155---156157Step 1 - Prepare: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/prepare.sh $1`158Step 2 - Config: @${CLAUDE_PLUGIN_ROOT}/config/$1.json159Step 3 - Execute: !`${CLAUDE_PLUGIN_ROOT}/bin/execute $1`160161Review results and report status.162```163164### Best Practices1651661. **Always use for plugin-internal paths:**167```markdown168# Good169@${CLAUDE_PLUGIN_ROOT}/templates/foo.md170171# Bad172@./templates/foo.md # Relative to current directory, not plugin173```1741752. **Validate file existence:**176```markdown177---178description: Use plugin config if exists179allowed-tools: Bash(test:*), Read180---181182!`test -f ${CLAUDE_PLUGIN_ROOT}/config.json && echo "exists" || echo "missing"`183184If config exists, load it: @${CLAUDE_PLUGIN_ROOT}/config.json185Otherwise, use defaults...186```1871883. **Document plugin file structure:**189```markdown190<!--191Plugin structure:192${CLAUDE_PLUGIN_ROOT}/193├── scripts/analyze.js (analysis script)194├── templates/ (report templates)195└── config/ (configuration files)196-->197```1981994. **Combine with arguments:**200```markdown201Run: !`${CLAUDE_PLUGIN_ROOT}/bin/process.sh $1 $2`202```203204### Troubleshooting205206**Variable not expanding:**207- Ensure command is loaded from plugin208- Check bash execution is allowed209- Verify syntax is exact: `${CLAUDE_PLUGIN_ROOT}`210211**File not found errors:**212- Verify file exists in plugin directory213- Check file path is correct relative to plugin root214- Ensure file permissions allow reading/execution215216**Path with spaces:**217- Bash commands automatically handle spaces218- File references work with spaces in paths219- No special quoting needed220221## Plugin Command Patterns222223### Pattern 1: Configuration-Based Commands224225Commands that load plugin-specific configuration:226227```markdown228---229description: Deploy using plugin settings230allowed-tools: Read, Bash(*)231---232233Load configuration: @${CLAUDE_PLUGIN_ROOT}/deploy-config.json234235Deploy to $1 environment using:2361. Configuration settings above2372. Current git branch: !`git branch --show-current`2383. Application version: !`cat package.json | grep version`239240Execute deployment and monitor progress.241```242243**When to use:** Commands that need consistent settings across invocations244245### Pattern 2: Template-Based Generation246247Commands that use plugin templates:248249```markdown250---251description: Generate documentation from template252argument-hint: [component-name]253---254255Template: @${CLAUDE_PLUGIN_ROOT}/templates/component-docs.md256257Generate documentation for $1 component following the template structure.258Include:259- Component purpose and usage260- API reference261- Examples262- Testing guidelines263```264265**When to use:** Standardized output generation266267### Pattern 3: Multi-Script Workflow268269Commands that orchestrate multiple plugin scripts:270271```markdown272---273description: Complete build and test workflow274allowed-tools: Bash(*)275---276277Build: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/build.sh`278Validate: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh`279Test: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/test.sh`280281Review all outputs and report:2821. Build status2832. Validation results2843. Test results2854. Recommended next steps286```287288**When to use:** Complex plugin workflows with multiple steps289290### Pattern 4: Environment-Aware Commands291292Commands that adapt to environment:293294```markdown295---296description: Deploy based on environment297argument-hint: [dev|staging|prod]298---299300Environment config: @${CLAUDE_PLUGIN_ROOT}/config/$1.json301302Environment check: !`echo "Deploying to: $1"`303304Deploy application using $1 environment configuration.305Verify deployment and run smoke tests.306```307308**When to use:** Commands that behave differently per environment309310### Pattern 5: Plugin Data Management311312Commands that manage plugin-specific data:313314```markdown315---316description: Save analysis results to plugin cache317allowed-tools: Bash(*), Read, Write318---319320Cache directory: ${CLAUDE_PLUGIN_ROOT}/cache/321322Analyze @$1 and save results to cache:323!`mkdir -p ${CLAUDE_PLUGIN_ROOT}/cache && date > ${CLAUDE_PLUGIN_ROOT}/cache/last-run.txt`324325Store analysis for future reference and comparison.326```327328**When to use:** Commands that need persistent data storage329330## Integration with Plugin Components331332### Invoking Plugin Agents333334Commands can trigger plugin agents using the Task tool:335336```markdown337---338description: Deep analysis using plugin agent339argument-hint: [file-path]340---341342Initiate deep code analysis of @$1 using the code-analyzer agent.343344The agent will:3451. Analyze code structure3462. Identify patterns3473. Suggest improvements3484. Generate detailed report349350Note: This uses the Task tool to launch the plugin's code-analyzer agent.351```352353**Key points:**354- Agent must be defined in plugin's `agents/` directory355- Claude will automatically use Task tool to launch agent356- Agent has access to same plugin resources357358### Invoking Plugin Skills359360Commands can reference plugin skills for specialized knowledge:361362```markdown363---364description: API documentation with best practices365argument-hint: [api-file]366---367368Document the API in @$1 following our API documentation standards.369370Use the api-docs-standards skill to ensure documentation includes:371- Endpoint descriptions372- Parameter specifications373- Response formats374- Error codes375- Usage examples376377Note: This leverages the plugin's api-docs-standards skill for consistency.378```379380**Key points:**381- Skill must be defined in plugin's `skills/` directory382- Mention skill by name to hint Claude should invoke it383- Skills provide specialized domain knowledge384385### Coordinating with Plugin Hooks386387Commands can be designed to work with plugin hooks:388389```markdown390---391description: Commit with pre-commit validation392allowed-tools: Bash(git:*)393---394395Stage changes: !\`git add $1\`396397Commit changes: !\`git commit -m "$2"\`398399Note: This commit will trigger the plugin's pre-commit hook for validation.400Review hook output for any issues.401```402403**Key points:**404- Hooks execute automatically on events405- Commands can prepare state for hooks406- Document hook interaction in command407408### Multi-Component Plugin Commands409410Commands that coordinate multiple plugin components:411412```markdown413---414description: Comprehensive code review workflow415argument-hint: [file-path]416---417418File to review: @$1419420Execute comprehensive review:4214221. **Static Analysis** (via plugin scripts)423!`node ${CLAUDE_PLUGIN_ROOT}/scripts/lint.js $1`4244252. **Deep Review** (via plugin agent)426Launch the code-reviewer agent for detailed analysis.4274283. **Best Practices** (via plugin skill)429Use the code-standards skill to ensure compliance.4304314. **Documentation** (via plugin template)432Template: @${CLAUDE_PLUGIN_ROOT}/templates/review-report.md433434Generate final report combining all outputs.435```436437**When to use:** Complex workflows leveraging multiple plugin capabilities438439## Validation Patterns440441### Input Validation442443Commands should validate inputs before processing:444445```markdown446---447description: Deploy to environment with validation448argument-hint: [environment]449---450451Validate environment: !`echo "$1" | grep -E "^(dev|staging|prod)$" || echo "INVALID"`452453$IF($1 in [dev, staging, prod],454Deploy to $1 environment using validated configuration,455ERROR: Invalid environment '$1'. Must be one of: dev, staging, prod456)457```458459**Validation approaches:**4601. Bash validation using grep/test4612. Inline validation in prompt4623. Script-based validation463464### File Existence Checks465466Verify required files exist:467468```markdown469---470description: Process configuration file471argument-hint: [config-file]472---473474Check file: !`test -f $1 && echo "EXISTS" || echo "MISSING"`475476Process configuration if file exists: @$1477478If file doesn't exist, explain:479- Expected location480- Required format481- How to create it482```483484### Required Arguments485486Validate required arguments provided:487488```markdown489---490description: Create deployment with version491argument-hint: [environment] [version]492---493494Validate inputs: !`test -n "$1" -a -n "$2" && echo "OK" || echo "MISSING"`495496$IF($1 AND $2,497Deploy version $2 to $1 environment,498ERROR: Both environment and version required. Usage: /deploy [env] [version]499)500```501502### Plugin Resource Validation503504Verify plugin resources available:505506```markdown507---508description: Run analysis with plugin tools509allowed-tools: Bash(test:*)510---511512Validate plugin setup:513- Config exists: !`test -f ${CLAUDE_PLUGIN_ROOT}/config.json && echo "✓" || echo "✗"`514- Scripts exist: !`test -d ${CLAUDE_PLUGIN_ROOT}/scripts && echo "✓" || echo "✗"`515- Tools available: !`test -x ${CLAUDE_PLUGIN_ROOT}/bin/analyze && echo "✓" || echo "✗"`516517If all checks pass, proceed with analysis.518Otherwise, report missing components and installation steps.519```520521### Output Validation522523Validate command execution results:524525```markdown526---527description: Build and validate output528allowed-tools: Bash(*)529---530531Build: !`bash ${CLAUDE_PLUGIN_ROOT}/scripts/build.sh`532533Validate output:534- Exit code: !`echo $?`535- Output exists: !`test -d dist && echo "✓" || echo "✗"`536- File count: !`find dist -type f | wc -l`537538Report build status and any validation failures.539```540541### Graceful Error Handling542543Handle errors gracefully with helpful messages:544545```markdown546---547description: Process file with error handling548argument-hint: [file-path]549---550551Try processing: !`node ${CLAUDE_PLUGIN_ROOT}/scripts/process.js $1 2>&1 || echo "ERROR: $?"`552553If processing succeeded:554- Report results555- Suggest next steps556557If processing failed:558- Explain likely causes559- Provide troubleshooting steps560- Suggest alternative approaches561```562563## Best Practices Summary564565### Plugin Commands Should:5665671. **Use ${CLAUDE_PLUGIN_ROOT} for all plugin-internal paths**568- Scripts, templates, configuration, resources5695702. **Validate inputs early**571- Check required arguments572- Verify file existence573- Validate argument formats5745753. **Document plugin structure**576- Explain required files577- Document script purposes578- Clarify dependencies5795804. **Integrate with plugin components**581- Reference agents for complex tasks582- Use skills for specialized knowledge583- Coordinate with hooks when relevant5845855. **Provide helpful error messages**586- Explain what went wrong587- Suggest how to fix588- Offer alternatives5895906. **Handle edge cases**591- Missing files592- Invalid arguments593- Failed script execution594- Missing dependencies5955967. **Keep commands focused**597- One clear purpose per command598- Delegate complex logic to scripts599- Use agents for multi-step workflows6006018. **Test across installations**602- Verify paths work everywhere603- Test with different arguments604- Validate error cases605606---607608For general command development, see main SKILL.md.609For command examples, see examples/ directory.610