Command Development for Claude Code
Note: The
.claude/commands/directory is a legacy format. For new skills, use the.claude/skills/<name>/SKILL.mddirectory format. Both are loaded identically — the only difference is file layout. See theskill-developmentskill for the preferred format.
Overview
Slash 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.
Key concepts:
- Markdown file format for commands
- YAML frontmatter for configuration
- Dynamic arguments and file references
- Bash execution for context
- Command organization and namespacing
Command Basics
What is a Slash Command?
A slash command is a Markdown file containing a prompt that Claude executes when invoked. Commands provide:
- Reusability: Define once, use repeatedly
- Consistency: Standardize common workflows
- Sharing: Distribute across team or projects
- Efficiency: Quick access to complex prompts
Critical: Commands are Instructions FOR Claude
Commands are written for agent consumption, not human consumption.
When 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.
Correct approach (instructions for Claude):
Incorrect approach (messages to user):
The 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.
Command Locations
Project commands (shared with team):
- Location:
.claude/commands/ - Scope: Available in specific project
- Label: Shown as "(project)" in
/help - Use for: Team workflows, project-specific tasks
Personal commands (available everywhere):
- Location:
~/.claude/commands/ - Scope: Available in all projects
- Label: Shown as "(user)" in
/help - Use for: Personal workflows, cross-project utilities
Plugin commands (bundled with plugins):
- Location:
plugin-name/commands/ - Scope: Available when plugin installed
- Label: Shown as "(plugin-name)" in
/help - Use for: Plugin-specific functionality
File Format
Basic Structure
Commands are Markdown files with .md extension:
Simple command:
No frontmatter needed for basic commands.
With YAML Frontmatter
Add configuration using YAML frontmatter:
YAML Frontmatter Fields
description
Purpose: Brief description shown in /help
Type: String
Default: First line of command prompt
Best practice: Clear, actionable description (under 60 characters)
allowed-tools
Purpose: Specify which tools command can use Type: String or Array Default: Inherits from conversation
Patterns:
Read, Write, Edit- Specific toolsBash(git:*)- Bash with git commands only*- All tools (rarely needed)
Use when: Command requires specific tool access
model
Purpose: Specify model for command execution Type: String (sonnet, opus, haiku) Default: Inherits from conversation
Use cases:
haiku- Fast, simple commandssonnet- Standard workflowsopus- Complex analysis
argument-hint
Purpose: Document expected arguments for autocomplete Type: String Default: None
Benefits:
- Helps users understand command arguments
- Improves command discovery
- Documents command interface
disable-model-invocation
Purpose: Prevent SlashCommand tool from programmatically calling command Type: Boolean Default: false
Use when: Command should only be manually invoked
Dynamic Arguments
Using $ARGUMENTS
Capture all arguments as single string:
Usage:
Expands to:
Using Positional Arguments
Capture individual arguments with $1, $2, $3, etc.:
Usage:
Expands to:
Combining Arguments
Mix positional and remaining arguments:
Usage:
Expands to:
File References
Using @ Syntax
Include file contents in command:
Usage:
Effect: Claude reads src/api/users.ts before processing command
Multiple File References
Reference multiple files:
Static File References
Reference known files without arguments:
Bash Execution in Commands
Commands 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.
When to use:
- Include dynamic context (git status, environment vars, etc.)
- Gather project/repository state
- Build context-aware workflows
Implementation details:
For 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 issues
Command Organization
Flat Structure
Simple organization for small command sets:
Use when: 5-15 commands, no clear categories
Namespaced Structure
Organize commands in subdirectories:
Benefits:
- Logical grouping by category
- Namespace shown in
/help - Easier to find related commands
Use when: 15+ commands, clear categories
Best Practices
Command Design
- Single responsibility: One command, one task
- Clear descriptions: Self-explanatory in
/help - Explicit dependencies: Use
allowed-toolswhen needed - Document arguments: Always provide
argument-hint - Consistent naming: Use verb-noun pattern (review-pr, fix-issue)
Argument Handling
- Validate arguments: Check for required arguments in prompt
- Provide defaults: Suggest defaults when arguments missing
- Document format: Explain expected argument format
- Handle edge cases: Consider missing or invalid arguments
File References
- Explicit paths: Use clear file paths
- Check existence: Handle missing files gracefully
- Relative paths: Use project-relative paths
- Glob support: Consider using Glob tool for patterns
Bash Commands
- Limit scope: Use
Bash(git:*)notBash(*) - Safe commands: Avoid destructive operations
- Handle errors: Consider command failures
- Keep fast: Long-running commands slow invocation
Documentation
- Add comments: Explain complex logic
- Provide examples: Show usage in comments
- List requirements: Document dependencies
- Version commands: Note breaking changes
Common Patterns
Review Pattern
Testing Pattern
Documentation Pattern
Workflow Pattern
Troubleshooting
Command not appearing:
- Check file is in correct directory
- Verify
.mdextension present - Ensure valid Markdown format
- Restart Claude Code
Arguments not working:
- Verify
$1,$2syntax correct - Check
argument-hintmatches usage - Ensure no extra spaces
Bash execution failing:
- Check
allowed-toolsincludes Bash - Verify command syntax in backticks
- Test command in terminal first
- Check for required permissions
File references not working:
- Verify
@syntax correct - Check file path is valid
- Ensure Read tool allowed
- Use absolute or project-relative paths
Plugin-Specific Features
CLAUDE_PLUGIN_ROOT Variable
Plugin commands have access to ${CLAUDE_PLUGIN_ROOT}, an environment variable that resolves to the plugin's absolute path.
Purpose:
- Reference plugin files portably
- Execute plugin scripts
- Load plugin configuration
- Access plugin templates
Basic usage:
Common patterns:
Why use it:
- Works across all installations
- Portable between systems
- No hardcoded paths needed
- Essential for multi-file plugins
Plugin Command Organization
Plugin commands discovered automatically from commands/ directory:
Namespace benefits:
- Logical command grouping
- Shown in
/helpoutput - Avoid name conflicts
- Organize related commands
Naming conventions:
- Use descriptive action names
- Avoid generic names (test, run)
- Consider plugin-specific prefix
- Use hyphens for multi-word names
Plugin Command Patterns
Configuration-based pattern:
Template-based pattern:
Multi-script pattern:
See references/plugin-features-reference.md for detailed patterns.
Integration with Plugin Components
Commands can integrate with other plugin components for powerful workflows.
Agent Integration
Launch plugin agents for complex tasks:
Key points:
- Agent must exist in
plugin/agents/directory - Claude uses Task tool to launch agent
- Document agent capabilities
- Reference plugin resources agent uses
Skill Integration
Leverage plugin skills for specialized knowledge:
Key points:
- Skill must exist in
plugin/skills/directory - Mention skill name to trigger invocation
- Document skill purpose
- Explain what skill provides
Hook Coordination
Design commands that work with plugin hooks:
- Commands can prepare state for hooks to process
- Hooks execute automatically on tool events
- Commands should document expected hook behavior
- Guide Claude on interpreting hook output
See references/plugin-features-reference.md for examples of commands that coordinate with hooks
Multi-Component Workflows
Combine agents, skills, and scripts:
When to use:
- Complex multi-step workflows
- Leverage multiple plugin capabilities
- Require specialized analysis
- Need structured outputs
Validation Patterns
Commands should validate inputs and resources before processing.
Argument Validation
File Existence Checks
Plugin Resource Validation
Error Handling
Best practices:
- Validate early in command
- Provide helpful error messages
- Suggest corrective actions
- Handle edge cases gracefully
For detailed frontmatter field specifications, see references/frontmatter-reference.md.
For plugin-specific features and patterns, see references/plugin-features-reference.md.
For command pattern examples, see examples/ directory.


