claude-commands
Guide for creating custom slash commands for Claude Code. Use when adding new commands, defining command arguments, or implementing command workflows.
What this skill does
# Claude Code Commands
Guide for creating custom slash commands that extend Claude Code functionality.
## When to Use This Skill
Activate this skill when:
- Creating new custom slash commands
- Understanding command structure and syntax
- Organizing commands for plugins
- Implementing command workflows
- Debugging command execution
## What Are Commands?
Commands are custom slash commands (like `/commit`, `/review`) that users can invoke to trigger specific workflows or expand prompts. They are markdown files that can contain:
- Static prompt text
- Dynamic content based on arguments
- Multi-step workflows
- Integration with tools and scripts
## Command File Structure
### Location
Commands are defined in markdown files located in:
- Plugin: `<plugin-root>/commands/`
- User-level: `.claude/commands/`
### File Naming
- Use kebab-case: `my-command.md`
- File name becomes the command name: `my-command.md` → `/my-command`
- Avoid conflicts with built-in commands
## Basic Command Format
### Simple Static Command
```markdown
# /my-command
This is the prompt that will be expanded when the user types /my-command.
The entire content of this file will replace the slash command in the conversation.
```
### Command with Description
```markdown
<!--
description: Brief description of what this command does
-->
# /my-command
Command prompt goes here...
```
## Command Arguments
Commands can accept arguments that users provide when invoking the command.
### Single Argument
```markdown
# /greet
Hello, {{arg}}! Welcome to the project.
```
Usage: `/greet Alice` → "Hello, Alice! Welcome to the project."
### Multiple Arguments
```markdown
# /create-file
Create a new file at {{arg1}} with the following content:
{{arg2}}
```
Usage: `/create-file src/main.rs "fn main() {}"`
### Named Arguments
```markdown
# /deploy
Deploy {{environment}} environment to {{region}}.
Configuration:
- Environment: {{environment}}
- Region: {{region}}
- Branch: {{branch}}
```
Usage: `/deploy --environment=production --region=us-east-1 --branch=main`
## Advanced Features
### Conditional Content
```markdown
# /analyze
Analyze the {{language}} codebase.
{{#if verbose}}
Provide detailed analysis including:
- Code complexity metrics
- Dependency analysis
- Security vulnerabilities
{{else}}
Provide a summary analysis.
{{/if}}
```
### Including Files
Reference other files or command outputs:
```markdown
# /context
Here is the current project structure:
{{file:PROJECT_STRUCTURE.md}}
And the current git status:
{{shell:git status}}
```
### Multi-Step Workflows
```markdown
# /full-review
I'll perform a comprehensive code review:
1. First, let me check the git diff:
{{shell:git diff}}
2. Now analyzing code quality...
3. Checking for security issues...
4. Final recommendations:
```
## Best Practices
### Clear Command Names
- Use descriptive, action-oriented names
- `/analyze-security` not `/sec`
- `/create-component` not `/comp`
### Provide Context
Always include what the command will do:
```markdown
# /commit
I'll analyze the current git changes and create a conventional commit message.
Current changes:
{{shell:git diff --staged}}
Based on these changes, here's my suggested commit message:
```
### Handle Edge Cases
```markdown
# /deploy
{{#if staging}}
Deploying to staging environment (safe for testing)
{{else if production}}
⚠️ WARNING: Deploying to PRODUCTION
Are you sure you want to continue? This will affect live users.
{{else}}
Error: Unknown environment. Please specify --staging or --production
{{/if}}
```
### Document Arguments
```markdown
<!--
description: Deploy application to specified environment
usage: /deploy [--environment=<env>] [--region=<region>]
arguments:
- environment: Target environment (staging, production)
- region: AWS region (us-east-1, eu-west-1, etc.)
-->
# /deploy
```
## Command Organization
### Plugin Commands
In `plugin.json`:
```json
{
"commands": [
"./commands/deploy.md",
"./commands/analyze.md",
"./commands/review.md"
]
}
```
### Directory-Based Commands
```json
{
"commands": ["./commands"]
}
```
This loads all `.md` files in the `commands/` directory.
### Namespaced Commands
Organize related commands in subdirectories:
```
commands/
├── git/
│ ├── commit.md
│ ├── review.md
│ └── cleanup.md
├── deploy/
│ ├── staging.md
│ └── production.md
```
## Common Command Patterns
### Git Commit Message Generator
```markdown
# /gcm
I'll analyze the staged changes and generate a conventional commit message.
{{shell:git diff --staged}}
Based on these changes, here's my commit message:
```
### Code Review Command
```markdown
# /review-pr
I'll review the pull request changes.
PR Number: {{pr_number}}
{{shell:gh pr diff {{pr_number}}}}
Review checklist:
- [ ] Code quality and style
- [ ] Security considerations
- [ ] Test coverage
- [ ] Documentation updates
```
### Project Scaffolding
```markdown
# /new-component
Creating a new {{component_type}} component named {{name}}.
I'll create:
1. Component file at src/components/{{name}}.tsx
2. Test file at src/components/{{name}}.test.tsx
3. Storybook file at src/components/{{name}}.stories.tsx
```
## Testing Commands
### Manual Testing
1. Install the plugin locally
2. Reload Claude Code
3. Type your command in the chat
4. Verify the expansion is correct
### Debugging
If a command doesn't work:
1. Check file location matches plugin.json
2. Verify markdown syntax
3. Test argument substitution
4. Check for conflicts with existing commands
## Command Templates
### Analysis Command Template
```markdown
<!--
description: Analyze {{target}} for {{criteria}}
-->
# /analyze-{{target}}
I'll analyze the {{target}} codebase for {{criteria}}.
{{shell:find {{target}} -type f -name "*.{{extension}}"}}
Analysis results:
```
### Workflow Command Template
```markdown
<!--
description: Execute {{workflow}} workflow
-->
# /{{workflow}}
Starting {{workflow}} workflow...
Step 1: {{step1_description}}
{{step1_action}}
Step 2: {{step2_description}}
{{step2_action}}
Workflow complete!
```
## Integration with Skills
Commands can reference skills:
```markdown
# /elixir-review
I'll review this Elixir code using my Phoenix and OTP knowledge.
Please provide the code to review, and I'll check for:
- Phoenix best practices
- OTP design patterns
- Elixir anti-patterns
- Performance considerations
```
## Security Considerations
### Avoid Sensitive Data
Never hardcode:
- API keys
- Passwords
- Tokens
- Private URLs
### Validate Input
```markdown
# /deploy
{{#unless environment}}
Error: --environment is required
{{/unless}}
{{#if (validate_environment environment)}}
Proceeding with deployment...
{{else}}
Error: Invalid environment. Must be staging or production.
{{/if}}
```
### Safe Shell Commands
Be cautious with shell command execution:
```markdown
# /safe-deploy
<!-- Only allow whitelisted commands -->
{{shell:./scripts/deploy.sh {{environment}}}}
```
## References
For more information about Claude Code commands:
- Claude Code Documentation: https://code.claude.com/docs/en/commands
- Example Commands: https://github.com/anthropics/claude-code/tree/main/examples/commands
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.