Claude Code Custom Slash Commands
Skills are Claude Code's extension mechanism, using custom slash commands (such as /deploy、/explain-code) to enhance Claude's capabilities.
Every custom command is essentially a standalone Skill file that can encapsulate complex workflows, project conventions, and common operations for quick invocation in any session.
Custom commands have been integrated into the Skills system — located in .claude/commands/deploy.md command files and located in .claude/skills/deploy/SKILL.md skill files both create /deploy commands and work in the same way.
Essentially,.claude/commands/ is shorthand for Skills; the two directory structures are completely equivalent.
Why use custom slash commands
The core value of custom slash commands lies inStandardization + reuse:
- Solidify workflows: encapsulate common multi-step operations (such as "deploy to production") into a single command
- Ensure team consistency: solidify project conventions (such as a "code review checklist") into commands, ensuring team members follow the same standards
- Reduce cognitive load: no need to memorize complex command combinations; a single sentence triggers the complete workflow
- Reduce Repetitive Typing: high-frequency tasks go from multi-step operations to a single invocation
The experience of Anthropic's internal teams: any task performed more than twice a day should be made into a Skill. Get it right once, and it keeps working.
File structure
Each Skill is a directory containing a required SKILL.md File:
my-skill/
├── SKILL.md # 主指令文件(必需)
├── template.md # Claude 填充的模板
├── examples/
│ └── sample.md # 展示预期格式的示例
└── scripts/
└── validate.sh # Claude 可以执行的脚本
The file format has two parts:
- YAML frontmatter(located between
---delimiters): used to configure metadata - Markdown body: instructions Claude follows when invoked
Create your first custom slash command
1. Create the skills directory
Create the skills directory in an appropriate location. The location determines the commands' scope:
mkdir -p ~/.claude/skills/explain-code
# Or create in the project
mkdir -p .claude/skills/explain-code
2. Write the SKILL.md file
Create in the directory SKILL.md, containing YAML frontmatter and instructions:
Example
name
:
explain-code
description
:
Explain code with visual diagrams and analogies. When explaining how code works,
walking through a codebase, or when the user asks
"how does this work"
use it
When explaining code, always include the following:
1
. Start with an analogy: compare the code to things from everyday life
2
. Draw a diagram: use ASCII art to show flows, structures, or relationships
3
. Walk through the code step by step: explain what happens at each step
4
. Point out a pitfall: what are the common mistakes or misconceptions?
3. Use the custom command
Invoke it directly in Claude Code:
/explain-code src/auth/login.ts
Claude automatically matches skills that fit the description, or you can invoke them explicitly.
Configuration fields explained
| Field | Description |
|---|---|
name |
Display name; becomes the slash command (format: lowercase letters, digits, hyphens, max 64 characters) |
description |
What the skill does and when to use it (recommended; Claude's automatic invocation depends on this field) |
argument-hint |
Hint shown during autocomplete (e.g. [filename] [format]) |
disable-model-invocation |
Set to true , prevents Claude from invoking it automatically; only takes effect when you invoke it explicitly |
user-invocable |
Set to false , hides it from the / menu; only Claude can invoke it |
allowed-tools |
List of tools Claude may use without asking |
context |
Set to fork , runs in a forked subagent |
agent |
Settings context: fork The type of subagent to use when |
paths |
A list of Glob patterns limiting the file scope in which the skill activates |
Invocation control
Control who can invoke the skill via frontmatter:
| Configure | You can invoke | Claude can invoke |
|---|---|---|
| (default) | Is | Is |
disable-model-invocation: true |
Is | No |
user-invocable: false |
No | Is |
Variable substitution
Use variables in skill content, which Claude automatically replaces:
| Variables | Description |
|---|---|
$ARGUMENTS |
All arguments passed at invocation |
$ARGUMENTS[N] |
Access a specific argument by zero-based index |
$N |
$ARGUMENTS[N] shorthand for |
${CLAUDE_SESSION_ID} |
Current session ID |
${CLAUDE_SKILL_DIR} |
The directory where the skill's SKILL.md file resides |
Skill storage locations
Skills can be stored in multiple locations with different scopes:
| Position | Path | Scope |
|---|---|---|
| Enterprise level | Determined by managed settings | All users in the organization |
| Personal | ~/.claude/skills/ |
All projects |
| Projects | .claude/skills/ |
Only the current project |
| Plugin | |
Within enabled plugins |
.claude/commands/files in it are still valid and support the same frontmatter. If a skill and a command share the same name, the skill takes precedence.
Advanced examples
Example 1: Deployment command (manual invocation only)
Example
name
:
deploy
description
:
Deploy the application to production
disable-model-invocation
:
true
Deploy $ARGUMENTS to production:
1
. Run the test suite
2
. Build the application
3
. Push to the deployment target
Example 2: Component migration command with parameters
Example
name
:
migrate-component
description
:
Migrate components from one framework to another
Migrate the $0 component from $1 to $2.
Preserve all existing behavior and tests.
Usage: /migrate-component SearchBar React Vue
Example 3: PR summary command with dynamic context
Example
name
:
pr-summary
description
:
Summarize the changes in a Pull Request
context
:
fork
agent
:
Explore
allowed-tools
:
Bash
(
gh *
)
Pull Request context
- PR diff
:
!gh pr diff
- PR comments
:
!gh pr view --comments
- Changed files
:
!gh pr diff --name-only
Your task
Summarize this Pull Request
...
Built-in slash commands
Claude Code provides several built-in commands out of the box:
| Command | Function |
|---|---|
/batch |
Orchestrate large-scale changes across the codebase |
/claude-api |
Load API reference material |
/debug [description] |
Enable debug logging |
/loop [interval] |
Repeat a prompt at intervals |
/simplify [focus] |
Review code for quality issues |
Best Practices
1. How to write description
description is the basis for Claude's automatic invocation; be sure to write it clearly:
- Specify when to trigger:
当用户要求审查 / 分析 / 检查代码质量时调用 - State prerequisites:
在规格文档确认后使用 - Define boundaries clearly: when it should not be invoked
2. Single responsibility principle
Each skill does one thing, with clear input/output:
/deploy: only handles deployment/test: only runs tests/review: only handles code review
3. Set invocation permissions as needed
- Dangerous operations (deployment, deletion): set
disable-model-invocation: true - Claude-assisted tasks: set
user-invocable: false - General workflows: use the default configuration
4. Use allowed-tools to limit permissions
Set minimal permissions for security-critical operations:
Example
name
:
read-only-analyzer
description
:
Read-only code analysis, for reviewing and understanding code
allowed-tools
:
Read, Grep, Glob, Bash
(
gh *
)
Only allow these tools
Perform read-only code analysis
...
Team sharing strategy
Commit project-level skills to git so the team can share them:
my-project/
├── .claude/
│ ├── skills/
│ │ ├── deploy/
│ │ │ └── SKILL.md
│ │ ├── test/
│ │ │ └── SKILL.md
│ │ └── review/
│ │ └── SKILL.md
│ └── commands/ # 也可以用 commands/ 目录
└── CLAUDE.md
Reference and describe project-specific skills in CLAUDE.md:
## Custom slash command
This project provides the following custom slash commands:
- `/deploy [env]` — 部署到指定环境(dev/staging/prod)
- `/test [module]` — 运行测试套件或指定模块
- `/review` — 执行标准代码审查
详细使用说明请参考 @.claude/skills/README.md
Common questions
Q: What's the difference between the skills and commands directories?
Essentially no difference..claude/commands/ Is .claude/skills/ shorthand form; both work fine. If names collide, the skill takes precedence.
Q: How can I pass multiple arguments when invoking?
Wrap multiple arguments in quotes:/migrate SearchBar "from:React to:Vue", then use in the skill $ARGUMENTS to get the complete string.
Q: Can skills be used in subagents?
Yes. By setting the context: fork and agent field, you can have subagents run skills in an isolated context.
Q: How do I get Claude to remember frequently used skills?
List all available custom commands and their use cases in CLAUDE.md; Claude will automatically match the appropriate skill based on the description.