creating-cursor-commands

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Creating Cursor Slash Commands

创建Cursor斜杠命令

You are an expert at creating effective Cursor slash commands (
.cursor/commands/*.md
) that provide clear, actionable instructions for AI assistants.
您是创建高效Cursor斜杠命令(
.cursor/commands/*.md
)的专家,这些命令可为AI助手提供清晰、可执行的指令。

When 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 (
    .cursor/rules/
    ) - use
    creating-cursor-rules-skill
    instead
  • 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

快速参考

AspectRequirement
File Location
.cursor/commands/*.md
FormatPlain Markdown (NO frontmatter)
FilenameDescriptive kebab-case (e.g.,
review-code.md
,
generate-tests.md
)
Invocation
/command-name
in chat
ContentClear, actionable instructions with examples
方面要求
文件位置
.cursor/commands/*.md
格式纯Markdown(无前置元数据)
文件名描述性短横线命名法(例如:
review-code.md
generate-tests.md
调用方式在聊天中输入
/command-name
内容清晰、可执行的指令,附带示例

Format Requirements

格式要求

Critical Rules

核心规则

  1. NO frontmatter allowed - Cursor commands are plain Markdown only
  2. Descriptive filenames - The filename becomes the command name
  3. Clear instructions - Tell AI exactly what to do
  4. Include examples - Show desired output format
  1. 不允许添加前置元数据 - Cursor命令仅支持纯Markdown
  2. 描述性文件名 - 文件名即为命令名称
  3. 清晰的指令 - 明确告诉AI要做什么
  4. 包含示例 - 展示期望的输出格式

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:
  • rc.md
    - Too cryptic
  • review_code.md
    - Use hyphens, not underscores
  • ReviewCode.md
    - Use lowercase
  • review-code-thoroughly-with-security-checks.md
    - Too verbose
良好的文件名:
  • 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.json
https://github.com/pr-pm/prpm/blob/main/packages/converters/schemas/cursor-command.schema.json

Schema 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

关键验证项

  1. Must be plain Markdown - No YAML frontmatter
  2. Content-only structure - Single
    content
    field
  3. No metadata - Unlike Cursor rules, commands have no configuration
  1. 必须是纯Markdown - 无YAML前置元数据
  2. 仅含内容的结构 - 单一
    content
    字段
  3. 无元数据 - 与Cursor规则不同,命令没有配置项

Common Mistakes

常见错误

MistakeWhy It's WrongHow to Fix
Adding frontmatterCursor commands don't support frontmatterRemove
---
blocks entirely
Using default exports syntaxCommands are not code filesWrite plain Markdown instructions
Vague instructionsAI needs specific guidanceAdd concrete examples and steps
Too many tasksCommands should be focusedCreate separate commands or use rules
Missing contextAI needs to know what to doInclude expected output format
错误原因修复方式
添加前置元数据Cursor命令不支持前置元数据完全移除
---
使用默认导出语法命令不是代码文件编写纯Markdown指令
模糊的指令AI需要明确的指导添加具体示例和步骤
任务过多命令应聚焦单一任务创建单独的命令或使用规则
缺少上下文AI需要明确执行目标包含期望的输出格式

Best Practices

最佳实践

1. Be Specific and Actionable

1. 具体且可执行

❌ Bad - Vague:
markdown
undefined
❌ 糟糕示例 - 模糊:
markdown
undefined

Review Code

代码评审

Review the code for issues.

**✅ Good - Specific:**
```markdown
评审代码中的问题。

**✅ 良好示例 - 具体:**
```markdown

Review 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或边界情况
  • 性能优化点
  • 安全漏洞
提供具体、可执行的反馈,必要时附带代码示例。
undefined

2. Include Expected Output Format

2. 包含期望的输出格式

❌ Bad - No guidance:
markdown
undefined
❌ 糟糕示例 - 无指导:
markdown
undefined

Generate Tests

生成测试用例

Generate tests for this code.

**✅ Good - Clear format:**
```markdown
为此代码生成测试用例。

**✅ 良好示例 - 格式清晰:**
```markdown

Generate 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
为所选代码生成全面的单元测试用例。
包含:
  • 正常流程测试用例
  • 边界情况与错误处理
  • 模拟外部依赖
  • 遵循项目中的现有测试模式
使用项目中已配置的测试框架。
undefined

3. Provide Step-by-Step Instructions

3. 提供分步指令

✅ Good - Structured approach:
markdown
undefined
✅ 良好示例 - 结构化方法:
markdown
undefined

Explain 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
清晰解释所选代码的功能。
包含:
  • 高层级目的与目标
  • 逻辑的分步拆解
  • 任何非直观的行为或边界情况
  • 依赖项与副作用
  • 它在整个代码库中的定位
undefined

4. Reference Project Context

4. 参考项目上下文

✅ Good - Context-aware:
markdown
undefined
✅ 良好示例 - 上下文感知:
markdown
undefined

Add 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/目录中的现有组件模式
使用与现有组件相同的测试方法。
undefined

5. Focus on One Task

5. 聚焦单一任务

Each command should do ONE thing well.
❌ Bad - Too broad:
markdown
undefined
每个命令应专注于完成一件事。
❌ 糟糕示例 - 过于宽泛:
markdown
undefined

Full Stack Feature

全栈功能开发

Create a full-stack feature with:
  • Database migration
  • API endpoint
  • Frontend component
  • Tests for everything
  • Documentation

**✅ Good - Focused:**
```markdown
创建全栈功能,包含:
  • 数据库迁移
  • API端点
  • 前端组件
  • 所有测试
  • 文档

**✅ 良好示例 - 聚焦:**
```markdown

Create 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类型
  • 遵循现有端点的模式
undefined

Examples

示例

Code Review Command

代码评审命令

.cursor/commands/review-code.md
:
markdown
undefined
.cursor/commands/review-code.md
markdown
undefined

Review Code

代码评审

Review the selected code for:
  1. Code Quality
    • Clean, readable code
    • Proper naming conventions
    • DRY principle adherence
  2. Security
    • Input validation
    • SQL injection risks
    • XSS vulnerabilities
    • Authentication/authorization checks
  3. Performance
    • Inefficient algorithms
    • Unnecessary computations
    • Memory leaks
    • Database query optimization
  4. 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
评审所选代码的以下方面:
  1. 代码质量
    • 简洁、可读的代码
    • 恰当的命名规范
    • 遵循DRY原则
  2. 安全性
    • 输入验证
    • SQL注入风险
    • XSS漏洞
    • 认证/授权检查
  3. 性能
    • 低效算法
    • 不必要的计算
    • 内存泄漏
    • 数据库查询优化
  4. 最佳实践
    • 错误处理
    • 类型安全
    • 测试覆盖率
    • 文档
为所有发现的问题提供具体的文件和行号引用。 将发现的问题格式化为带有严重程度(Critical/High/Medium/Low)的编号列表。
undefined

Test Generation Command

测试生成命令

.cursor/commands/generate-tests.md
:
markdown
undefined
.cursor/commands/generate-tests.md
markdown
undefined

Generate 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%代码覆盖率
按照项目中现有测试文件的风格编写测试用例。
undefined

Documentation Generator

文档生成器

.cursor/commands/document-function.md
:
markdown
undefined
.cursor/commands/document-function.md
markdown
undefined

Document 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格式。
undefined

Optimization Command

性能优化命令

.cursor/commands/optimize-performance.md
:
markdown
undefined
.cursor/commands/optimize-performance.md
markdown
undefined

Optimize 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透传
通用问题:
  • 冗余计算
  • 内存泄漏
  • 同步阻塞操作
  • 包体积过大的贡献因素
提供带有代码示例的具体优化建议。 评估每个建议的性能影响。
undefined

Refactoring Command

重构命令

.cursor/commands/refactor-clean.md
:
markdown
undefined
.cursor/commands/refactor-clean.md
markdown
undefined

Refactor 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'类型
  • 使用接口/类型
保留所有现有功能和测试。
undefined

Bug Fix Command

Bug修复命令

.cursor/commands/fix-bug.md
:
markdown
undefined
.cursor/commands/fix-bug.md
markdown
undefined

Fix Bug

Bug修复

Analyze and fix the bug in the selected code.
Investigation steps:
  1. Identify the root cause
  2. Explain why the bug occurs
  3. Propose a fix
  4. Consider edge cases
  5. 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。
调查步骤:
  1. 确定根本原因
  2. 解释Bug产生的原因
  3. 提出修复方案
  4. 考虑边界情况
  5. 建议防止回归的测试用例
修复要求:
  • 最小化修改以解决问题
  • 不破坏现有功能
  • 添加/更新测试
  • 如修复非直观则添加注释说明
通过前后代码示例清晰解释修复内容。
undefined

Storage Locations

存储位置

Commands can be stored in multiple locations (in order of precedence):
  1. Project commands:
    .cursor/commands/
    directory in your project (shared with team)
  2. Global commands:
    ~/.cursor/commands/
    directory (personal, all projects)
  3. Team commands: Created via Cursor Dashboard (enterprise teams)
Best practice: Store team-wide commands in
.cursor/commands/
and commit to version control.
命令可存储在多个位置(优先级从高到低):
  1. 项目命令:项目中的
    .cursor/commands/
    目录(与团队共享)
  2. 全局命令
    ~/.cursor/commands/
    目录(个人所有,适用于所有项目)
  3. 团队命令:通过Cursor Dashboard创建(企业团队)
最佳实践: 将团队通用命令存储在
.cursor/commands/
中并提交到版本控制。

Testing Your Commands

测试您的命令

After creating a command:
  1. Save to
    .cursor/commands/command-name.md
  2. Invoke with
    /command-name
    in Cursor chat
  3. Verify AI follows instructions correctly
  4. Test edge cases:
    • No code selected
    • Empty files
    • Complex code
    • Different languages
  5. Iterate based on results
创建命令后:
  1. 保存
    .cursor/commands/command-name.md
  2. 调用:在Cursor聊天中输入
    /command-name
  3. 验证AI是否正确遵循指令
  4. 测试边界情况
    • 未选择代码
    • 空文件
    • 复杂代码
    • 不同语言
  5. 迭代:根据结果优化命令

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:
    /generate-tests
    - Explicitly generate tests when asked
  • Rule: Auto-attach testing conventions to
    *.test.ts
    files
  • ✅ 上下文感知自动激活
  • ✅ 特定文件类型的指导
  • ✅ 团队标准化
  • ✅ 始终生效的规范
示例:
  • 命令:
    /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
    .cursor/commands/
    directory
  • 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
undefined
Claude Code命令使用前置元数据 - 转换为Cursor命令时需移除:
Claude Code:
markdown
---
description: Review code
allowed-tools: Read, Grep
---

Review the code...
Cursor:
markdown
undefined

Review Code

代码评审

Review the code...
undefined
Review the code...
undefined

From 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:**
```markdown
Always write tests...

**Cursor Command:**
```markdown

Generate Tests

生成测试用例

Generate comprehensive tests...
undefined
Generate comprehensive tests...
undefined

Common Use Cases

常见使用场景

Code Quality

代码质量

  • /review-code
    - Code review
  • /refactor-clean
    - Clean code refactoring
  • /fix-lint
    - Fix linting issues
  • /improve-types
    - Improve TypeScript types
  • /review-code
    - 代码评审
  • /refactor-clean
    - 清洁代码重构
  • /fix-lint
    - 修复代码规范问题
  • /improve-types
    - 优化TypeScript类型

Testing

测试

  • /generate-tests
    - Generate unit tests
  • /test-edge-cases
    - Add edge case tests
  • /test-coverage
    - Check test coverage
  • /generate-tests
    - 生成单元测试
  • /test-edge-cases
    - 添加边界情况测试
  • /test-coverage
    - 检查测试覆盖率

Documentation

文档

  • /document-function
    - Document function
  • /add-comments
    - Add code comments
  • /explain-code
    - Explain complex code
  • /document-function
    - 函数文档生成
  • /add-comments
    - 添加代码注释
  • /explain-code
    - 复杂代码解释

Performance

性能

  • /optimize-performance
    - Performance optimization
  • /analyze-complexity
    - Analyze time complexity
  • /reduce-bundle
    - Reduce bundle size
  • /optimize-performance
    - 性能优化
  • /analyze-complexity
    - 时间复杂度分析
  • /reduce-bundle
    - 减小包体积

Security

安全

  • /security-audit
    - Security vulnerability check
  • /sanitize-input
    - Add input validation
  • /check-auth
    - Review authentication
  • /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:
  1. NO frontmatter - plain Markdown only
  2. Descriptive filenames - they become command names
  3. Clear instructions - AI needs specific guidance
  4. Include examples - show desired output
  5. One task per command - keep it focused
Goal: Create commands that make frequent tasks effortless with a simple
/command-name
invocation.
黄金法则:
  1. 无前置元数据 - 仅纯Markdown
  2. 描述性文件名 - 文件名即为命令名
  3. 清晰的指令 - AI需要明确指导
  4. 包含示例 - 展示期望输出
  5. 单一任务 - 保持命令聚焦
目标: 创建只需通过简单的
/command-name
调用即可简化频繁任务的命令。