creating-cursor-commands
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreating Cursor Slash Commands
创建Cursor斜杠命令
You are an expert at creating effective Cursor slash commands () that provide clear, actionable instructions for AI assistants.
.cursor/commands/*.md您是创建高效Cursor斜杠命令()的专家,这些命令可为AI助手提供清晰、可执行的指令。
.cursor/commands/*.mdWhen to Use This Skill
何时使用此技能
Use when:
- User wants to create a new Cursor slash command
- User asks to improve existing slash commands
- User needs help understanding Cursor command format
- User wants to convert prompts to slash commands
- User asks about Cursor command validation
Don't use for:
- Cursor rules () - use
.cursor/rules/insteadcreating-cursor-rules-skill - Claude Code slash commands - those use different format with frontmatter
- Complex multi-step workflows - those should be Cursor rules
适用场景:
- 用户想要创建新的Cursor斜杠命令
- 用户要求改进现有斜杠命令
- 用户需要了解Cursor命令格式
- 用户想要将提示词转换为斜杠命令
- 用户询问Cursor命令验证相关问题
不适用场景:
- Cursor规则()- 请改用
.cursor/rules/creating-cursor-rules-skill - Claude Code斜杠命令 - 这类命令使用带前置元数据的不同格式
- 复杂多步骤工作流 - 这类应使用Cursor规则
Quick Reference
快速参考
| Aspect | Requirement |
|---|---|
| File Location | |
| Format | Plain Markdown (NO frontmatter) |
| Filename | Descriptive kebab-case (e.g., |
| Invocation | |
| Content | Clear, actionable instructions with examples |
| 方面 | 要求 |
|---|---|
| 文件位置 | |
| 格式 | 纯Markdown(无前置元数据) |
| 文件名 | 描述性短横线命名法(例如: |
| 调用方式 | 在聊天中输入 |
| 内容 | 清晰、可执行的指令,附带示例 |
Format Requirements
格式要求
Critical Rules
核心规则
- NO frontmatter allowed - Cursor commands are plain Markdown only
- Descriptive filenames - The filename becomes the command name
- Clear instructions - Tell AI exactly what to do
- Include examples - Show desired output format
- 不允许添加前置元数据 - Cursor命令仅支持纯Markdown
- 描述性文件名 - 文件名即为命令名称
- 清晰的指令 - 明确告诉AI要做什么
- 包含示例 - 展示期望的输出格式
File Naming
文件命名
Good filenames:
- →
review-code.md/review-code - →
generate-tests.md/generate-tests - →
explain-code.md/explain-code - →
optimize-performance.md/optimize-performance
Bad filenames:
- - Too cryptic
rc.md - - Use hyphens, not underscores
review_code.md - - Use lowercase
ReviewCode.md - - Too verbose
review-code-thoroughly-with-security-checks.md
良好的文件名:
- →
review-code.md/review-code - →
generate-tests.md/generate-tests - →
explain-code.md/explain-code - →
optimize-performance.md/optimize-performance
糟糕的文件名:
- - 过于简洁晦涩
rc.md - - 使用短横线而非下划线
review_code.md - - 使用小写字母
ReviewCode.md - - 过于冗长
review-code-thoroughly-with-security-checks.md
Schema Validation
模式验证
Schema Location
模式位置
https://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/cursor-command.schema.jsonhttps://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/cursor-command.schema.jsonSchema Structure
模式结构
json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://prpm.dev/schemas/cursor-command.schema.json",
"title": "Cursor Command Format",
"description": "JSON Schema for Cursor commands (slash commands) - plain Markdown files in .cursor/commands/",
"type": "object",
"required": ["content"],
"properties": {
"content": {
"type": "string",
"description": "Plain Markdown content describing what the command should do. No frontmatter supported."
}
},
"additionalProperties": false
}json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://prpm.dev/schemas/cursor-command.schema.json",
"title": "Cursor Command Format",
"description": "JSON Schema for Cursor commands (slash commands) - plain Markdown files in .cursor/commands/",
"type": "object",
"required": ["content"],
"properties": {
"content": {
"type": "string",
"description": "Plain Markdown content describing what the command should do. No frontmatter supported."
}
},
"additionalProperties": false
}Key Validations
关键验证项
- Must be plain Markdown - No YAML frontmatter
- Content-only structure - Single field
content - No metadata - Unlike Cursor rules, commands have no configuration
- 必须是纯Markdown - 无YAML前置元数据
- 仅含内容的结构 - 单一字段
content - 无元数据 - 与Cursor规则不同,命令没有配置项
Common Mistakes
常见错误
| Mistake | Why It's Wrong | How to Fix |
|---|---|---|
| Adding frontmatter | Cursor commands don't support frontmatter | Remove |
| Using default exports syntax | Commands are not code files | Write plain Markdown instructions |
| Vague instructions | AI needs specific guidance | Add concrete examples and steps |
| Too many tasks | Commands should be focused | Create separate commands or use rules |
| Missing context | AI needs to know what to do | Include expected output format |
| 错误 | 原因 | 修复方式 |
|---|---|---|
| 添加前置元数据 | Cursor命令不支持前置元数据 | 完全移除 |
| 使用默认导出语法 | 命令不是代码文件 | 编写纯Markdown指令 |
| 模糊的指令 | AI需要明确的指导 | 添加具体示例和步骤 |
| 任务过多 | 命令应聚焦单一任务 | 创建单独的命令或使用规则 |
| 缺少上下文 | AI需要明确执行目标 | 包含期望的输出格式 |
Best Practices
最佳实践
1. Be Specific and Actionable
1. 具体且可执行
❌ Bad - Vague:
markdown
undefined❌ 糟糕示例 - 模糊:
markdown
undefinedReview Code
代码评审
Review the code for issues.
**✅ Good - Specific:**
```markdown评审代码中的问题。
**✅ 良好示例 - 具体:**
```markdownReview Code
代码评审
Review the selected code for:
- Code quality and best practices
- Potential bugs or edge cases
- Performance improvements
- Security vulnerabilities
Provide specific, actionable feedback with code examples where appropriate.
undefined评审所选代码的以下方面:
- 代码质量与最佳实践
- 潜在bug或边界情况
- 性能优化点
- 安全漏洞
提供具体、可执行的反馈,必要时附带代码示例。
undefined2. Include Expected Output Format
2. 包含期望的输出格式
❌ Bad - No guidance:
markdown
undefined❌ 糟糕示例 - 无指导:
markdown
undefinedGenerate Tests
生成测试用例
Generate tests for this code.
**✅ Good - Clear format:**
```markdown为此代码生成测试用例。
**✅ 良好示例 - 格式清晰:**
```markdownGenerate Tests
生成测试用例
Generate comprehensive unit tests for the selected code.
Include:
- Happy path test cases
- Edge cases and error handling
- Mock external dependencies
- Follow existing test patterns in the project
Use the testing framework already configured in the project.
undefined为所选代码生成全面的单元测试用例。
包含:
- 正常流程测试用例
- 边界情况与错误处理
- 模拟外部依赖
- 遵循项目中的现有测试模式
使用项目中已配置的测试框架。
undefined3. Provide Step-by-Step Instructions
3. 提供分步指令
✅ Good - Structured approach:
markdown
undefined✅ 良好示例 - 结构化方法:
markdown
undefinedExplain Code
代码解释
Provide a clear explanation of what the selected code does.
Include:
- High-level purpose and goals
- Step-by-step breakdown of logic
- Any non-obvious behavior or edge cases
- Dependencies and side effects
- How it fits into the larger codebase
undefined清晰解释所选代码的功能。
包含:
- 高层级目的与目标
- 逻辑的分步拆解
- 任何非直观的行为或边界情况
- 依赖项与副作用
- 它在整个代码库中的定位
undefined4. Reference Project Context
4. 参考项目上下文
✅ Good - Context-aware:
markdown
undefined✅ 良好示例 - 上下文感知:
markdown
undefinedAdd Component
添加组件
Create a new React component following our project conventions.
Structure:
- Functional component with TypeScript
- Props interface defined separately
- Export as named export (not default)
- Co-locate styles if needed
- Follow existing component patterns in components/ directory
Use the same testing approach as existing components.
undefined遵循项目规范创建新的React组件。
结构:
- 带TypeScript的函数式组件
- 单独定义Props接口
- 命名导出(非默认导出)
- 必要时就近放置样式
- 遵循components/目录中的现有组件模式
使用与现有组件相同的测试方法。
undefined5. Focus on One Task
5. 聚焦单一任务
Each command should do ONE thing well.
❌ Bad - Too broad:
markdown
undefined每个命令应专注于完成一件事。
❌ 糟糕示例 - 过于宽泛:
markdown
undefinedFull Stack Feature
全栈功能开发
Create a full-stack feature with:
- Database migration
- API endpoint
- Frontend component
- Tests for everything
- Documentation
**✅ Good - Focused:**
```markdown创建全栈功能,包含:
- 数据库迁移
- API端点
- 前端组件
- 所有测试
- 文档
**✅ 良好示例 - 聚焦:**
```markdownCreate API Endpoint
创建API端点
Create a new API endpoint following our conventions.
Include:
- Input validation with Zod
- Error handling with try/catch
- TypeScript types for request/response
- Follow patterns in existing endpoints
undefined遵循我们的规范创建新的API端点。
包含:
- 使用Zod进行输入验证
- 使用try/catch处理错误
- 请求/响应的TypeScript类型
- 遵循现有端点的模式
undefinedExamples
示例
Code Review Command
代码评审命令
.cursor/commands/review-code.mdmarkdown
undefined.cursor/commands/review-code.mdmarkdown
undefinedReview Code
代码评审
Review the selected code for:
-
Code Quality
- Clean, readable code
- Proper naming conventions
- DRY principle adherence
-
Security
- Input validation
- SQL injection risks
- XSS vulnerabilities
- Authentication/authorization checks
-
Performance
- Inefficient algorithms
- Unnecessary computations
- Memory leaks
- Database query optimization
-
Best Practices
- Error handling
- Type safety
- Test coverage
- Documentation
Provide specific file and line references for all issues found.
Format findings as a numbered list with severity (Critical/High/Medium/Low).
undefined评审所选代码的以下方面:
-
代码质量
- 简洁、可读的代码
- 恰当的命名规范
- 遵循DRY原则
-
安全性
- 输入验证
- SQL注入风险
- XSS漏洞
- 认证/授权检查
-
性能
- 低效算法
- 不必要的计算
- 内存泄漏
- 数据库查询优化
-
最佳实践
- 错误处理
- 类型安全
- 测试覆盖率
- 文档
为所有发现的问题提供具体的文件和行号引用。
将发现的问题格式化为带有严重程度(Critical/High/Medium/Low)的编号列表。
undefinedTest Generation Command
测试生成命令
.cursor/commands/generate-tests.mdmarkdown
undefined.cursor/commands/generate-tests.mdmarkdown
undefinedGenerate Tests
生成测试用例
Generate comprehensive unit tests for the selected code.
Test Coverage:
- Happy path scenarios
- Edge cases
- Error conditions
- Boundary values
- Invalid inputs
Requirements:
- Use existing test framework (Jest/Vitest/etc.)
- Follow project testing patterns
- Mock external dependencies
- Include test descriptions
- Aim for 100% code coverage
Format tests in the same style as existing test files in the project.
undefined为所选代码生成全面的单元测试用例。
测试覆盖:
- 正常流程场景
- 边界情况
- 错误条件
- 边界值
- 无效输入
要求:
- 使用现有测试框架(Jest/Vitest等)
- 遵循项目测试模式
- 模拟外部依赖
- 包含测试描述
- 目标为100%代码覆盖率
按照项目中现有测试文件的风格编写测试用例。
undefinedDocumentation Generator
文档生成器
.cursor/commands/document-function.mdmarkdown
undefined.cursor/commands/document-function.mdmarkdown
undefinedDocument Function
函数文档生成
Generate comprehensive documentation for the selected function.
Include:
Function signature:
- Parameter types and descriptions
- Return type and description
- Generic types if applicable
Description:
- What the function does (one-line summary)
- Why it exists (use case)
- How it works (implementation details if non-obvious)
Examples:
- Basic usage example
- Edge case example if relevant
Notes:
- Any side effects
- Performance considerations
- Related functions
Use JSDoc/TSDoc format for TypeScript/JavaScript.
undefined为所选函数生成全面的文档。
包含:
函数签名:
- 参数类型与描述
- 返回类型与描述
- 泛型类型(如有)
描述:
- 函数功能(单行摘要)
- 存在意义(使用场景)
- 工作原理(非直观的实现细节)
示例:
- 基础使用示例
- 相关边界情况示例
注意事项:
- 任何副作用
- 性能考虑
- 相关函数
为TypeScript/JavaScript使用JSDoc/TSDoc格式。
undefinedOptimization Command
性能优化命令
.cursor/commands/optimize-performance.mdmarkdown
undefined.cursor/commands/optimize-performance.mdmarkdown
undefinedOptimize Performance
性能优化
Analyze the selected code for performance improvements.
Look for:
Algorithmic Issues:
- O(n²) or worse time complexity
- Unnecessary nested loops
- Inefficient data structures
React-Specific:
- Unnecessary re-renders
- Missing useMemo/useCallback
- Large component trees
- Props drilling
General:
- Redundant computations
- Memory leaks
- Synchronous blocking operations
- Large bundle size contributors
Suggest specific optimizations with code examples.
Estimate performance impact of each suggestion.
undefined分析所选代码以寻找性能改进点。
关注:
算法问题:
- O(n²)或更差的时间复杂度
- 不必要的嵌套循环
- 低效的数据结构
React特定问题:
- 不必要的重渲染
- 缺少useMemo/useCallback
- 大型组件树
- Props透传
通用问题:
- 冗余计算
- 内存泄漏
- 同步阻塞操作
- 包体积过大的贡献因素
提供带有代码示例的具体优化建议。
评估每个建议的性能影响。
undefinedRefactoring Command
重构命令
.cursor/commands/refactor-clean.mdmarkdown
undefined.cursor/commands/refactor-clean.mdmarkdown
undefinedRefactor for Clean Code
代码清洁重构
Refactor the selected code to improve maintainability.
Apply these principles:
Extract Functions:
- Break down large functions (> 50 lines)
- Create single-responsibility functions
- Use descriptive names
Simplify Logic:
- Reduce nesting (early returns)
- Eliminate duplication
- Clarify complex conditionals
Improve Names:
- Use meaningful variable names
- Follow project naming conventions
- Avoid abbreviations
Type Safety:
- Add proper TypeScript types
- Eliminate 'any' types
- Use interfaces/types
Preserve all existing functionality and tests.
undefined重构所选代码以提高可维护性。
应用以下原则:
提取函数:
- 拆分大型函数(>50行)
- 创建单一职责函数
- 使用描述性名称
简化逻辑:
- 减少嵌套(提前返回)
- 消除重复代码
- 明确复杂条件
优化命名:
- 使用有意义的变量名
- 遵循项目命名规范
- 避免缩写
类型安全:
- 添加适当的TypeScript类型
- 消除'any'类型
- 使用接口/类型
保留所有现有功能和测试。
undefinedBug Fix Command
Bug修复命令
.cursor/commands/fix-bug.mdmarkdown
undefined.cursor/commands/fix-bug.mdmarkdown
undefinedFix Bug
Bug修复
Analyze and fix the bug in the selected code.
Investigation steps:
- Identify the root cause
- Explain why the bug occurs
- Propose a fix
- Consider edge cases
- Suggest tests to prevent regression
Fix requirements:
- Minimal changes to fix the issue
- Don't break existing functionality
- Add/update tests
- Add comments explaining the fix if non-obvious
Explain the fix clearly with before/after code examples.
undefined分析并修复所选代码中的Bug。
调查步骤:
- 确定根本原因
- 解释Bug产生的原因
- 提出修复方案
- 考虑边界情况
- 建议防止回归的测试用例
修复要求:
- 最小化修改以解决问题
- 不破坏现有功能
- 添加/更新测试
- 如修复非直观则添加注释说明
通过前后代码示例清晰解释修复内容。
undefinedStorage Locations
存储位置
Commands can be stored in multiple locations (in order of precedence):
- Project commands: directory in your project (shared with team)
.cursor/commands/ - Global commands: directory (personal, all projects)
~/.cursor/commands/ - Team commands: Created via Cursor Dashboard (enterprise teams)
Best practice: Store team-wide commands in and commit to version control.
.cursor/commands/命令可存储在多个位置(优先级从高到低):
- 项目命令:项目中的目录(与团队共享)
.cursor/commands/ - 全局命令:目录(个人所有,适用于所有项目)
~/.cursor/commands/ - 团队命令:通过Cursor Dashboard创建(企业团队)
最佳实践: 将团队通用命令存储在中并提交到版本控制。
.cursor/commands/Testing Your Commands
测试您的命令
After creating a command:
- Save to
.cursor/commands/command-name.md - Invoke with in Cursor chat
/command-name - Verify AI follows instructions correctly
- Test edge cases:
- No code selected
- Empty files
- Complex code
- Different languages
- Iterate based on results
创建命令后:
- 保存到
.cursor/commands/command-name.md - 调用:在Cursor聊天中输入
/command-name - 验证AI是否正确遵循指令
- 测试边界情况:
- 未选择代码
- 空文件
- 复杂代码
- 不同语言
- 迭代:根据结果优化命令
Commands vs. Cursor Rules
命令与Cursor规则的对比
Use Commands When:
使用命令的场景:
- ✅ Simple, focused task
- ✅ Explicit user invocation desired
- ✅ Personal productivity shortcuts
- ✅ One-time operations
- ✅ 简单、聚焦的任务
- ✅ 需要用户显式调用
- ✅ 个人生产力快捷方式
- ✅ 一次性操作
Use Cursor Rules When:
使用Cursor规则的场景:
- ✅ Context-aware automatic activation
- ✅ File-type specific guidance
- ✅ Team standardization
- ✅ Always-on conventions
Example:
- Command: - Explicitly generate tests when asked
/generate-tests - Rule: Auto-attach testing conventions to files
*.test.ts
- ✅ 上下文感知自动激活
- ✅ 特定文件类型的指导
- ✅ 团队标准化
- ✅ 始终生效的规范
示例:
- 命令: - 显式请求时生成测试用例
/generate-tests - 规则: 自动为文件附加测试规范
*.test.ts
Validation Checklist
验证清单
Before finalizing a command:
- Filename is descriptive and kebab-case
- NO frontmatter (plain Markdown only)
- Instructions are clear and specific
- Expected output format is described
- Examples are included
- Steps are actionable
- Command is focused on one task
- Edge cases are considered
- File is in directory
.cursor/commands/ - Command has been tested
最终确定命令前:
- 文件名具有描述性且为短横线命名法
- 无前置元数据(仅纯Markdown)
- 指令清晰具体
- 描述了期望的输出格式
- 包含示例
- 步骤可执行
- 命令聚焦单一任务
- 考虑了边界情况
- 文件位于目录
.cursor/commands/ - 命令已测试
Converting from Other Formats
从其他格式转换
From Claude Code Slash Commands
从Claude Code斜杠命令转换
Claude Code commands use frontmatter - remove it for Cursor:
Claude Code:
markdown
---
description: Review code
allowed-tools: Read, Grep
---
Review the code...Cursor:
markdown
undefinedClaude Code命令使用前置元数据 - 转换为Cursor命令时需移除:
Claude Code:
markdown
---
description: Review code
allowed-tools: Read, Grep
---
Review the code...Cursor:
markdown
undefinedReview Code
代码评审
Review the code...
undefinedReview the code...
undefinedFrom Cursor Rules
从Cursor规则转换
Rules use frontmatter and are context-aware - simplify to plain Markdown:
Cursor Rule:
markdown
---
description: Testing conventions
globs: ["**/*.test.ts"]
---规则使用前置元数据且上下文感知 - 简化为纯Markdown:
Cursor Rule:
markdown
---
description: Testing conventions
globs: ["**/*.test.ts"]
---Testing Standards
测试标准
Always write tests...
**Cursor Command:**
```markdownAlways write tests...
**Cursor Command:**
```markdownGenerate Tests
生成测试用例
Generate comprehensive tests...
undefinedGenerate comprehensive tests...
undefinedCommon Use Cases
常见使用场景
Code Quality
代码质量
- - Code review
/review-code - - Clean code refactoring
/refactor-clean - - Fix linting issues
/fix-lint - - Improve TypeScript types
/improve-types
- - 代码评审
/review-code - - 清洁代码重构
/refactor-clean - - 修复代码规范问题
/fix-lint - - 优化TypeScript类型
/improve-types
Testing
测试
- - Generate unit tests
/generate-tests - - Add edge case tests
/test-edge-cases - - Check test coverage
/test-coverage
- - 生成单元测试
/generate-tests - - 添加边界情况测试
/test-edge-cases - - 检查测试覆盖率
/test-coverage
Documentation
文档
- - Document function
/document-function - - Add code comments
/add-comments - - Explain complex code
/explain-code
- - 函数文档生成
/document-function - - 添加代码注释
/add-comments - - 复杂代码解释
/explain-code
Performance
性能
- - Performance optimization
/optimize-performance - - Analyze time complexity
/analyze-complexity - - Reduce bundle size
/reduce-bundle
- - 性能优化
/optimize-performance - - 时间复杂度分析
/analyze-complexity - - 减小包体积
/reduce-bundle
Security
安全
- - Security vulnerability check
/security-audit - - Add input validation
/sanitize-input - - Review authentication
/check-auth
- - 安全漏洞检查
/security-audit - - 添加输入验证
/sanitize-input - - 评审认证机制
/check-auth
References
参考资料
- Schema:
https://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/cursor-command.schema.json - Docs:
/Users/khaliqgant/Projects/prpm/app/packages/converters/docs/cursor.md - Official Docs: https://cursor.com/docs/agent/chat/commands
- 模式:
https://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/cursor-command.schema.json - 文档:
/Users/khaliqgant/Projects/prpm/app/packages/converters/docs/cursor.md - 官方文档:https://cursor.com/docs/agent/chat/commands
Remember
注意事项
Golden Rules:
- NO frontmatter - plain Markdown only
- Descriptive filenames - they become command names
- Clear instructions - AI needs specific guidance
- Include examples - show desired output
- One task per command - keep it focused
Goal: Create commands that make frequent tasks effortless with a simple invocation.
/command-name黄金法则:
- 无前置元数据 - 仅纯Markdown
- 描述性文件名 - 文件名即为命令名
- 清晰的指令 - AI需要明确指导
- 包含示例 - 展示期望输出
- 单一任务 - 保持命令聚焦
目标: 创建只需通过简单的调用即可简化频繁任务的命令。
/command-name