create-skill-file
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude Agent Skill Writing Guide
Claude Agent Skill 编写指南
How to create high-quality SKILL.md files
如何创建高质量的SKILL.md文件
Table of Contents
目录
Quick Start
快速开始
3 Steps to Create a Skill
创建技能的3个步骤
Step 1: Create Directory
bash
mkdir -p .claude/skill/your-skill-name
cd .claude/skill/your-skill-nameStep 2: Create SKILL.md
markdown
---
name: your-skill-name
description: Brief description with trigger keywords and scenarios
---步骤1:创建目录
bash
mkdir -p .claude/skill/your-skill-name
cd .claude/skill/your-skill-name步骤2:创建SKILL.md
markdown
---
name: your-skill-name
description: Brief description with trigger keywords and scenarios
---Your Skill Title
你的技能标题
When to Use This Skill
何时使用此技能
- User asks to [specific scenario]
- User mentions "[keyword]"
- 用户要求[具体场景]
- 用户提及"[关键词]"
How It Works
工作原理
- Step 1: [Action]
- Step 2: [Action]
- 步骤1:[操作]
- 步骤2:[操作]
Examples
示例
Input: User request
Output: Expected result
**Step 3: Test**
- Use keywords from description in conversation to trigger
- Observe whether Claude executes correctly
- Adjust based on effectiveness
---输入:用户请求
输出:预期结果
**步骤3:测试**
- 在对话中使用描述中的关键词触发技能
- 观察Claude是否正确执行
- 根据效果进行调整
---Core Principles
核心原则
1. Keep It Concise
1. 保持简洁
Only add new knowledge that Claude doesn't know:
- ✅ Project-specific workflows
- ✅ Special naming conventions or format requirements
- ✅ How to use custom tools and scripts
- ❌ General programming knowledge
- ❌ Obvious steps
Example Comparison:
markdown
undefined仅添加Claude不知道的新知识:
- ✅ 项目特定的工作流
- ✅ 特殊命名规范或格式要求
- ✅ 自定义工具和脚本的使用方法
- ❌ 通用编程知识
- ❌ 显而易见的步骤
示例对比:
markdown
undefined❌ Too Detailed
❌ 过于详细
- Create Python file
- Import necessary libraries
- Define functions
- Write main program logic
- 创建Python文件
- 导入必要的库
- 定义函数
- 编写主程序逻辑
✅ Concise and Effective
✅ 简洁有效
Use to call internal API.
Request headers must include (from environment variable ).
scripts/api_client.pyX-Internal-TokenINTERNAL_API_KEYundefined使用调用内部API。
请求头必须包含(来自环境变量)。
scripts/api_client.pyX-Internal-TokenINTERNAL_API_KEYundefined2. Set Appropriate Freedom
2. 设置合适的自由度
| Freedom | Use Case | Writing Approach |
|---|---|---|
| High | Requires creativity, multiple solutions | Provide guiding principles, not specific steps |
| Medium | Recommended patterns but allow variations | Provide parameterized examples and default flows |
| Low | Error-prone, requires strict execution | Provide detailed step-by-step instructions or scripts |
Decision Criteria:
- Is there a clear "correct answer"? → Low freedom
- Does it need to adapt to different scenarios? → High freedom
- What's the cost of errors? → High cost = low freedom
| 自由度 | 使用场景 | 编写方式 |
|---|---|---|
| 高 | 需要创意、多种解决方案 | 提供指导原则,而非具体步骤 |
| 中 | 推荐模式但允许变通 | 提供参数化示例和默认流程 |
| 低 | 易出错、需要严格执行 | 提供详细的分步说明或脚本 |
判断标准:
- 是否有明确的「正确答案」?→ 低自由度
- 是否需要适应不同场景?→ 高自由度
- 错误的成本有多高?→ 成本高=低自由度
3. Progressive Disclosure
3. 渐进式披露
Organize complex content in layers:
SKILL.md (Main document, 200-500 lines)
├── reference.md (Detailed documentation)
├── examples.md (Complete examples)
└── scripts/ (Executable scripts)Rules:
- SKILL.md > 500 lines → Split into sub-files
- Sub-files > 100 lines → Add table of contents
- Reference depth ≤ 1 level
分层组织复杂内容:
SKILL.md (主文档,200-500行)
├── reference.md (详细文档)
├── examples.md (完整示例)
└── scripts/ (可执行脚本)规则:
- SKILL.md超过500行 → 拆分为子文件
- 子文件超过100行 → 添加目录
- 引用深度≤1级
File Structure Standards
文件结构标准
YAML Frontmatter
YAML前置元数据
yaml
---
name: skill-name-here
description: Clear description of what this skill does and when to activate it
---Field Specifications:
| Field | Requirements | Description |
|---|---|---|
| Lowercase letters, numbers, hyphens, ≤64 characters | Must match directory name |
| Plain text, ≤1024 characters | Used for retrieval and activation |
Naming Prohibitions:
- ❌ XML tags, reserved words (,
anthropic)claude - ❌ Vague terms (,
helper,utility)manager - ❌ Spaces or underscores (use hyphens )
-
Description Tips:
yaml
undefinedyaml
---
name: skill-name-here
description: Clear description of what this skill does and when to activate it
---字段规范:
| 字段 | 要求 | 说明 |
|---|---|---|
| 小写字母、数字、连字符,≤64字符 | 必须与目录名称匹配 |
| 纯文本,≤1024字符 | 用于检索和激活 |
命名禁忌:
- ❌ XML标签、保留词(、
anthropic)claude - ❌ 模糊术语(、
helper、utility)manager - ❌ 空格或下划线(使用连字符)
-
描述技巧:
yaml
undefined❌ Too Generic
❌ 过于笼统
description: Helps with code tasks
description: 帮助处理代码任务
✅ Specific with Keywords
✅ 包含具体关键词
description: Processes CSV files and generates Excel reports with charts. Use when user asks to convert data formats or create visual reports.
description: 处理CSV文件并生成带图表的Excel报表。当用户要求转换数据格式或创建可视化报表时使用。
✅ States Trigger Scenarios
✅ 明确触发场景
description: Analyzes Python code for security vulnerabilities using bandit. Activates when user mentions "security audit" or "vulnerability scan".
undefineddescription: 使用bandit分析Python代码的安全漏洞。当用户提及"安全审计"或"漏洞扫描"时激活。
undefinedDirectory Organization
目录组织
Basic Structure (Simple Skill):
skill-name/
└── SKILL.mdStandard Structure (Recommended):
skill-name/
├── SKILL.md
├── templates/
│ └── template.md
└── scripts/
└── script.py基础结构(简单技能):
skill-name/
└── SKILL.md标准结构(推荐):
skill-name/
├── SKILL.md
├── templates/
│ └── template.md
└── scripts/
└── script.pyNaming and Description Standards
命名与描述标准
Skill Naming
技能命名
Recommended Format: Verb-ing + noun form
✅ Good Names:
- processing-csv-files
- generating-api-docs
- managing-database-migrations
❌ Bad Names:
- csv (too brief)
- data_processor (uses underscores)
- helper (too vague)推荐格式:动词-ing + 名词形式
✅ 好的名称:
- processing-csv-files
- generating-api-docs
- managing-database-migrations
❌ 不好的名称:
- csv(过于简短)
- data_processor(使用下划线)
- helper(过于模糊)Description Writing
描述编写
Must use third person:
yaml
undefined必须使用第三人称:
yaml
undefined❌ Wrong
❌ 错误
description: I help you process PDFs
description: 我帮你处理PDF
✅ Correct
✅ 正确
description: Processes PDF documents and extracts structured data
**4C Principles**:
- **Clear**: Avoid jargon and vague terms
- **Concise**: 1-2 sentences explaining core functionality
- **Contextual**: Describe applicable scenarios
- **Complete**: Functionality + trigger conditions
---description: 处理PDF文档并提取结构化数据
**4C原则**:
- **清晰(Clear)**: 避免行话和模糊术语
- **简洁(Concise)**: 1-2句话说明核心功能
- **上下文(Contextual)**: 描述适用场景
- **完整(Complete)**: 功能 + 触发条件
---Content Writing Guide
内容编写指南
"When to Use" Section
「何时使用」部分
Clearly state trigger scenarios:
markdown
undefined明确说明触发场景:
markdown
undefinedWhen to Use This Skill
何时使用此技能
- User asks to analyze Python code for type errors
- User mentions "mypy" or "type checking"
- User is working in a Python project with type hints
- User needs to add type annotations
**Patterns**:
- Direct request: "User asks to X"
- Keywords: "User mentions 'keyword'"
- Context: "User is working with X"
- Task type: "User needs to X"- 用户要求分析Python代码的类型错误
- 用户提及"mypy"或"类型检查"
- 用户正在使用带类型提示的Python项目
- 用户需要添加类型注解
**模式**:
- 直接请求:"用户要求X"
- 关键词:"用户提及'关键词'"
- 上下文:"用户正在使用X"
- 任务类型:"用户需要X"Workflow Design
工作流设计
Simple Linear Flow:
markdown
undefined简单线性流程:
markdown
undefinedHow It Works
工作原理
- Scan the project for all files
.py - Run on each file
mypy --strict - Parse error output and categorize by severity
- Generate summary report with fix suggestions
**Conditional Branching Flow**:
```markdown- 扫描项目中所有文件
.py - 对每个文件运行
mypy --strict - 解析错误输出并按严重程度分类
- 生成包含修复建议的汇总报告
**条件分支流程**:
```markdownWorkflow
工作流
-
Check project type
- If Django → Use config
django-stubs - If Flask → Use config
flask-stubs - Otherwise → Use default mypy config
- If Django → Use
-
Run type checking
- If errors found → Proceed to step 3
- If no errors → Report success and exit
**Checklist Pattern** (Validation tasks):
```markdown-
检查项目类型
- 如果是Django → 使用配置
django-stubs - 如果是Flask → 使用配置
flask-stubs - 否则 → 使用默认mypy配置
- 如果是Django → 使用
-
运行类型检查
- 如果发现错误 → 进入步骤3
- 如果没有错误 → 报告成功并退出
**检查清单模式**(验证任务):
```markdownPre-deployment Checklist
部署前检查清单
Execute in order. Stop if any step fails.
- Run tests: (must pass)
npm test - Build: (no errors)
npm run build - Check deps: (no critical vulnerabilities)
npm audit
undefined按顺序执行,若任何步骤失败则停止。
- 运行测试:(必须通过)
npm test - 构建:(无错误)
npm run build - 检查依赖:(无严重漏洞)
npm audit
undefinedExamples and Templates
示例与模板
Input-Output Examples:
markdown
undefined输入输出示例:
markdown
undefinedExamples
示例
Example 1: Basic Check
示例1:基础检查
User Request: "Check my code for type errors"
Action:
- Scan for files
.py - Run on all files
mypy
Output:
Found 3 type errors in 2 files:
src/main.py:15: error: Missing return type
src/utils.py:42: error: Incompatible types
undefined用户请求:"检查我的代码是否有类型错误"
操作:
- 扫描文件
.py - 对所有文件运行
mypy
输出:
在2个文件中发现3个类型错误:
src/main.py:15: error: Missing return type
src/utils.py:42: error: Incompatible types
undefinedScript Integration
脚本集成
When to Use Scripts:
- Simple commands → Describe directly in SKILL.md
- Complex processes → Provide standalone scripts
Script Writing Standards:
python
#!/usr/bin/env python3
"""
Brief description of what this script does.
Usage:
python script.py <arg> [--option value]
"""
import argparse
DEFAULT_VALUE = 80 # Use constants, not magic numbers
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("directory", help="Directory to process")
parser.add_argument("--threshold", type=int, default=DEFAULT_VALUE)
args = parser.parse_args()
# Validate inputs
if not Path(args.directory).is_dir():
print(f"Error: {args.directory} not found")
return 1
# Execute
result = process(args.directory, args.threshold)
# Report
print(f"Processed {result['count']} files")
return 0
if __name__ == "__main__":
exit(main())Key Standards:
- ✅ Shebang line and docstring
- ✅ Type annotations and constants
- ✅ Parameter validation and error handling
- ✅ Clear return values (0=success, 1=failure)
何时使用脚本:
- 简单命令 → 直接在SKILL.md中描述
- 复杂流程 → 提供独立脚本
脚本编写标准:
python
#!/usr/bin/env python3
"""
Brief description of what this script does.
Usage:
python script.py <arg> [--option value]
"""
import argparse
DEFAULT_VALUE = 80 # 使用常量,而非魔法数字
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("directory", help="Directory to process")
parser.add_argument("--threshold", type=int, default=DEFAULT_VALUE)
args = parser.parse_args()
# 验证输入
if not Path(args.directory).is_dir():
print(f"Error: {args.directory} not found")
return 1
# 执行
result = process(args.directory, args.threshold)
# 报告
print(f"Processed {result['count']} files")
return 0
if __name__ == "__main__":
exit(main())核心标准:
- ✅ Shebang行和文档字符串
- ✅ 类型注解和常量
- ✅ 参数验证和错误处理
- ✅ 清晰的返回值(0=成功,1=失败)
Best Practices
最佳实践
Do:
- ✅ Provide executable commands and scripts
- ✅ Include input-output examples
- ✅ State validation criteria and success conditions
- ✅ Include Do/Don't lists
Don't:
- ❌ Include general knowledge Claude already knows
- ❌ Use abstract descriptions instead of concrete steps
- ❌ Omit error handling guidance
- ❌ Use pseudocode instead of real code in examples
建议:
- ✅ 提供可执行命令和脚本
- ✅ 包含输入输出示例
- ✅ 说明验证标准和成功条件
- ✅ 包含Do/Don't列表
禁忌:
- ❌ 包含Claude已有的通用知识
- ❌ 使用抽象描述而非具体步骤
- ❌ 省略错误处理指导
- ❌ 在示例中使用伪代码而非真实代码
Quality Checklist
质量检查清单
Core Quality
核心质量
- follows naming conventions (lowercase, hyphens, ≤64 characters)
name - includes trigger keywords and scenarios (≤1024 characters)
description - Name matches directory name
- Only includes information Claude doesn't know
- No redundant or duplicate content
- 符合命名规范(小写、连字符、≤64字符)
name - 包含触发关键词和场景(≤1024字符)
description - 名称与目录名称匹配
- 仅包含Claude不知道的信息
- 无冗余或重复内容
Functional Completeness
功能完整性
- Has "When to Use" section with 3-5 trigger scenarios
- Has clear execution flow or steps
- At least 2-3 complete examples
- Includes input and expected output
- Error handling guidance provided
- 包含「何时使用」部分,有3-5个触发场景
- 有清晰的执行流程或步骤
- 至少2-3个完整示例
- 包含输入和预期输出
- 提供错误处理指导
Structure Standards
结构标准
- Clear section organization
- Table of contents for >200 lines
- Reference nesting ≤ 1 level
- All paths use forward slashes
/ - Consistent terminology
- 章节组织清晰
- 超过200行添加目录
- 引用嵌套≤1级
- 所有路径使用正斜杠
/ - 术语一致
Scripts and Templates
脚本与模板
- Scripts include usage instructions and parameter documentation
- Scripts have error handling
- Avoid magic numbers, use configuration
- Template format is clear and usable
- 脚本包含使用说明和参数文档
- 脚本有错误处理
- 避免魔法数字,使用配置
- 模板格式清晰可用
Final Check
最终检查
- Read through for fluency and readability
- Test triggering with actual scenarios
- Appropriate length (200-500 lines, or split)
- 通读确保流畅易读
- 使用实际场景测试触发
- 长度合适(200-500行,或拆分)
FAQ
常见问题
Q: How long should a Skill be?
- Minimum: 50-100 lines
- Ideal: 200-500 lines
- Maximum: 500 lines (split if exceeded)
Q: How to make Skills easier to activate?
- Use keywords in that users would say
description - State specific scenarios ("when user asks to X")
- Mention related tool names
Q: What if multiple Skills overlap?
- Use more specific to differentiate
description - Explain relationships in "When to Use"
- Consider merging into one Skill
Q: Do Skills need maintenance?
- Review quarterly, update outdated information
- Iterate based on usage feedback
- Update promptly when tools or APIs change
Q: 技能应该多长?
- 最短:50-100行
- 理想:200-500行
- 最长:500行(超过则拆分)
Q: 如何让技能更容易激活?
- 在中使用用户会说的关键词
description - 明确具体场景("当用户要求X时")
- 提及相关工具名称
Q: 如果多个技能重叠怎么办?
- 使用更具体的区分
description - 在「何时使用」中说明关系
- 考虑合并为一个技能
Q: 技能需要维护吗?
- 每季度回顾,更新过时信息
- 根据使用反馈迭代
- 工具或API变更时及时更新
Quick Reference
快速参考
Frontmatter Template
前置元数据模板
yaml
---
name: skill-name
description: Brief description with trigger keywords
---yaml
---
name: skill-name
description: 包含触发关键词的简短描述
---Basic Structure Template
基础结构模板
markdown
undefinedmarkdown
undefinedSkill Title
技能标题
When to Use This Skill
何时使用此技能
- Scenario 1
- Scenario 2
- 场景1
- 场景2
How It Works
工作原理
- Step 1
- Step 2
- 步骤1
- 步骤2
Examples
示例
Example 1
示例1
...
...
References
参考
- Link
---- 链接
---Related Resources
相关资源
- Claude Agent Skills Official Documentation
- Best Practices Checklist
- Template Files - Ready-to-use templates
- Basic skill template
- Workflow skill template
- Example Library - Complete Skill examples
- Good examples
- Common mistakes
- Claude Agent Skills 官方文档
- 最佳实践检查清单
- 模板文件 - 即用型模板
- 基础技能模板
- 工作流技能模板
- 示例库 - 完整技能示例
- 优秀示例
- 常见错误