slash-commands.md +0 −546 deleted
File Deleted View Diff
1# Slash commands
2
3> Control Claude's behavior during an interactive session with slash commands.
4
5## Built-in slash commands
6
7| Command | Purpose |
8| :------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9| `/add-dir` | Add additional working directories |
10| `/agents` | Manage custom AI subagents for specialized tasks |
11| `/bashes` | List and manage background tasks |
12| `/bug` | Report bugs (sends conversation to Anthropic) |
13| `/clear` | Clear conversation history |
14| `/compact [instructions]` | Compact conversation with optional focus instructions |
15| `/config` | Open the Settings interface (Config tab). Type to search and filter settings |
16| `/context` | Visualize current context usage as a colored grid |
17| `/cost` | Show token usage statistics. See [cost tracking guide](/en/costs#using-the-cost-command) for subscription-specific details. |
18| `/doctor` | Run diagnostics to check installation health, detect configuration issues (invalid settings, MCP errors, keybinding problems), and identify context usage warnings (large CLAUDE.md files, high MCP token usage) |
19| `/exit` | Exit the REPL |
20| `/export [filename]` | Export the current conversation to a file or clipboard |
21| `/help` | Get usage help |
22| `/hooks` | Manage hook configurations for tool events |
23| `/ide` | Manage IDE integrations and show status |
24| `/init` | Initialize project with `CLAUDE.md` guide |
25| `/install-github-app` | Set up Claude GitHub Actions for a repository |
26| `/login` | Switch Anthropic accounts |
27| `/logout` | Sign out from your Anthropic account |
28| `/mcp` | Manage MCP server connections and OAuth authentication |
29| `/memory` | Edit `CLAUDE.md` memory files |
30| `/model` | Select or change the AI model |
31| `/output-style [style]` | Set the output style directly or from a selection menu |
32| `/permissions` | View or update [permissions](/en/iam#configuring-permissions) |
33| `/plan` | Enter plan mode directly from the prompt |
34| `/plugin` | Manage Claude Code plugins |
35| `/pr-comments` | View pull request comments |
36| `/privacy-settings` | View and update your privacy settings |
37| `/release-notes` | View release notes |
38| `/rename <name>` | Rename the current session for easier identification |
39| `/remote-env` | Configure remote session environment (claude.ai subscribers) |
40| `/resume [session]` | Resume a conversation by ID or name, or open the session picker |
41| `/review` | Request code review |
42| `/rewind` | Rewind the conversation and/or code |
43| `/sandbox` | Enable sandboxed bash tool with filesystem and network isolation for safer, more autonomous execution |
44| `/security-review` | Complete a security review of pending changes on the current branch |
45| `/stats` | Visualize daily usage, session history, streaks, and model preferences. Press `r` to cycle date ranges (Last 7 days, Last 30 days, All time) |
46| `/status` | Open the Settings interface (Status tab) showing version, model, account, and connectivity |
47| `/statusline` | Set up Claude Code's status line UI |
48| `/teleport` | Resume a remote session from claude.ai by session ID, or open a picker (claude.ai subscribers) |
49| `/terminal-setup` | Install Shift+Enter key binding for newlines (VS Code, Alacritty, Zed, Warp) |
50| `/theme` | Change the color theme |
51| `/todos` | List current TODO items |
52| `/usage` | For subscription plans only: show plan usage limits and rate limit status |
53| `/vim` | Enter vim mode for alternating insert and command modes |
54
55## Custom slash commands
56
57Custom slash commands allow you to define frequently used prompts as Markdown files that Claude Code can execute. Commands are organized by scope (project-specific or personal) and support namespacing through directory structures.
58
59<Tip>
60 Slash command autocomplete works anywhere in your input, not just at the beginning. Type `/` at any position to see available commands.
61</Tip>
62
63### Syntax
64
65```
66/<command-name> [arguments]
67```
68
69#### Parameters
70
71| Parameter | Description |
72| :--------------- | :---------------------------------------------------------------- |
73| `<command-name>` | Name derived from the Markdown filename (without `.md` extension) |
74| `[arguments]` | Optional arguments passed to the command |
75
76### Command types
77
78#### Project commands
79
80Commands stored in your repository and shared with your team. When listed in `/help`, these commands show "(project)" after their description.
81
82**Location**: `.claude/commands/`
83
84The following example creates the `/optimize` command:
85
86```bash theme={null}
87# Create a project command
88mkdir -p .claude/commands
89echo "Analyze this code for performance issues and suggest optimizations:" > .claude/commands/optimize.md
90```
91
92#### Personal commands
93
94Commands available across all your projects. When listed in `/help`, these commands show "(user)" after their description.
95
96**Location**: `~/.claude/commands/`
97
98The following example creates the `/security-review` command:
99
100```bash theme={null}
101# Create a personal command
102mkdir -p ~/.claude/commands
103echo "Review this code for security vulnerabilities:" > ~/.claude/commands/security-review.md
104```
105
106### Features
107
108#### Namespacing
109
110Use subdirectories to group related commands. Subdirectories appear in the command description but don't affect the command name.
111
112For example:
113
114* `.claude/commands/frontend/component.md` creates `/component` with description "(project:frontend)"
115* `~/.claude/commands/component.md` creates `/component` with description "(user)"
116
117If a project command and user command share the same name, the project command takes precedence and the user command is silently ignored. For example, if both `.claude/commands/deploy.md` and `~/.claude/commands/deploy.md` exist, `/deploy` runs the project version.
118
119Commands in different subdirectories can share names since the subdirectory appears in the description to distinguish them. For example, `.claude/commands/frontend/test.md` and `.claude/commands/backend/test.md` both create `/test`, but show as "(project:frontend)" and "(project:backend)" respectively.
120
121#### Arguments
122
123Pass dynamic values to commands using argument placeholders:
124
125##### All arguments with `$ARGUMENTS`
126
127The `$ARGUMENTS` placeholder captures all arguments passed to the command:
128
129```bash theme={null}
130# Command definition
131echo 'Fix issue #$ARGUMENTS following our coding standards' > .claude/commands/fix-issue.md
132
133# Usage
134> /fix-issue 123 high-priority
135# $ARGUMENTS becomes: "123 high-priority"
136```
137
138##### Individual arguments with `$1`, `$2`, etc.
139
140Access specific arguments individually using positional parameters (similar to shell scripts):
141
142```bash theme={null}
143# Command definition
144echo 'Review PR #$1 with priority $2 and assign to $3' > .claude/commands/review-pr.md
145
146# Usage
147> /review-pr 456 high alice
148# $1 becomes "456", $2 becomes "high", $3 becomes "alice"
149```
150
151Use positional arguments when you need to:
152
153* Access arguments individually in different parts of your command
154* Provide defaults for missing arguments
155* Build more structured commands with specific parameter roles
156
157#### Bash command execution
158
159Execute bash commands before the slash command runs using the `!` prefix. The output is included in the command context. You *must* include `allowed-tools` with the `Bash` tool, but you can choose the specific bash commands to allow.
160
161For example:
162
163```markdown theme={null}
164allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
165description: Create a git commit
166
167## Context
168
169- Current git status: !`git status`
170- Current git diff (staged and unstaged changes): !`git diff HEAD`
171- Current branch: !`git branch --show-current`
172- Recent commits: !`git log --oneline -10`
173
174## Your task
175
176Based on the above changes, create a single git commit.
177```
178
179#### File references
180
181Include file contents in commands using the `@` prefix to [reference files](/en/common-workflows#reference-files-and-directories).
182
183For example:
184
185```markdown theme={null}
186# Reference a specific file
187
188Review the implementation in @src/utils/helpers.js
189
190# Reference multiple files
191
192Compare @src/old-version.js with @src/new-version.js
193```
194
195#### Thinking mode
196
197Slash commands can trigger extended thinking by including [extended thinking keywords](/en/common-workflows#use-extended-thinking).
198
199### Frontmatter
200
201Command files support frontmatter, useful for specifying metadata about the command:
202
203| Frontmatter | Purpose | Default |
204| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------- |
205| `allowed-tools` | List of tools the command can use | Inherits from the conversation |
206| `argument-hint` | The arguments expected for the slash command. Example: `argument-hint: add [tagId] \| remove [tagId] \| list`. This hint is shown to the user when auto-completing the slash command. | None |
207| `context` | Set to `fork` to run the command in a forked sub-agent context with its own conversation history. | Inline (no fork) |
208| `agent` | Specify which [agent type](/en/sub-agents#built-in-subagents) to use when `context: fork` is set. Only applicable when combined with `context: fork`. | `general-purpose` |
209| `description` | Brief description of the command | Uses the first line from the prompt |
210| `model` | Specific model string (see [Models overview](https://docs.claude.com/en/docs/about-claude/models/overview)) | Inherits from the conversation |
211| `disable-model-invocation` | Whether to prevent the `Skill` tool from calling this command | false |
212| `hooks` | Define hooks scoped to this command's execution. See [Define hooks for commands](#define-hooks-for-commands). | None |
213
214For example:
215
216```markdown theme={null}
217allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
218argument-hint: [message]
219description: Create a git commit
220model: claude-3-5-haiku-20241022
221
222Create a git commit with message: $ARGUMENTS
223```
224
225Example using positional arguments:
226
227```markdown theme={null}
228argument-hint: [pr-number] [priority] [assignee]
229description: Review pull request
230
231Review PR #$1 with priority $2 and assign to $3.
232Focus on security, performance, and code style.
233```
234
235#### Define hooks for commands
236
237Slash commands can define hooks that run during the command's execution. Use the `hooks` field to specify `PreToolUse`, `PostToolUse`, or `Stop` handlers:
238
239```markdown theme={null}
240description: Deploy to staging with validation
241hooks:
242 PreToolUse:
243 - matcher: "Bash"
244 hooks:
245 - type: command
246 command: "./scripts/validate-deploy.sh"
247 once: true
248
249Deploy the current branch to staging environment.
250```
251
252The `once: true` option runs the hook only once per session. After the first successful execution, the hook is removed.
253
254Hooks defined in a command are scoped to that command's execution and are automatically cleaned up when the command finishes.
255
256See [Hooks](/en/hooks) for the complete hook configuration format.
257
258## Plugin commands
259
260[Plugins](/en/plugins) can provide custom slash commands that integrate seamlessly with Claude Code. Plugin commands work exactly like user-defined commands but are distributed through [plugin marketplaces](/en/plugin-marketplaces).
261
262### How plugin commands work
263
264Plugin commands are:
265
266* **Namespaced**: Commands can use the format `/plugin-name:command-name` to avoid conflicts (plugin prefix is optional unless there are name collisions)
267* **Automatically available**: Once a plugin is installed and enabled, its commands appear in `/help`
268* **Fully integrated**: Support all command features (arguments, frontmatter, bash execution, file references)
269
270### Plugin command structure
271
272**Location**: `commands/` directory in plugin root
273
274**File format**: Markdown files with frontmatter
275
276**Basic command structure**:
277
278```markdown theme={null}
279description: Brief description of what the command does
280
281# Command Name
282
283Detailed instructions for Claude on how to execute this command.
284Include specific guidance on parameters, expected outcomes, and any special considerations.
285```
286
287**Advanced command features**:
288
289* **Arguments**: Use placeholders like `{arg1}` in command descriptions
290* **Subdirectories**: Organize commands in subdirectories for namespacing
291* **Bash integration**: Commands can execute shell scripts and programs
292* **File references**: Commands can reference and modify project files
293
294### Invocation patterns
295
296```shell Direct command (when no conflicts) theme={null}
297/command-name
298```
299
300```shell Plugin-prefixed (when needed for disambiguation) theme={null}
301/plugin-name:command-name
302```
303
304```shell With arguments (if command supports them) theme={null}
305/command-name arg1 arg2
306```
307
308## MCP slash commands
309
310MCP servers can expose prompts as slash commands that become available in Claude Code. These commands are dynamically discovered from connected MCP servers.
311
312### Command format
313
314MCP commands follow the pattern:
315
316```
317/mcp__<server-name>__<prompt-name> [arguments]
318```
319
320### Features
321
322#### Dynamic discovery
323
324MCP commands are automatically available when:
325
326* An MCP server is connected and active
327* The server exposes prompts through the MCP protocol
328* The prompts are successfully retrieved during connection
329
330#### Arguments
331
332MCP prompts can accept arguments defined by the server:
333
334```
335# Without arguments
336> /mcp__github__list_prs
337
338# With arguments
339> /mcp__github__pr_review 456
340> /mcp__jira__create_issue "Bug title" high
341```
342
343#### Naming conventions
344
345Server and prompt names are normalized:
346
347* Spaces and special characters become underscores
348* Names are lowercase for consistency
349
350### Managing MCP connections
351
352Use the `/mcp` command to:
353
354* View all configured MCP servers
355* Check connection status
356* Authenticate with OAuth-enabled servers
357* Clear authentication tokens
358* View available tools and prompts from each server
359
360### MCP permissions and wildcards
361
362To approve all tools from an MCP server, use either the server name alone or wildcard syntax:
363
364* `mcp__github` (approves all GitHub tools)
365* `mcp__github__*` (wildcard syntax, also approves all GitHub tools)
366
367To approve specific tools, list each one explicitly:
368
369* `mcp__github__get_issue`
370* `mcp__github__list_issues`
371
372See [MCP permission rules](/en/iam#tool-specific-permission-rules) for more details.
373
374## `Skill` tool
375
376<Note>
377 In earlier versions of Claude Code, slash command invocation was provided by a separate `SlashCommand` tool. This has been merged into the `Skill` tool.
378</Note>
379
380The `Skill` tool allows Claude to programmatically invoke both [custom slash commands](/en/slash-commands#custom-slash-commands) and [Agent Skills](/en/skills) during a conversation. This gives Claude the ability to use these capabilities on your behalf when appropriate.
381
382### What the `Skill` tool can invoke
383
384The `Skill` tool provides access to:
385
386| Type | Location | Requirements |
387| :-------------------- | :------------------------------------------- | :--------------------------------------------- |
388| Custom slash commands | `.claude/commands/` or `~/.claude/commands/` | Must have `description` frontmatter |
389| Agent Skills | `.claude/skills/` or `~/.claude/skills/` | Must not have `disable-model-invocation: true` |
390
391Built-in commands like `/compact` and `/init` are *not* available through this tool.
392
393### Encourage Claude to use specific commands
394
395To encourage Claude to use the `Skill` tool, reference the command by name, including the slash, in your prompts or `CLAUDE.md` file:
396
397```
398> Run /write-unit-test when you are about to start writing tests.
399```
400
401This tool puts each available command's metadata into context up to the character budget limit. Use `/context` to monitor token usage.
402
403To see which commands and Skills are available to the `Skill` tool, run `claude --debug` and trigger a query.
404
405### Disable the `Skill` tool
406
407To prevent Claude from programmatically invoking any commands or Skills:
408
409```bash theme={null}
410/permissions
411# Add to deny rules: Skill
412```
413
414This removes the `Skill` tool and all command/Skill descriptions from context.
415
416### Disable specific commands or Skills
417
418To prevent a specific command or Skill from being invoked programmatically via the `Skill` tool, add `disable-model-invocation: true` to its frontmatter. This also removes the item's metadata from context.
419
420<Note>
421 The `user-invocable` field in Skills only controls menu visibility, not `Skill` tool access. Use `disable-model-invocation: true` to block programmatic invocation. See [Control Skill visibility](/en/skills#control-skill-visibility) for details.
422</Note>
423
424### `Skill` permission rules
425
426The permission rules support:
427
428* **Exact match**: `Skill(commit)` (allows only `commit` with no arguments)
429* **Prefix match**: `Skill(review-pr:*)` (allows `review-pr` with any arguments)
430
431### Character budget limit
432
433The `Skill` tool includes a character budget to limit context usage. This prevents token overflow when many commands and Skills are available.
434
435The budget includes each item's name, arguments, and description.
436
437* **Default limit**: 15,000 characters
438* **Custom limit**: Set via `SLASH_COMMAND_TOOL_CHAR_BUDGET` environment variable. The name is retained for backwards compatibility.
439
440When the budget is exceeded, Claude sees only a subset of available items. In `/context`, a warning shows how many are included.
441
442## Skills vs slash commands
443
444**Slash commands** and **Agent Skills** serve different purposes in Claude Code:
445
446### Use slash commands for
447
448**Quick, frequently used prompts**:
449
450* Simple prompt snippets you use often
451* Quick reminders or templates
452* Frequently used instructions that fit in one file
453
454**Examples**:
455
456* `/review` → "Review this code for bugs and suggest improvements"
457* `/explain` → "Explain this code in simple terms"
458* `/optimize` → "Analyze this code for performance issues"
459
460### Use Skills for
461
462**Comprehensive capabilities with structure**:
463
464* Complex workflows with multiple steps
465* Capabilities requiring scripts or utilities
466* Knowledge organized across multiple files
467* Team workflows you want to standardize
468
469**Examples**:
470
471* PDF processing Skill with form-filling scripts and validation
472* Data analysis Skill with reference docs for different data types
473* Documentation Skill with style guides and templates
474
475### Key differences
476
477| Aspect | Slash Commands | Agent Skills |
478| -------------- | -------------------------------- | ----------------------------------- |
479| **Complexity** | Simple prompts | Complex capabilities |
480| **Structure** | Single .md file | Directory with SKILL.md + resources |
481| **Discovery** | Explicit invocation (`/command`) | Automatic (based on context) |
482| **Files** | One file only | Multiple files, scripts, templates |
483| **Scope** | Project or personal | Project or personal |
484| **Sharing** | Via git | Via git |
485
486### Example comparison
487
488**As a slash command**:
489
490```markdown theme={null}
491# .claude/commands/review.md
492Review this code for:
493- Security vulnerabilities
494- Performance issues
495- Code style violations
496```
497
498Usage: `/review` (manual invocation)
499
500**As a Skill**:
501
502```
503.claude/skills/code-review/
504├── SKILL.md (overview and workflows)
505├── SECURITY.md (security checklist)
506├── PERFORMANCE.md (performance patterns)
507├── STYLE.md (style guide reference)
508└── scripts/
509 └── run-linters.sh
510```
511
512Usage: "Can you review this code?" (automatic discovery)
513
514The Skill provides richer context, validation scripts, and organized reference material.
515
516### When to use each
517
518**Use slash commands**:
519
520* You invoke the same prompt repeatedly
521* The prompt fits in a single file
522* You want explicit control over when it runs
523
524**Use Skills**:
525
526* Claude should discover the capability automatically
527* Multiple files or scripts are needed
528* Complex workflows with validation steps
529* Team needs standardized, detailed guidance
530
531Both slash commands and Skills can coexist. Use the approach that fits your needs.
532
533Learn more about [Agent Skills](/en/skills).
534
535## See also
536
537* [Plugins](/en/plugins) - Extend Claude Code with custom commands through plugins
538* [Identity and Access Management](/en/iam) - Complete guide to permissions, including MCP tool permissions
539* [Interactive mode](/en/interactive-mode) - Shortcuts, input modes, and interactive features
540* [CLI reference](/en/cli-reference) - Command-line flags and options
541* [Settings](/en/settings) - Configuration options
542* [Memory management](/en/memory) - Managing Claude's memory across sessions
543
544
545
546> To find navigation and other pages in this documentation, fetch the llms.txt file at: https://code.claude.com/docs/llms.txt