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/documentation-patterns.md
1# Command Documentation Patterns23Strategies for creating self-documenting, maintainable commands with excellent user experience.45## Overview67Well-documented commands are easier to use, maintain, and distribute. Documentation should be embedded in the command itself, making it immediately accessible to users and maintainers.89## Self-Documenting Command Structure1011### Complete Command Template1213```markdown14---15description: Clear, actionable description under 60 chars16argument-hint: [arg1] [arg2] [optional-arg]17allowed-tools: Read, Bash(git:*)18model: sonnet19---2021<!--22COMMAND: command-name23VERSION: 1.0.024AUTHOR: Team Name25LAST UPDATED: 2025-01-152627PURPOSE:28Detailed explanation of what this command does and why it exists.2930USAGE:31/command-name arg1 arg23233ARGUMENTS:34arg1: Description of first argument (required)35arg2: Description of second argument (optional, defaults to X)3637EXAMPLES:38/command-name feature-branch main39→ Compares feature-branch with main4041/command-name my-branch42→ Compares my-branch with current branch4344REQUIREMENTS:45- Git repository46- Branch must exist47- Permissions to read repository4849RELATED COMMANDS:50/other-command - Related functionality51/another-command - Alternative approach5253TROUBLESHOOTING:54- If branch not found: Check branch name spelling55- If permission denied: Check repository access5657CHANGELOG:58v1.0.0 (2025-01-15): Initial release59v0.9.0 (2025-01-10): Beta version60-->6162# Command Implementation6364[Command prompt content here...]6566[Explain what will happen...]6768[Guide user through steps...]6970[Provide clear output...]71```7273### Documentation Comment Sections7475**PURPOSE**: Why the command exists76- Problem it solves77- Use cases78- When to use vs when not to use7980**USAGE**: Basic syntax81- Command invocation pattern82- Required vs optional arguments83- Default values8485**ARGUMENTS**: Detailed argument documentation86- Each argument described87- Type information88- Valid values/ranges89- Defaults9091**EXAMPLES**: Concrete usage examples92- Common use cases93- Edge cases94- Expected outputs9596**REQUIREMENTS**: Prerequisites97- Dependencies98- Permissions99- Environmental setup100101**RELATED COMMANDS**: Connections102- Similar commands103- Complementary commands104- Alternative approaches105106**TROUBLESHOOTING**: Common issues107- Known problems108- Solutions109- Workarounds110111**CHANGELOG**: Version history112- What changed when113- Breaking changes highlighted114- Migration guidance115116## In-Line Documentation Patterns117118### Commented Sections119120```markdown121---122description: Complex multi-step command123---124125<!-- SECTION 1: VALIDATION -->126<!-- This section checks prerequisites before proceeding -->127128Checking prerequisites...129- Git repository: !`git rev-parse --git-dir 2>/dev/null`130- Branch exists: [validation logic]131132<!-- SECTION 2: ANALYSIS -->133<!-- Analyzes the differences between branches -->134135Analyzing differences between $1 and $2...136[Analysis logic...]137138<!-- SECTION 3: RECOMMENDATIONS -->139<!-- Provides actionable recommendations -->140141Based on analysis, recommend:142[Recommendations...]143144<!-- END: Next steps for user -->145```146147### Inline Explanations148149```markdown150---151description: Deployment command with inline docs152---153154# Deploy to $1155156## Pre-flight Checks157158<!-- We check branch status to prevent deploying from wrong branch -->159Current branch: !`git branch --show-current`160161<!-- Production deploys must come from main/master -->162if [ "$1" = "production" ] && [ "$(git branch --show-current)" != "main" ]; then163⚠️ WARNING: Not on main branch for production deploy164This is unusual. Confirm this is intentional.165fi166167<!-- Test status ensures we don't deploy broken code -->168Running tests: !`npm test`169170✓ All checks passed171172## Deployment173174<!-- Actual deployment happens here -->175<!-- Uses blue-green strategy for zero-downtime -->176Deploying to $1 environment...177[Deployment steps...]178179<!-- Post-deployment verification -->180Verifying deployment health...181[Health checks...]182183Deployment complete!184185## Next Steps186187<!-- Guide user on what to do after deployment -->1881. Monitor logs: /logs $11892. Run smoke tests: /smoke-test $11903. Notify team: /notify-deployment $1191```192193### Decision Point Documentation194195```markdown196---197description: Interactive deployment command198---199200# Interactive Deployment201202## Configuration Review203204Target: $1205Current version: !`cat version.txt`206New version: $2207208<!-- DECISION POINT: User confirms configuration -->209<!-- This pause allows user to verify everything is correct -->210<!-- We can't automatically proceed because deployment is risky -->211212Review the above configuration.213214**Continue with deployment?**215- Reply "yes" to proceed216- Reply "no" to cancel217- Reply "edit" to modify configuration218219[Await user input before continuing...]220221<!-- After user confirms, we proceed with deployment -->222<!-- All subsequent steps are automated -->223224Proceeding with deployment...225```226227## Help Text Patterns228229### Built-in Help Command230231Create a help subcommand for complex commands:232233```markdown234---235description: Main command with help236argument-hint: [subcommand] [args]237---238239# Command Processor240241if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then242**Command Help**243244USAGE:245/command [subcommand] [args]246247SUBCOMMANDS:248init [name] Initialize new configuration249deploy [env] Deploy to environment250status Show current status251rollback Rollback last deployment252help Show this help253254EXAMPLES:255/command init my-project256/command deploy staging257/command status258/command rollback259260For detailed help on a subcommand:261/command [subcommand] --help262263Exit.264fi265266[Regular command processing...]267```268269### Contextual Help270271Provide help based on context:272273```markdown274---275description: Context-aware command276argument-hint: [operation] [target]277---278279# Context-Aware Operation280281if [ -z "$1" ]; then282**No operation specified**283284Available operations:285- analyze: Analyze target for issues286- fix: Apply automatic fixes287- report: Generate detailed report288289Usage: /command [operation] [target]290291Examples:292/command analyze src/293/command fix src/app.js294/command report295296Run /command help for more details.297298Exit.299fi300301[Command continues if operation provided...]302```303304## Error Message Documentation305306### Helpful Error Messages307308```markdown309---310description: Command with good error messages311---312313# Validation Command314315if [ -z "$1" ]; then316❌ ERROR: Missing required argument317318The 'file-path' argument is required.319320USAGE:321/validate [file-path]322323EXAMPLE:324/validate src/app.js325326Try again with a file path.327328Exit.329fi330331if [ ! -f "$1" ]; then332❌ ERROR: File not found: $1333334The specified file does not exist or is not accessible.335336COMMON CAUSES:3371. Typo in file path3382. File was deleted or moved3393. Insufficient permissions340341SUGGESTIONS:342- Check spelling: $1343- Verify file exists: ls -la $(dirname "$1")344- Check permissions: ls -l "$1"345346Exit.347fi348349[Command continues if validation passes...]350```351352### Error Recovery Guidance353354```markdown355---356description: Command with recovery guidance357---358359# Operation Command360361Running operation...362363!`risky-operation.sh`364365if [ $? -ne 0 ]; then366❌ OPERATION FAILED367368The operation encountered an error and could not complete.369370WHAT HAPPENED:371The risky-operation.sh script returned a non-zero exit code.372373WHAT THIS MEANS:374- Changes may be partially applied375- System may be in inconsistent state376- Manual intervention may be needed377378RECOVERY STEPS:3791. Check operation logs: cat /tmp/operation.log3802. Verify system state: /check-state3813. If needed, rollback: /rollback-operation3824. Fix underlying issue3835. Retry operation: /retry-operation384385NEED HELP?386- Check troubleshooting guide: /help troubleshooting387- Contact support with error code: ERR_OP_FAILED_001388389Exit.390fi391```392393## Usage Example Documentation394395### Embedded Examples396397```markdown398---399description: Command with embedded examples400---401402# Feature Command403404This command performs feature analysis with multiple options.405406## Basic Usage407408\`\`\`409/feature analyze src/410\`\`\`411412Analyzes all files in src/ directory for feature usage.413414## Advanced Usage415416\`\`\`417/feature analyze src/ --detailed418\`\`\`419420Provides detailed analysis including:421- Feature breakdown by file422- Usage patterns423- Optimization suggestions424425## Use Cases426427**Use Case 1: Quick overview**428\`\`\`429/feature analyze .430\`\`\`431Get high-level feature summary of entire project.432433**Use Case 2: Specific directory**434\`\`\`435/feature analyze src/components436\`\`\`437Focus analysis on components directory only.438439**Use Case 3: Comparison**440\`\`\`441/feature analyze src/ --compare baseline.json442\`\`\`443Compare current features against baseline.444445---446447Now processing your request...448449[Command implementation...]450```451452### Example-Driven Documentation453454```markdown455---456description: Example-heavy command457---458459# Transformation Command460461## What This Does462463Transforms data from one format to another.464465## Examples First466467### Example 1: JSON to YAML468**Input:** `data.json`469\`\`\`json470{"name": "test", "value": 42}471\`\`\`472473**Command:** `/transform data.json yaml`474475**Output:** `data.yaml`476\`\`\`yaml477name: test478value: 42479\`\`\`480481### Example 2: CSV to JSON482**Input:** `data.csv`483\`\`\`csv484name,value485test,42486\`\`\`487488**Command:** `/transform data.csv json`489490**Output:** `data.json`491\`\`\`json492[{"name": "test", "value": "42"}]493\`\`\`494495### Example 3: With Options496**Command:** `/transform data.json yaml --pretty --sort-keys`497498**Result:** Formatted YAML with sorted keys499500---501502## Your Transformation503504File: $1505Format: $2506507[Perform transformation...]508```509510## Maintenance Documentation511512### Version and Changelog513514```markdown515<!--516VERSION: 2.1.0517LAST UPDATED: 2025-01-15518AUTHOR: DevOps Team519520CHANGELOG:521v2.1.0 (2025-01-15):522- Added support for YAML configuration523- Improved error messages524- Fixed bug with special characters in arguments525526v2.0.0 (2025-01-01):527- BREAKING: Changed argument order528- BREAKING: Removed deprecated --old-flag529- Added new validation checks530- Migration guide: /migration-v2531532v1.5.0 (2024-12-15):533- Added --verbose flag534- Improved performance by 50%535536v1.0.0 (2024-12-01):537- Initial stable release538539MIGRATION NOTES:540From v1.x to v2.0:541Old: /command arg1 arg2 --old-flag542New: /command arg2 arg1543544The --old-flag is removed. Use --new-flag instead.545546DEPRECATION WARNINGS:547- The --legacy-mode flag is deprecated as of v2.1.0548- Will be removed in v3.0.0 (estimated 2025-06-01)549- Use --modern-mode instead550551KNOWN ISSUES:552- #123: Slow performance with large files (workaround: use --stream flag)553- #456: Special characters in Windows (fix planned for v2.2.0)554-->555```556557### Maintenance Notes558559```markdown560<!--561MAINTENANCE NOTES:562563CODE STRUCTURE:564- Lines 1-50: Argument parsing and validation565- Lines 51-100: Main processing logic566- Lines 101-150: Output formatting567- Lines 151-200: Error handling568569DEPENDENCIES:570- Requires git 2.x or later571- Uses jq for JSON processing572- Needs bash 4.0+ for associative arrays573574PERFORMANCE:575- Fast path for small inputs (< 1MB)576- Streams large files to avoid memory issues577- Caches results in /tmp for 1 hour578579SECURITY CONSIDERATIONS:580- Validates all inputs to prevent injection581- Uses allowed-tools to limit Bash access582- No credentials in command file583584TESTING:585- Unit tests: tests/command-test.sh586- Integration tests: tests/integration/587- Manual test checklist: tests/manual-checklist.md588589FUTURE IMPROVEMENTS:590- TODO: Add support for TOML format591- TODO: Implement parallel processing592- TODO: Add progress bar for large files593594RELATED FILES:595- lib/parser.sh: Shared parsing logic596- lib/formatter.sh: Output formatting597- config/defaults.yml: Default configuration598-->599```600601## README Documentation602603Commands should have companion README files:604605```markdown606# Command Name607608Brief description of what the command does.609610## Installation611612This command is part of the [plugin-name] plugin.613614Install with:615\`\`\`616/plugin install plugin-name617\`\`\`618619## Usage620621Basic usage:622\`\`\`623/command-name [arg1] [arg2]624\`\`\`625626## Arguments627628- `arg1`: Description (required)629- `arg2`: Description (optional, defaults to X)630631## Examples632633### Example 1: Basic Usage634\`\`\`635/command-name value1 value2636\`\`\`637638Description of what happens.639640### Example 2: Advanced Usage641\`\`\`642/command-name value1 --option643\`\`\`644645Description of advanced feature.646647## Configuration648649Optional configuration file: `.claude/command-name.local.md`650651\`\`\`markdown652---653default_arg: value654enable_feature: true655---656\`\`\`657658## Requirements659660- Git 2.x or later661- jq (for JSON processing)662- Node.js 14+ (optional, for advanced features)663664## Troubleshooting665666### Issue: Command not found667668**Solution:** Ensure plugin is installed and enabled.669670### Issue: Permission denied671672**Solution:** Check file permissions and allowed-tools setting.673674## Contributing675676Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).677678## License679680MIT License - See [LICENSE](LICENSE).681682## Support683684- Issues: https://github.com/user/plugin/issues685- Docs: https://docs.example.com686- Email: [email protected]687```688689## Best Practices690691### Documentation Principles6926931. **Write for your future self**: Assume you'll forget details6942. **Examples before explanations**: Show, then tell6953. **Progressive disclosure**: Basic info first, details available6964. **Keep it current**: Update docs when code changes6975. **Test your docs**: Verify examples actually work698699### Documentation Locations7007011. **In command file**: Core usage, examples, inline explanations7022. **README**: Installation, configuration, troubleshooting7033. **Separate docs**: Detailed guides, tutorials, API reference7044. **Comments**: Implementation details for maintainers705706### Documentation Style7077081. **Clear and concise**: No unnecessary words7092. **Active voice**: "Run the command" not "The command can be run"7103. **Consistent terminology**: Use same terms throughout7114. **Formatted well**: Use headings, lists, code blocks7125. **Accessible**: Assume reader is beginner713714### Documentation Maintenance7157161. **Version everything**: Track what changed when7172. **Deprecate gracefully**: Warn before removing features7183. **Migration guides**: Help users upgrade7194. **Archive old docs**: Keep old versions accessible7205. **Review regularly**: Ensure docs match reality721722## Documentation Checklist723724Before releasing a command:725726- [ ] Description in frontmatter is clear727- [ ] argument-hint documents all arguments728- [ ] Usage examples in comments729- [ ] Common use cases shown730- [ ] Error messages are helpful731- [ ] Requirements documented732- [ ] Related commands listed733- [ ] Changelog maintained734- [ ] Version number updated735- [ ] README created/updated736- [ ] Examples actually work737- [ ] Troubleshooting section complete738739With good documentation, commands become self-service, reducing support burden and improving user experience.740