slash-commands
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSlash Commands Reference
斜杠命令参考
Create and use user-triggered prompts with syntax.
/command-name使用语法创建和使用用户触发的提示词。
/命令名称When to Use
适用场景
- "How do I create a slash command?"
- "What slash commands are available?"
- "Add bash to my command"
- "Use file references in commands"
- "Slash commands vs skills"
- "如何创建斜杠命令?"
- "有哪些可用的斜杠命令?"
- "为我的命令添加Bash功能"
- "在命令中使用文件引用"
- "斜杠命令 vs 技能"
Built-in Commands
内置命令
| Command | Purpose |
|---|---|
| Clear conversation history |
| Compact conversation with focus |
| Open settings interface |
| Show token usage |
| Manage sub-agents |
| Manage MCP servers |
| Edit CLAUDE.md files |
| Select AI model |
| Request code review |
| Resume session |
| Get usage help |
| 命令 | 用途 |
|---|---|
| 清除对话历史 |
| 精简对话内容,聚焦重点 |
| 打开设置界面 |
| 显示Token使用情况 |
| 管理子Agent |
| 管理MCP服务器 |
| 编辑CLAUDE.md文件 |
| 选择AI模型 |
| 请求代码评审 |
| 恢复会话 |
| 获取使用帮助 |
Creating Commands
创建命令
Project Commands
项目级命令
bash
mkdir -p .claude/commands
cat > .claude/commands/optimize.md << 'EOF'
---
description: Analyze code for performance issues
---
Review this code for:
- Performance bottlenecks
- Memory leaks
- Caching opportunities
EOFbash
mkdir -p .claude/commands
cat > .claude/commands/optimize.md << 'EOF'
---
description: Analyze code for performance issues
---
Review this code for:
- Performance bottlenecks
- Memory leaks
- Caching opportunities
EOFPersonal Commands
个人级命令
bash
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/review.md << 'EOF'
---
description: Security-focused code review
---
Check for vulnerabilities:
- Input validation
- SQL injection
- XSS risks
EOFbash
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/review.md << 'EOF'
---
description: Security-focused code review
---
Check for vulnerabilities:
- Input validation
- SQL injection
- XSS risks
EOFCommand File Format
命令文件格式
yaml
---
description: Brief description for /help
allowed-tools: [Bash, Read, Write] # Optional
argument-hint: "[file] [type]" # Optional
---
Your markdown instructions here.
Use $1, $2 for arguments or $ARGUMENTS for all.yaml
---
description: Brief description for /help
allowed-tools: [Bash, Read, Write] # Optional
argument-hint: "[file] [type]" # Optional
---
Your markdown instructions here.
Use $1, $2 for arguments or $ARGUMENTS for all.Bash Execution
Bash执行
Run bash before loading prompt with prefix:
!yaml
---
allowed-tools: Bash(git:*), Bash(grep:*)
description: Git commit helper
---
Current status: !`git status`
Staged changes: !`git diff --staged`
Recent commits: !`git log --oneline -5`
Based on these changes, suggest a commit message.Rules:
- Must declare in frontmatter
allowed-tools: Bash(...) - Use backticks:
!`command` - Output is included in Claude's context
使用前缀在加载提示词前运行Bash命令:
!yaml
---
allowed-tools: Bash(git:*), Bash(grep:*)
description: Git commit helper
---
Current status: !`git status`
Staged changes: !`git diff --staged`
Recent commits: !`git log --oneline -5`
Based on these changes, suggest a commit message.规则:
- 必须在前置元数据中声明
allowed-tools: Bash(...) - 使用反引号:
!`command` - 输出会被包含在Claude的上下文当中
File References
文件引用
Include files with prefix:
@markdown
Review against @.claude/STYLE_GUIDE.md
Compare:
- @src/old.js
- @src/new.js
Refactor files matching @src/**/*.util.ts使用前缀引用文件:
@markdown
Review against @.claude/STYLE_GUIDE.md
Compare:
- @src/old.js
- @src/new.js
Refactor files matching @src/**/*.util.tsArguments
参数使用
yaml
---
argument-hint: "[pr-number] [priority]"
---
Review PR #$1 with priority: $2yaml
---
argument-hint: "[pr-number] [priority]"
---
Review PR #$1 with priority: $2Or use all arguments:
Or use all arguments:
Fix issue #$ARGUMENTS
**Usage:**
```bash
/review-pr 456 highFix issue #$ARGUMENTS
**使用示例:**
```bash
/review-pr 456 high$1 = "456", $2 = "high"
$1 = "456", $2 = "high"
undefinedundefinedNamespacing
命名空间
Organize with subdirectories:
.claude/commands/
├── frontend/
│ └── component.md → /component (project:frontend)
└── backend/
└── endpoint.md → /endpoint (project:backend)使用子目录组织命令:
.claude/commands/
├── frontend/
│ └── component.md → /component (project:frontend)
└── backend/
└── endpoint.md → /endpoint (project:backend)MCP Slash Commands
MCP斜杠命令
MCP servers expose prompts as commands:
bash
/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" highMCP服务器将提示词暴露为命令:
bash
/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" highSlash Commands vs Skills
斜杠命令 vs 技能
| Aspect | Slash Commands | Skills |
|---|---|---|
| Invocation | Explicit: | Auto-discovered |
| Files | Single .md file | Directory with SKILL.md |
| Use Case | Quick prompts | Complex workflows |
Use slash commands for: Frequently typed prompts, simple templates
Use skills for: Complex workflows, multiple files, auto-discovery
| 维度 | 斜杠命令 | 技能 |
|---|---|---|
| 调用方式 | 显式: | 自动发现 |
| 文件结构 | 单个.md文件 | 包含SKILL.md的目录 |
| 适用场景 | 快速提示词 | 复杂工作流 |
使用斜杠命令的场景: 频繁输入的提示词、简单模板
使用技能的场景: 复杂工作流、多文件、自动发现
Example: Complete Git Commit Command
示例:完整的Git提交命令
yaml
---
description: Generate semantic commit message
allowed-tools: Bash(git:*), Read
argument-hint: "[type]"
---yaml
---
description: Generate semantic commit message
allowed-tools: Bash(git:*), Read
argument-hint: "[type]"
---Semantic Commit Generator
Semantic Commit Generator
Staged files: !
git diff --name-only --cachedDiff preview:
!
git diff --cached | head -100Generate a conventional commit message.
Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)
Format:
<type>(<scope>): <subject>
**Usage:** `/commit feat`Staged files: !
git diff --name-only --cachedDiff preview:
!
git diff --cached | head -100Generate a conventional commit message.
Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)
Format:
<type>(<scope>): <subject>
**使用示例:** `/commit feat`