Guide for creating effective custom slash commands...
This skill provides comprehensive guidance for designing and implementing custom slash commands that are minimal, explicit, and leverage Claude Code's full capabilities including preflight checks, skill integration, and subagent delegation.
Before creating or reviewing a command, fetch the latest official documentation using WebFetch for the most relevant links below. This ensures your commands follow current best practices and API conventions.
IMPORTANT: When this skill is invoked, you MUST use WebFetch to retrieve at least the primary reference before proceeding with command creation or review.
Use slash commands for:
Use skills for:
Rule of thumb: If it's getting complex (>200 lines or needs multiple resource files), it should be a skill instead.
To create a command, follow the "Command Creation Process" in order, skipping steps only if there is a clear reason why they are not applicable.
Skip this step only when the command's usage patterns are already clearly understood.
To create an effective command, clearly understand concrete examples of how the command will be used. This understanding can come from either direct user examples or generated examples that are validated with user feedback.
For example, when building a command for atomic commits:
To avoid overwhelming users, avoid asking too many questions in a single message. Start with the most important questions and follow up as needed for better effectiveness.
Conclude this step when there is a clear sense of the functionality the command should support.
To turn concrete examples into an effective command, analyze each example by:
Example: When building a /quick-commit command for "create atomic commit with message," the analysis shows:
Example: When building a /review-pr command for "review pull request for quality," the analysis shows:
To establish the command structure, analyze each concrete example to identify:
allowed-tools, argument-hint, description, model)Commands are single markdown files with four required sections. Create the command file following this structure:
File location:
.claude/commands/command-name.md~/.claude/commands/command-name.mdCommand structure template:
---
allowed-tools: Bash(cmd1:*), Bash(cmd2:*), Read, Edit
argument-hint: <required> [optional]
description: Brief description under 10 words
model: sonnet
---
## Preflight Checks
- Check description: !`bash command`
- Another check: !`bash command`
## Context
- Context description: !`bash command`
- File context: @path/to/file.ext
- Skills to reference: @skill-name
## Task Instructions
Explicitly describe what Claude should do:
1. First step (use specific skill if applicable)
2. Second step (delegate to subagent if needed)
3. Final step with verification
## Success Criteria
- What should be true when complete
- How to verify the command succeeded
Writing guidelines:
allowed-tools (never bare Bash), concise description (~10 words), appropriate model (sonnet default, haiku for simple tasks)! prefix for bash commands, validate all prerequisites before execution! commands and @ referencesPrompt Engineering for Task Instructions: Command task instructions are prompts that Claude will execute. Invoke Skill(command='crafting-agentic-prompts') for guidance on writing effective agentic prompts including:
This skill provides proven patterns for creating prompts that drive effective agent behavior.
For detailed patterns and examples, see reference files:
references/preflight-patterns.md - Validation check patternsreferences/context-patterns.md - Context gathering patternsreferences/tool-patterns.md - Skill/Task/TodoWrite patternsreferences/examples.md - 8 production-ready command examplesreferences/advanced-patterns.md - Complex scenarios (args, recovery, performance)Use the validation script with --minimal flag for rapid iteration during development:
python3 scripts/validate_command.py /path/to/command.md --minimal
Iterative workflow:
--minimal validation--minimal) for final checkUse --minimal mode early and often. It provides:
Desired outcome: 100% pass rate (17/17 checks) before proceeding to quality review.
Mandatory gate before deployment. Two options:
Option A: Self-review
Follow references/command-quality-review.md:
python3 scripts/validate_command.py /path/to/command.md (must achieve 100%)Option B: Use reviewer subagent
Task(subagent_type="artifact-quality-reviewer", prompt="Review command at /path/to/command.md")
The subagent runs automated checks first, then conducts manual review following the same framework.
Quality review categories:
Target: All categories score ā„4/5 for approval.
See references/command-quality-review.md for complete manual review workflow, scoring rubrics, and quality standards.
IMPORTANT: Commands may have side effects. Test with extreme caution.
Safety assessment:
allowed-tools frontmatterSafe testing patterns:
Read, Grep, Glob only ā Safe to testEdit, Write ā Test in isolated directoryBash(git:*) ā Test in isolated git repoTesting workflow (when safe):
When NOT to functionally test:
ā Structure validation only in these cases
After passing quality review and testing, the command is ready for use.
Deployment locations:
.claude/commands/ - Committed to git, shared with team~/.claude/commands/ - Available across all projectsIteration workflow:
--minimal mode)! prefix)allowed-tools to limit command capabilities for safetySpecify exactly which tools the command can use. Be restrictive for safety.
Patterns:
Bash(git add:*) - Specific git command with any argumentsBash(git add:*), Bash(git commit:*) - Multiple specific commandsRead, Grep, Glob - Read-only file operationsRead, Edit - Can read and edit, but not create filesRead, Write, Edit, TodoWrite - Full file manipulation plus task trackingTask - Can launch subagentsImportant: Do NOT use Bash alone - always specify which bash commands are allowed.
Show users what arguments are expected. This appears during autocomplete.
Patterns:
[file] - Single optional argument<pr-number> - Single required argument (use angle brackets)[message] - Optional text argumentadd [tag] | remove [tag] | list - Multiple command modes<from> <to> - Multiple required argumentsKeep it under 10 words. This appears in /help output.
Good examples:
Use specific models for specific tasks:
sonnet - Default, best for most taskshaiku - Fast, for simple/cheap tasksSet to true to prevent the SlashCommand tool from invoking this command automatically:
disable-model-invocation: true - User must invoke manuallyā Too vague - "Do the thing with $ARGUMENTS" ā Explicit - Use specific skills/subagents with numbered steps
ā No preflight checks - Commands fail at runtime ā Validated - Check git repo, file existence, dependencies first
ā Overly permissive - allowed-tools: Bash
ā
Restrictive - Bash(git add:*), Bash(git commit:*), Read, Edit
references/preflight-patterns.md - Validation checks (file existence, git, dependencies)references/context-patterns.md - Information gathering (git, project, code)references/tool-patterns.md - Skill/Task/TodoWrite/file operationsreferences/examples.md - 8 production-ready examplesreferences/advanced-patterns.md - Complex scenarios (args, recovery, performance)references/command-quality-review.md - Comprehensive quality review frameworkEffective slash commands are:
Remember: If it's getting complex, it should probably be a skill instead!