command-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommand Creator
命令创建工具
Create custom slash commands for Claude Code. Commands are Markdown files that define reusable prompts with support for arguments, bash execution, file references, and tool permissions.
为Claude Code创建自定义斜杠命令。命令是Markdown文件,用于定义可复用的提示,支持参数、bash执行、文件引用和工具权限。
Command Locations
命令位置
| Type | Location | Scope |
|---|---|---|
| Project | | Shared with team via git |
| Personal | | Available across all projects |
Project commands take precedence over personal commands with the same name.
| 类型 | 位置 | 作用范围 |
|---|---|---|
| 项目级 | | 通过git与团队共享 |
| 个人级 | | 在所有项目中可用 |
项目级命令优先级高于同名的个人级命令。
Basic Structure
基本结构
markdown
---
description: Brief description shown in /help
---
Your prompt instructions here.Filename becomes the command name: →
review.md/reviewmarkdown
---
description: 在/help中显示的简要描述
---
此处填写你的提示说明。文件名即为命令名称: →
review.md/reviewFrontmatter Options
前置配置选项
| Field | Purpose | Default |
|---|---|---|
| Brief description for /help | First line of prompt |
| Tools the command can use | Inherits from conversation |
| Shows usage hint in autocomplete | None |
| Specific model to use | Inherits from conversation |
| Prevent Skill tool from calling this | false |
| Command-scoped hooks (PreToolUse, PostToolUse, Stop) | None |
| 字段 | 用途 | 默认值 |
|---|---|---|
| 用于/help的简要描述 | 提示内容的第一行 |
| 命令可使用的工具 | 继承自对话设置 |
| 在自动补全中显示使用提示 | 无 |
| 要使用的特定模型 | 继承自对话设置 |
| 阻止Skill工具调用此命令 | false |
| 命令级钩子(PreToolUse、PostToolUse、Stop) | 无 |
Arguments
参数
All arguments: $ARGUMENTS
$ARGUMENTS所有参数:$ARGUMENTS
$ARGUMENTSmarkdown
---
description: Fix an issue
---
Fix issue #$ARGUMENTS following our coding standardsUsage: → = "123 high-priority"
/fix-issue 123 high-priority$ARGUMENTSmarkdown
---
description: 修复问题
---
按照我们的编码标准修复问题#$ARGUMENTS使用示例: → = "123 high-priority"
/fix-issue 123 high-priority$ARGUMENTSPositional: $1
, $2
, etc.
$1$2位置参数:$1
, $2
等
$1$2markdown
---
argument-hint: [pr-number] [priority] [assignee]
description: Review pull request
---
Review PR #$1 with priority $2 and assign to $3.Usage:
/review-pr 456 high alicemarkdown
---
argument-hint: [pr-number] [priority] [assignee]
description: 审核拉取请求
---
审核PR #$1,优先级为$2,指定给$3。使用示例:
/review-pr 456 high aliceBash Execution
Bash执行
Execute bash before the command runs using the exclamation mark prefix. Output is included in context.
markdown
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a git commit
---使用感叹号前缀在命令运行前执行bash命令,输出会包含在上下文当中。
markdown
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: 创建git提交
---Context
上下文
- Current git status: !`git status`
- Current git diff: !`git diff HEAD`
- Current branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -10`
- 当前git状态: !`git status`
- 当前git差异: !`git diff HEAD`
- 当前分支: !`git branch --show-current`
- 最近提交: !`git log --oneline -10`
Task
任务
Create a git commit based on the above changes.
**Required**: Include `allowed-tools` with the Bash tool when using bang execution (the exclamation mark prefix).基于上述变更创建一个git提交。
**必填项**:当使用感叹号执行时,需在`allowed-tools`中包含Bash工具。File References
文件引用
Include file contents using the prefix:
@markdown
Review the implementation in @src/utils/helpers.js
Compare @src/old-version.js with @src/new-version.js使用前缀引入文件内容:
@markdown
审核@src/utils/helpers.js中的实现
对比@src/old-version.js与@src/new-version.jsNamespacing
命名空间
Subdirectories group related commands. The subdirectory appears in the description:
- →
.claude/commands/frontend/component.md(project:frontend)/component - →
.claude/commands/backend/test.md(project:backend)/test
Commands in different subdirectories can share names.
子目录用于分组相关命令,子目录会显示在描述中:
- →
.claude/commands/frontend/component.md(project:frontend)/component - →
.claude/commands/backend/test.md(project:backend)/test
不同子目录下的命令可以重名。
Example: Complete Command
示例:完整命令
markdown
---
allowed-tools: Bash(npm:*), Bash(git:*), Read, Edit, Write
argument-hint: [component-name]
description: Create a new React component with tests
model: claude-sonnet-4-20250514
---markdown
---
allowed-tools: Bash(npm:*), Bash(git:*), Read, Edit, Write
argument-hint: [component-name]
description: 创建带测试的新React组件
model: claude-sonnet-4-20250514
---Context
上下文
- Existing components: !`ls src/components/`
- Project structure: !`ls -la src/`
- 现有组件: !`ls src/components/`
- 项目结构: !`ls -la src/`
Task
任务
Create a new React component named $1:
- Create component file at @src/components/$1.tsx
- Create test file at @src/components/$1.test.tsx
- Export from @src/components/index.ts
- Follow patterns in existing components
undefined创建名为$1的新React组件:
- 在@src/components/$1.tsx创建组件文件
- 在@src/components/$1.test.tsx创建测试文件
- 在@src/components/index.ts中导出
- 遵循现有组件的模式
undefinedHooks in Commands
命令中的钩子
Define command-scoped hooks that run during execution:
markdown
---
description: Deploy with validation
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate.sh"
once: true
---
Deploy to staging environment.The option runs the hook only once per session.
once: true定义在执行过程中运行的命令级钩子:
markdown
---
description: 带验证的部署
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate.sh"
once: true
---
部署到预发布环境。once: trueBest Practices
最佳实践
- Keep prompts concise - Claude is smart; don't over-explain
- Use bash execution for context - Gather relevant state before the task
- Specify allowed-tools - Limit to what the command needs
- Add argument-hint - Help users understand expected arguments
- Use file references - Point to relevant files with
@ - Namespace related commands - Use subdirectories for organization
- 保持提示简洁 - Claude很智能,无需过度解释
- 使用bash执行获取上下文 - 在任务前收集相关状态
- 指定allowed-tools - 限制为命令所需的工具
- 添加argument-hint - 帮助用户理解预期参数
- 使用文件引用 - 用指向相关文件
@ - 为相关命令设置命名空间 - 使用子目录进行组织