slash-command-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSlash Command Builder - Claude Code Command Expert
斜杠命令构建器 - Claude Code命令专家
Use this skill when creating, improving, or troubleshooting Claude Code slash commands. Provides expert guidance on command structure, syntax, frontmatter configuration, and best practices.
当你需要创建、改进或排查Claude Code斜杠命令时,可使用此技能。它提供关于命令结构、语法、frontmatter配置以及最佳实践的专业指导。
When to Use This Skill
何时使用此技能
Activate this skill when:
- User asks to create a new slash command
- User wants to improve an existing command
- User needs help with command arguments or frontmatter
- User is troubleshooting command invocation issues
- User wants to understand slash command capabilities
- User asks about the difference between commands and skills
在以下场景激活此技能:
- 用户请求创建新的斜杠命令
- 用户想要改进现有命令
- 用户需要命令参数或frontmatter相关帮助
- 用户在排查命令调用问题
- 用户想要了解斜杠命令的功能
- 用户询问命令与技能的区别
Quick Reference
快速参考
Command File Structure
命令文件结构
markdown
---
description: Brief description shown in autocomplete
argument-hint: [arg1] [arg2] <optional-arg>
allowed-tools: Bash(git *), Read, Write
model: claude-3-5-sonnet-20241022
disable-model-invocation: false
---
Your command prompt here with $ARGUMENTS or $1, $2, etc.
Use !`command` for bash execution
Use @file.txt for file referencesmarkdown
---
description: Brief description shown in autocomplete
argument-hint: [arg1] [arg2] <optional-arg>
allowed-tools: Bash(git *), Read, Write
model: claude-3-5-sonnet-20241022
disable-model-invocation: false
---
Your command prompt here with $ARGUMENTS or $1, $2, etc.
Use !`command` for bash execution
Use @file.txt for file referencesFile Locations
文件位置
Project commands (shared with team):
.claude/commands/my-command.mdPersonal commands (individual use):
~/.claude/commands/my-command.mdOrganized commands (namespaced):
.claude/commands/frontend/component.md → /component (project:frontend)项目命令(与团队共享):
.claude/commands/my-command.md个人命令(个人使用):
~/.claude/commands/my-command.md分类命令(命名空间式):
.claude/commands/frontend/component.md → /component (project:frontend)Creating Effective Slash Commands
创建高效的斜杠命令
Step 1: Identify the Use Case
步骤1:确定使用场景
Good candidates for slash commands:
- Frequently repeated prompts
- Simple, single-purpose tasks
- Quick code reviews or analyses
- Common git workflows
- Standard documentation tasks
NOT good for slash commands (use Skills instead):
- Complex multi-step workflows
- Context-aware behavior
- Team standardization needs
- Workflows requiring multiple files
适合作为斜杠命令的场景:
- 频繁重复的提示词
- 简单、单一目标的任务
- 快速代码审查或分析
- 常见Git工作流
- 标准化文档任务
不适合作为斜杠命令的场景(建议使用Skills):
- 复杂的多步骤工作流
- 上下文感知的行为
- 团队标准化需求
- 需要处理多个文件的工作流
Step 2: Choose Command Name
步骤2:选择命令名称
Best practices:
- Use lowercase with hyphens: ,
/review-pr/optimize-code - Make it memorable and intuitive
- Avoid conflicts with built-in commands
- Keep it short (2-3 words max)
Examples:
- ✅ - Clear, concise
/review-pr - ✅ - Action-oriented
/fix-lint - ❌ - Too verbose
/review-pull-request-thoroughly - ❌ - Too cryptic
/rpr
最佳实践:
- 使用小写加连字符:、
/review-pr/optimize-code - 名称要易记且直观
- 避免与内置命令冲突
- 保持简短(最多2-3个词)
示例:
- ✅ - 清晰、简洁
/review-pr - ✅ - 面向动作
/fix-lint - ❌ - 过于冗长
/review-pull-request-thoroughly - ❌ - 过于晦涩
/rpr
Step 3: Design the Prompt
步骤3:设计提示词
Simple command (no arguments):
markdown
---
description: Analyze code for performance bottlenecks
---
Analyze the current file for performance issues:
1. Identify O(n²) or worse algorithms
2. Find unnecessary re-renders or computations
3. Check for memory leaks
4. Suggest optimizations with code examplesCommand with all arguments:
markdown
---
description: Generate component boilerplate
argument-hint: <component-name> <type>
---
Create a $ARGUMENTS component following our style guide:
- Use TypeScript with strict types
- Include prop interfaces
- Add JSDoc comments
- Export as defaultCommand with positional arguments:
markdown
---
description: Review pull request
argument-hint: [pr-number] [reviewer]
---
Review PR #$1 and assign to @$2:
1. Check code quality and style
2. Verify tests are included
3. Look for security issues
4. Suggest improvements
5. Add comments in GitHub无参数的简单命令:
markdown
---
description: Analyze code for performance bottlenecks
---
Analyze the current file for performance issues:
1. Identify O(n²) or worse algorithms
2. Find unnecessary re-renders or computations
3. Check for memory leaks
4. Suggest optimizations with code examples带所有参数的命令:
markdown
---
description: Generate component boilerplate
argument-hint: <component-name> <type>
---
Create a $ARGUMENTS component following our style guide:
- Use TypeScript with strict types
- Include prop interfaces
- Add JSDoc comments
- Export as default带位置参数的命令:
markdown
---
description: Review pull request
argument-hint: [pr-number] [reviewer]
---
Review PR #$1 and assign to @$2:
1. Check code quality and style
2. Verify tests are included
3. Look for security issues
4. Suggest improvements
5. Add comments in GitHubStep 4: Add Frontmatter Configuration
步骤4:添加frontmatter配置
See in this skill directory for complete frontmatter options.
FRONTMATTER.mdMinimal frontmatter:
yaml
---
description: What this command does
---Full-featured frontmatter:
yaml
---
description: Complete command with all options
argument-hint: [required] <optional>
allowed-tools: Bash(git *), Read(**/*.ts), Write
model: claude-3-5-sonnet-20241022
disable-model-invocation: false
---查看此技能目录中的获取完整的frontmatter选项。
FRONTMATTER.md最简frontmatter:
yaml
---
description: What this command does
---全功能frontmatter:
yaml
---
description: Complete command with all options
argument-hint: [required] <optional>
allowed-tools: Bash(git *), Read(**/*.ts), Write
model: claude-3-5-sonnet-20241022
disable-model-invocation: false
---Step 5: Test the Command
步骤5:测试命令
- Save the file to
.claude/commands/ - Invoke with
/command-name - Check argument substitution works
- Verify tool permissions if using
allowed-tools - Test edge cases (missing args, wrong types)
- 将文件保存到目录
.claude/commands/ - 使用调用命令
/command-name - 检查参数替换是否正常工作
- 如果使用了,验证工具权限是否正确
allowed-tools - 测试边缘情况(缺失参数、错误类型)
Advanced Features
高级功能
Bash Execution
Bash执行
Execute shell commands inline with prefix:
!markdown
---
description: Show git status
allowed-tools: Bash(git status:*)
---
Current repository status:
!`git status`
Recent commits:
!`git log --oneline -5`使用前缀在命令中执行shell命令:
!markdown
---
description: Show git status
allowed-tools: Bash(git status:*)
---
Current repository status:
!`git status`
Recent commits:
!`git log --oneline -5`File References
文件引用
Include file contents with prefix:
@markdown
---
description: Review specific file
argument-hint: <file-path>
---
Review this file for code quality:
@$1
Focus on:
- Type safety
- Error handling
- Performance
- Maintainability使用前缀包含文件内容:
@markdown
---
description: Review specific file
argument-hint: <file-path>
---
Review this file for code quality:
@$1
Focus on:
- Type safety
- Error handling
- Performance
- MaintainabilityTool Permissions
工具权限
Restrict which tools Claude can use:
markdown
---
description: Safe git status check
allowed-tools: Bash(git status:*), Bash(git diff:*)
---
Show current changes:
!`git status`
!`git diff --stat`Tool permission syntax:
- - Allow specific command with any args
Bash(command:*) - - Allow reading TypeScript files in path
Read(path/to/*.ts) - - Allow writing any file
Write - ,
Glob,Grep- Other available toolsEdit
限制Claude可使用的工具:
markdown
---
description: Safe git status check
allowed-tools: Bash(git status:*), Bash(git diff:*)
---
Show current changes:
!`git status`
!`git diff --stat`工具权限语法:
- - 允许特定命令使用任意参数
Bash(command:*) - - 允许读取路径下的TypeScript文件
Read(path/to/*.ts) - - 允许写入任意文件
Write - ,
Glob,Grep- 其他可用工具Edit
Model Selection
模型选择
Override default model for specific commands:
markdown
---
description: Quick syntax fix
model: claude-3-5-haiku-20241022
---
Fix syntax errors in the current file quickly.When to use different models:
- - Fast, simple tasks
claude-3-5-haiku-20241022 - - General purpose (default)
claude-3-5-sonnet-20241022 - - Complex reasoning
claude-opus-4-20250514
为特定命令覆盖默认模型:
markdown
---
description: Quick syntax fix
model: claude-3-5-haiku-20241022
---
Fix syntax errors in the current file quickly.何时使用不同模型:
- - 快速处理简单任务
claude-3-5-haiku-20241022 - - 通用场景(默认)
claude-3-5-sonnet-20241022 - - 复杂推理任务
claude-opus-4-20250514
Disable Auto-Invocation
禁用自动调用
Prevent Claude from calling command automatically:
markdown
---
description: Destructive operation
disable-model-invocation: true
---
!`rm -rf node_modules`
!`npm install`阻止Claude自动调用命令:
markdown
---
description: Destructive operation
disable-model-invocation: true
---
!`rm -rf node_modules`
!`npm install`Common Patterns
常见模式
Code Review Command
代码审查命令
markdown
---
description: Review code changes
argument-hint: [file-or-pr]
allowed-tools: Bash(git *), Read, Grep
---
Review $ARGUMENTS for:
1. **Code Quality**
- Clean, readable code
- Proper naming conventions
- DRY principle
2. **Security**
- Input validation
- SQL injection risks
- XSS vulnerabilities
3. **Performance**
- Inefficient algorithms
- Unnecessary computations
- Memory leaks
4. **Tests**
- Unit test coverage
- Edge cases handled
- Integration tests
Provide specific file:line references for all issues.markdown
---
description: Review code changes
argument-hint: [file-or-pr]
allowed-tools: Bash(git *), Read, Grep
---
Review $ARGUMENTS for:
1. **Code Quality**
- Clean, readable code
- Proper naming conventions
- DRY principle
2. **Security**
- Input validation
- SQL injection risks
- XSS vulnerabilities
3. **Performance**
- Inefficient algorithms
- Unnecessary computations
- Memory leaks
4. **Tests**
- Unit test coverage
- Edge cases handled
- Integration tests
Provide specific file:line references for all issues.Git Workflow Command
Git工作流命令
markdown
---
description: Create feature branch
argument-hint: <feature-name>
allowed-tools: Bash(git *)
---
Create and switch to feature branch:
!`git checkout -b feature/$1`
!`git push -u origin feature/$1`
Branch feature/$1 created and pushed to origin.markdown
---
description: Create feature branch
argument-hint: <feature-name>
allowed-tools: Bash(git *)
---
Create and switch to feature branch:
!`git checkout -b feature/$1`
!`git push -u origin feature/$1`
Branch feature/$1 created and pushed to origin.Documentation Generator
文档生成器
markdown
---
description: Generate API docs
argument-hint: <file-path>
allowed-tools: Read
---
Generate comprehensive API documentation for:
@$1
Include:
- Function signatures with types
- Parameter descriptions
- Return value documentation
- Usage examples
- Error casesmarkdown
---
description: Generate API docs
argument-hint: <file-path>
allowed-tools: Read
---
Generate comprehensive API documentation for:
@$1
Include:
- Function signatures with types
- Parameter descriptions
- Return value documentation
- Usage examples
- Error casesTest Generator
测试用例生成器
markdown
---
description: Generate test cases
argument-hint: <file-to-test>
allowed-tools: Read, Write
---
Generate test cases for:
@$1
Create tests covering:
- Happy path scenarios
- Edge cases
- Error conditions
- Boundary values
Use the existing test framework style.markdown
---
description: Generate test cases
argument-hint: <file-to-test>
allowed-tools: Read, Write
---
Generate test cases for:
@$1
Create tests covering:
- Happy path scenarios
- Edge cases
- Error conditions
- Boundary values
Use the existing test framework style.Troubleshooting
故障排除
Command Not Found
命令未找到
Problem: doesn't autocomplete
/my-commandSolutions:
- Check file is in or
.claude/commands/~/.claude/commands/ - Verify filename matches command ()
.claude/commands/my-command.md - Restart Claude Code to reload commands
- Check for syntax errors in frontmatter
问题: 无法自动补全
/my-command解决方案:
- 检查文件是否位于或
.claude/commands/目录~/.claude/commands/ - 验证文件名与命令名称匹配()
.claude/commands/my-command.md - 重启Claude Code以重新加载命令
- 检查frontmatter中是否存在语法错误
Arguments Not Substituting
参数未替换
Problem: appears literally instead of being replaced
$1Solutions:
- Ensure arguments are passed:
/command arg1 arg2 - Check you're using ,
$1(not$2)${1} - For all args, use instead
$ARGUMENTS - Verify frontmatter is correct
argument-hint
问题: 直接显示为文本而非被替换
$1解决方案:
- 确保已传入参数:
/command arg1 arg2 - 检查是否使用了、
$1(而非$2)${1} - 若要获取所有参数,使用替代
$ARGUMENTS - 验证frontmatter配置正确
argument-hint
Tool Permission Denied
工具权限被拒绝
Problem: Command can't execute bash or read files
Solutions:
- Add frontmatter
allowed-tools - Use specific tool patterns:
Bash(git *) - Check tool name capitalization (e.g., , not
Bash)bash - For file operations, use glob patterns:
Read(**/*.ts)
问题: 命令无法执行bash或读取文件
解决方案:
- 添加frontmatter配置
allowed-tools - 使用特定工具模式:
Bash(git *) - 检查工具名称的大小写(例如而非
Bash)bash - 对于文件操作,使用通配符模式:
Read(**/*.ts)
Command Invokes at Wrong Time
命令在错误时间被调用
Problem: Claude calls command when you don't want it to
Solutions:
- Add to frontmatter
disable-model-invocation: true - Ensure is specific to avoid false triggers
description - Use more explicit command names
问题: Claude在你不需要时调用了命令
解决方案:
- 在frontmatter中添加
disable-model-invocation: true - 确保足够具体,避免误触发
description - 使用更明确的命令名称
Commands vs. Skills
命令与技能的区别
Use Slash Commands When:
适合使用斜杠命令的场景:
- ✅ Task is simple and focused
- ✅ Prompt fits in one Markdown file
- ✅ Need quick, explicit invocation
- ✅ Personal productivity shortcuts
- ✅ 任务简单且聚焦
- ✅ 提示词可放入单个Markdown文件
- ✅ 需要快速、显式的调用
- ✅ 个人生产力快捷方式
Use Skills When:
适合使用技能的场景:
- ✅ Complex, multi-step workflows
- ✅ Context-aware automatic activation
- ✅ Team needs standardization
- ✅ Multiple supporting files needed
- ✅ Sophisticated conditional logic
Example:
- Command: - Quick PR review prompt
/review-pr - Skill: - Comprehensive review framework with security.md, performance.md, style.md, and scripts
code-reviewer
- ✅ 复杂的多步骤工作流
- ✅ 上下文感知的自动激活
- ✅ 团队标准化需求
- ✅ 需要多个支持文件
- ✅ 复杂的条件逻辑
示例:
- 命令: - 快速PR审查提示词
/review-pr - 技能: - 包含security.md、performance.md、style.md和脚本的全面审查框架
code-reviewer
Best Practices
最佳实践
1. Keep Commands Focused
1. 保持命令聚焦
Each command should do ONE thing well. Don't create Swiss Army knife commands.
每个命令应专注于完成一件事。不要创建“瑞士军刀”式的命令。
2. Use Clear Argument Hints
2. 使用清晰的参数提示
yaml
argument-hint: [required] <optional> [choices: a|b|c]yaml
argument-hint: [required] <optional> [choices: a|b|c]3. Document Expected Output
3. 记录预期输出
Tell Claude what format you want:
markdown
Generate a JSON response with this structure:
{
"issues": [],
"suggestions": []
}告诉Claude你想要的输出格式:
markdown
Generate a JSON response with this structure:
{
"issues": [],
"suggestions": []
}4. Include Examples
4. 包含示例
Show Claude what good output looks like:
markdown
Example output:向Claude展示优质输出的样子:
markdown
Example output:Security Issues
Security Issues
- SQL Injection (file.ts:42) - Use parameterized queries
undefined- SQL Injection (file.ts:42) - Use parameterized queries
undefined5. Be Specific with Tool Permissions
5. 工具权限要具体
Don't use - use
allowed-tools: Bashallowed-tools: Bash(git *)不要使用,应使用
allowed-tools: Bashallowed-tools: Bash(git *)6. Test with Edge Cases
6. 测试边缘情况
- Missing arguments
- Wrong argument types
- Files that don't exist
- Empty repositories
- 缺失参数
- 错误的参数类型
- 不存在的文件
- 空仓库
7. Version Control Commands
7. 对命令进行版本控制
Store in git for team collaboration
.claude/commands/将目录存入Git以实现团队协作
.claude/commands/8. Organize with Namespaces
8. 使用命名空间组织命令
Use subdirectories for related commands:
.claude/commands/
├── git/
│ ├── feature.md
│ ├── fix.md
│ └── release.md
└── testing/
├── unit.md
└── e2e.md使用子目录管理相关命令:
.claude/commands/
├── git/
│ ├── feature.md
│ ├── fix.md
│ └── release.md
└── testing/
├── unit.md
└── e2e.mdRelated Documentation
相关文档
- FRONTMATTER.md - Complete frontmatter reference
- EXAMPLES.md - Real-world command examples
- PATTERNS.md - Common command patterns
- FRONTMATTER.md - 完整的frontmatter参考
- EXAMPLES.md - 真实场景的命令示例
- PATTERNS.md - 常见命令模式
Checklist for New Commands
新命令检查清单
Before finalizing a slash command:
- Command name is clear and concise
- Description frontmatter is specific
- Argument hints are provided if needed
- Tool permissions are minimal and specific
- Prompt is focused on one task
- Examples are included in prompt
- Expected output format is specified
- Edge cases are considered
- Command has been tested
- File is in correct directory
Remember: Great slash commands are simple, focused, and make frequent tasks effortless. If you find yourself adding complexity, consider creating a Skill instead.
在最终确定斜杠命令前,请检查:
- 命令名称清晰简洁
- 已添加具体的description frontmatter
- 若需要,已提供参数提示
- 工具权限最小化且具体
- 提示词聚焦于单个任务
- 提示词中包含示例
- 已指定预期输出格式
- 考虑了边缘情况
- 命令已测试
- 文件位于正确目录
记住: 优秀的斜杠命令简单、聚焦,能让频繁执行的任务变得轻松。如果发现需要添加复杂功能,建议考虑创建一个Skill而非命令。