slash-commands

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Slash Commands Reference

斜杠命令参考

Create and use user-triggered prompts with
/command-name
syntax.
使用
/命令名称
语法创建和使用用户触发的提示词。

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

内置命令

CommandPurpose
/clear
Clear conversation history
/compact
Compact conversation with focus
/config
Open settings interface
/cost
Show token usage
/agents
Manage sub-agents
/mcp
Manage MCP servers
/memory
Edit CLAUDE.md files
/model
Select AI model
/review
Request code review
/resume
Resume session
/help
Get usage help
命令用途
/clear
清除对话历史
/compact
精简对话内容,聚焦重点
/config
打开设置界面
/cost
显示Token使用情况
/agents
管理子Agent
/mcp
管理MCP服务器
/memory
编辑CLAUDE.md文件
/model
选择AI模型
/review
请求代码评审
/resume
恢复会话
/help
获取使用帮助

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
EOF
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
EOF

Personal 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
EOF
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
EOF

Command 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
    allowed-tools: Bash(...)
    in frontmatter
  • 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.ts

Arguments

参数使用

yaml
---
argument-hint: "[pr-number] [priority]"
---

Review PR #$1 with priority: $2
yaml
---
argument-hint: "[pr-number] [priority]"
---

Review PR #$1 with priority: $2

Or use all arguments:

Or use all arguments:

Fix issue #$ARGUMENTS

**Usage:**
```bash
/review-pr 456 high
Fix issue #$ARGUMENTS

**使用示例:**
```bash
/review-pr 456 high

$1 = "456", $2 = "high"

$1 = "456", $2 = "high"

undefined
undefined

Namespacing

命名空间

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" high
MCP服务器将提示词暴露为命令:
bash
/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" high

Slash Commands vs Skills

斜杠命令 vs 技能

AspectSlash CommandsSkills
InvocationExplicit:
/command
Auto-discovered
FilesSingle .md fileDirectory with SKILL.md
Use CaseQuick promptsComplex workflows
Use slash commands for: Frequently typed prompts, simple templates Use skills for: Complex workflows, multiple files, auto-discovery
维度斜杠命令技能
调用方式显式:
/command
自动发现
文件结构单个.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 --cached
Diff preview: !
git diff --cached | head -100
Generate 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 --cached
Diff preview: !
git diff --cached | head -100
Generate a conventional commit message. Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)
Format:
<type>(<scope>): <subject>

**使用示例:** `/commit feat`