$npx -y skills add anthropics/claude-code --skill command-developmentThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in c
| 1 | # Command Development for Claude Code |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | **Key concepts:** |
| 8 | - Markdown file format for commands |
| 9 | - YAML frontmatter for configuration |
| 10 | - Dynamic arguments and file references |
| 11 | - Bash execution for context |
| 12 | - Command organization and namespacing |
| 13 | |
| 14 | ## Command Basics |
| 15 | |
| 16 | ### What is a Slash Command? |
| 17 | |
| 18 | A slash command is a Markdown file containing a prompt that Claude executes when invoked. Commands provide: |
| 19 | - **Reusability**: Define once, use repeatedly |
| 20 | - **Consistency**: Standardize common workflows |
| 21 | - **Sharing**: Distribute across team or projects |
| 22 | - **Efficiency**: Quick access to complex prompts |
| 23 | |
| 24 | ### Critical: Commands are Instructions FOR Claude |
| 25 | |
| 26 | **Commands are written for agent consumption, not human consumption.** |
| 27 | |
| 28 | 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. |
| 29 | |
| 30 | **Correct approach (instructions for Claude):** |
| 31 | ```markdown |
| 32 | Review this code for security vulnerabilities including: |
| 33 | - SQL injection |
| 34 | - XSS attacks |
| 35 | - Authentication issues |
| 36 | |
| 37 | Provide specific line numbers and severity ratings. |
| 38 | ``` |
| 39 | |
| 40 | **Incorrect approach (messages to user):** |
| 41 | ```markdown |
| 42 | This command will review your code for security issues. |
| 43 | You'll receive a report with vulnerability details. |
| 44 | ``` |
| 45 | |
| 46 | 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. |
| 47 | |
| 48 | ### Command Locations |
| 49 | |
| 50 | **Project commands** (shared with team): |
| 51 | - Location: `.claude/commands/` |
| 52 | - Scope: Available in specific project |
| 53 | - Label: Shown as "(project)" in `/help` |
| 54 | - Use for: Team workflows, project-specific tasks |
| 55 | |
| 56 | **Personal commands** (available everywhere): |
| 57 | - Location: `~/.claude/commands/` |
| 58 | - Scope: Available in all projects |
| 59 | - Label: Shown as "(user)" in `/help` |
| 60 | - Use for: Personal workflows, cross-project utilities |
| 61 | |
| 62 | **Plugin commands** (bundled with plugins): |
| 63 | - Location: `plugin-name/commands/` |
| 64 | - Scope: Available when plugin installed |
| 65 | - Label: Shown as "(plugin-name)" in `/help` |
| 66 | - Use for: Plugin-specific functionality |
| 67 | |
| 68 | ## File Format |
| 69 | |
| 70 | ### Basic Structure |
| 71 | |
| 72 | Commands are Markdown files with `.md` extension: |
| 73 | |
| 74 | ``` |
| 75 | .claude/commands/ |
| 76 | ├── review.md # /review command |
| 77 | ├── test.md # /test command |
| 78 | └── deploy.md # /deploy command |
| 79 | ``` |
| 80 | |
| 81 | **Simple command:** |
| 82 | ```markdown |
| 83 | Review this code for security vulnerabilities including: |
| 84 | - SQL injection |
| 85 | - XSS attacks |
| 86 | - Authentication bypass |
| 87 | - Insecure data handling |
| 88 | ``` |
| 89 | |
| 90 | No frontmatter needed for basic commands. |
| 91 | |
| 92 | ### With YAML Frontmatter |
| 93 | |
| 94 | Add configuration using YAML frontmatter: |
| 95 | |
| 96 | ```markdown |
| 97 | --- |
| 98 | description: Review code for security issues |
| 99 | allowed-tools: Read, Grep, Bash(git:*) |
| 100 | model: sonnet |
| 101 | --- |
| 102 | |
| 103 | Review this code for security vulnerabilities... |
| 104 | ``` |
| 105 | |
| 106 | ## YAML Frontmatter Fields |
| 107 | |
| 108 | ### description |
| 109 | |
| 110 | **Purpose:** Brief description shown in `/help` |
| 111 | **Type:** String |
| 112 | **Default:** First line of command prompt |
| 113 | |
| 114 | ```yaml |
| 115 | --- |
| 116 | description: Review pull request for code quality |
| 117 | --- |
| 118 | ``` |
| 119 | |
| 120 | **Best practice:** Clear, actionable description (under 60 characters) |
| 121 | |
| 122 | ### allowed-tools |
| 123 | |
| 124 | **Purpose:** Specify which tools command can use |
| 125 | **Type:** String or Array |
| 126 | **Default:** Inherits from conversation |
| 127 | |
| 128 | ```yaml |
| 129 | --- |
| 130 | allowed-tools: Read, Write, Edit, Bash(git:*) |
| 131 | --- |
| 132 | ``` |
| 133 | |
| 134 | **Patterns:** |
| 135 | - `Read, Write, Edit` - Specific tools |
| 136 | - `Bash(git:*)` - Bash with git commands only |
| 137 | - `*` - All tools (rarely needed) |
| 138 | |
| 139 | **Use when:** Command requires specific tool access |
| 140 | |
| 141 | ### model |
| 142 | |
| 143 | **Purpose:** Specify model for command execution |
| 144 | **Type:** String (sonnet, opus, haiku) |
| 145 | **Default:** Inherits from conversation |
| 146 | |
| 147 | ```yaml |
| 148 | --- |
| 149 | model: haiku |
| 150 | --- |
| 151 | ``` |
| 152 | |
| 153 | **Use cases:** |
| 154 | - `haiku` - Fast, simple commands |
| 155 | - `sonnet` - Standard workflows |
| 156 | - `opus` - Complex analysis |
| 157 | |
| 158 | ### argument-hint |
| 159 | |
| 160 | **Purpose:** Document expected arguments for autocomplete |
| 161 | **Type:** String |
| 162 | **Default:** None |
| 163 | |
| 164 | ```yaml |
| 165 | --- |
| 166 | argument-hint: [pr-number] [priority] [assignee] |
| 167 | --- |
| 168 | ``` |
| 169 | |
| 170 | **Benefits:** |
| 171 | - Helps users understand command arguments |
| 172 | - Improves command discovery |
| 173 | - Documents command interface |
| 174 | |
| 175 | ### disable-model-invocation |
| 176 | |
| 177 | **Purpose:** Prevent SlashCommand tool from programmatically calling command |
| 178 | **Type:** Boolean |
| 179 | **Default:** false |
| 180 | |
| 181 | `` |