skills-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSkills Best Practices
Skills最佳实践
Comprehensive reference for building Agent Skills that follow Anthropic's official guidelines. Skills are folders containing instructions, scripts, and resources that teach Claude how to handle specific tasks. They follow the Agent Skills open standard.
本指南是遵循Anthropic官方规范构建Agent Skills的综合参考资料。Skills是包含指令、脚本和资源的文件夹,用于指导Claude处理特定任务。它们遵循Agent Skills开放标准。
Quick Start
快速开始
A minimal skill is a directory with a file:
SKILL.mdmy-skill/
├── SKILL.md # Required - instructions with YAML frontmatter
├── references/ # Optional - detailed docs loaded on demand
├── scripts/ # Optional - executable code
└── assets/ # Optional - templates, fonts, iconsMinimal :
SKILL.mdyaml
---
name: my-skill-name
description: What it does. Use when [specific triggers].
---一个最简技能是包含文件的目录:
SKILL.mdmy-skill/
├── SKILL.md # 必填项 - 带有YAML前置元数据的指令文件
├── references/ # 可选 - 按需加载的详细文档
├── scripts/ # 可选 - 可执行代码
└── assets/ # 可选 - 模板、字体、图标最简示例:
SKILL.mdyaml
---
name: my-skill-name
description: What it does. Use when [specific triggers].
---My Skill Name
My Skill Name
[Instructions here]
Only `name` and `description` are required in frontmatter.[Instructions here]
前置元数据中仅`name`和`description`为必填项。Core Design Principles
核心设计原则
Progressive Disclosure (Most Important)
渐进式披露(最重要)
Skills load information in three levels to minimize token usage:
| Level | When Loaded | Token Cost | Content |
|---|---|---|---|
| 1: Metadata | Always (startup) | ~100 tokens | |
| 2: Instructions | When skill triggers | <5k tokens (recommended) | SKILL.md body |
| 3: Resources | As needed | Effectively unlimited | Bundled files, scripts |
Keep SKILL.md under 500 lines. Move detailed docs to separate files and reference them:
markdown
undefinedSkills通过三个层级加载信息,以最小化令牌消耗:
| 层级 | 加载时机 | 令牌成本 | 内容 |
|---|---|---|---|
| 1: 元数据 | 始终加载(启动时) | ~100令牌 | 前置元数据中的 |
| 2: 指令 | 技能触发时 | <5k令牌(推荐) | SKILL.md正文内容 |
| 3: 资源 | 按需加载 | 几乎无限制 | 捆绑文件、脚本 |
请将SKILL.md控制在500行以内。将详细文档移至单独文件并通过引用链接:
markdown
undefinedAdvanced features
高级功能
- Form filling: See FORMS.md
- API reference: See reference.md
Claude reads referenced files only when the task requires them.- 表单填充: 参考FORMS.md
- API参考: 参考reference.md
Claude仅在任务需要时才会读取引用文件。Composability
可组合性
Skills work alongside other skills. Don't assume yours is the only one loaded.
Skills可与其他技能协同工作,不要假设你的技能是唯一加载的技能。
Portability
可移植性
Skills work across Claude.ai, Claude Code, API, and Agent SDK without modification (if dependencies are available).
Skills无需修改即可在Claude.ai、Claude Code、API和Agent SDK上运行(前提是依赖项可用)。
Writing the Description (Critical)
描述撰写(关键)
The description is the single most important field - it determines when your skill activates. Claude uses it to decide relevance from potentially 100+ available skills.
描述是最重要的字段——它决定了你的技能何时激活。Claude会根据描述从100+可用技能中判断相关性。
Rules
规则
- Write in third person ("Processes files..." not "I help you process files...")
- Include WHAT it does + WHEN to use it
- Max 1024 characters, no XML angle brackets
- Be slightly "pushy" - Claude tends to undertrigger rather than overtrigger
- Include specific trigger phrases users would naturally say
- 使用第三人称撰写(例如“处理文件...”而非“我帮你处理文件...”)
- 包含功能 + 使用场景
- 最多1024字符,不包含XML尖括号
- 语气可稍“主动”——Claude倾向于触发不足而非过度触发
- 包含用户自然会使用的特定触发短语
Good vs Bad
正反示例
yaml
undefinedyaml
undefinedGOOD - specific, actionable, includes triggers
良好示例 - 具体、可操作、包含触发词
description: Extract text and tables from PDF files, fill forms, merge
documents. Use when working with PDF files or when the user mentions
PDFs, forms, or document extraction.
description: Extract text and tables from PDF files, fill forms, merge
documents. Use when working with PDF files or when the user mentions
PDFs, forms, or document extraction.
BAD - too vague
不良示例 - 过于模糊
description: Helps with documents.
description: Helps with documents.
BAD - missing triggers
不良示例 - 缺少触发场景
description: Creates sophisticated multi-page documentation systems.
More examples in [references/description-guide.md](references/description-guide.md).description: Creates sophisticated multi-page documentation systems.
更多示例请参考[references/description-guide.md](references/description-guide.md)。Frontmatter Reference
前置元数据参考
Required Fields
必填字段
| Field | Rules |
|---|---|
| Kebab-case, max 64 chars, lowercase + numbers + hyphens only. No "claude" or "anthropic" |
| Non-empty, max 1024 chars, no XML tags. WHAT + WHEN |
The agentskills.io standard and the Claude API require both fields. Claude Code is more lenient: falls back to the directory name, and falls back to the first markdown paragraph. Write both anyway for portability.
namedescription| 字段 | 规则 |
|---|---|
| 使用kebab-case格式,最多64字符,仅包含小写字母、数字和连字符。不可使用“claude”或“anthropic” |
| 非空,最多1024字符,无XML标签。需包含功能+使用场景 |
agentskills.io标准和Claude API要求这两个字段。Claude Code的限制更宽松:会回退到目录名称,会回退到第一个markdown段落。但为了可移植性,建议同时填写这两个字段。
namedescriptionOptional Fields (Claude Code)
可选字段(Claude Code)
| Field | Purpose |
|---|---|
| Autocomplete hint, e.g. |
| Extra trigger context, appended to |
| Named positional arguments for |
| |
| |
| Pre-approves tools (no permission prompt); space-separated, e.g. |
| Override model for this skill; accepts |
| Override effort level: |
| |
| Subagent type when |
| Hooks scoped to this skill's lifecycle |
| Glob patterns limiting when skill activates |
| 字段 | 用途 |
|---|---|
| 自动补全提示,例如 |
| 额外触发上下文,会附加到技能列表中的 |
| 用于 |
| |
| |
| 预批准工具(无需权限提示);空格分隔,例如 |
| 覆盖此技能使用的模型;接受 |
| 覆盖努力级别: |
| |
| 当 |
| 作用于此技能生命周期的钩子 |
| 限制技能激活的Glob模式 |
Naming Conventions
命名规范
The (and its folder) must: be 1-64 chars; use only lowercase letters, numbers, and hyphens; not start or end with a hyphen; not contain consecutive hyphens (); and match the parent directory name. Anthropic surfaces also reject the reserved words and .
name--claudeanthropicPrefer gerund form for clarity:
- ,
processing-pdfs,analyzing-spreadsheetsmanaging-databases - Also acceptable: ,
pdf-processingprocess-pdfs - Avoid: ,
helper,utils,toolsdocuments
name--claudeanthropic优先使用动名词形式以确保清晰:
- ,
processing-pdfs,analyzing-spreadsheetsmanaging-databases - 也可接受:,
pdf-processingprocess-pdfs - 避免使用:,
helper,utils,toolsdocuments
Structuring Instructions
指令结构
Be Concise
简洁性
Claude is smart. Only add context it doesn't already have:
markdown
undefinedClaude很智能,只需添加它不具备的上下文信息:
markdown
undefinedGOOD (~50 tokens)
良好示例(约50令牌)
Extract PDF text
提取PDF文本
Use pdfplumber for text extraction:
python
import pdfplumber
with pdfplumber.open("file.pdf") as pdf:
text = pdf.pages[0].extract_text()使用pdfplumber进行文本提取:
python
import pdfplumber
with pdfplumber.open("file.pdf") as pdf:
text = pdf.pages[0].extract_text()BAD (~150 tokens)
不良示例(约150令牌)
Extract PDF text
提取PDF文本
PDF files are a common file format containing text and images.
To extract text, you need a library. There are many available...
undefinedPDF是包含文本和图像的常见文件格式。
要提取文本,你需要一个库。有很多可用的库...
undefinedAvoid Too Many Options
避免过多选项
Don't present multiple approaches unless necessary. Give one default with an escape hatch:
markdown
undefined除非必要,否则不要提供多种方法。给出一个默认方案并提供备选方案:
markdown
undefinedBAD: "Use pypdf, or pdfplumber, or PyMuPDF, or pdf2image..."
不良示例:"使用pypdf,或pdfplumber,或PyMuPDF,或pdf2image..."
GOOD: "Use pdfplumber for text extraction. For scanned PDFs needing
良好示例:"使用pdfplumber进行文本提取。对于需要OCR的扫描版PDF,改用pdf2image搭配pytesseract。"
OCR, use pdf2image with pytesseract instead."
—
undefinedundefinedSet Degrees of Freedom
设置自由度
- High freedom (text guidelines): Multiple approaches valid, context-dependent
- Medium freedom (pseudocode/templates): Preferred pattern exists, some variation OK
- Low freedom (exact scripts): Operations are fragile, consistency critical
- 高自由度(文本指南):多种方法均有效,取决于上下文
- 中等自由度(伪代码/模板):存在首选模式,允许一定变化
- 低自由度(精确脚本):操作易受影响,一致性至关重要
Recommended SKILL.md Structure
推荐的SKILL.md结构
markdown
undefinedmarkdown
undefinedSkill Name
技能名称
Quick start
快速开始
[Minimal working example]
[最简工作示例]
Workflow Decision Tree
工作流决策树
[Route to the right approach based on task type]
[根据任务类型选择合适的方法]
Detailed Instructions
详细指令
[Step-by-step for each workflow]
[每个工作流的分步说明]
Examples
示例
[Concrete input/output pairs]
[具体的输入/输出对]
Troubleshooting
故障排除
[Common errors and fixes]
undefined[常见错误及修复方法]
undefinedReference Files
参考文件
Keep references one level deep from SKILL.md. "Depth" means the reference chain (a file linking to a file linking to a file), not filesystem nesting - a subdirectory is fine. In a chain, Claude may preview files with partial reads () and miss content.
references/headmarkdown
undefined请将参考文件保持在SKILL.md的一级深度。“深度”指的是引用链(文件链接到文件再链接到文件),而非文件系统嵌套——子目录是允许的。在多级引用链中,Claude可能会部分读取文件()并遗漏内容。
references/headmarkdown
undefinedBAD: Too deep
不良示例:层级过深
SKILL.md -> advanced.md -> details.md -> actual info
SKILL.md -> advanced.md -> details.md -> 实际信息
GOOD: One level
良好示例:一级深度
SKILL.md -> advanced.md (contains the info directly)
SKILL.md -> reference.md (contains the info directly)
For reference files >100 lines, include a **table of contents** at the top. Watch file *size* too: a single reference of many hundreds of lines defeats progressive disclosure even at one level deep, because Claude loads the whole file for any subtopic. Split large references by subtopic so each task pulls only what it needs.SKILL.md -> advanced.md(直接包含信息)
SKILL.md -> reference.md(直接包含信息)
对于超过100行的参考文件,请在顶部添加**目录**。同时注意文件大小:即使是一级深度,数百行的参考文件也会违背渐进式披露的原则,因为Claude会为任何子主题加载整个文件。请按子主题拆分大型参考文件,以便每个任务仅获取所需内容。Patterns
模式
Sequential Workflow
顺序工作流
markdown
undefinedmarkdown
undefinedStep 1: Analyze input
步骤1:分析输入
Run:
python scripts/analyze.py input.pdf运行:
python scripts/analyze.py input.pdfStep 2: Validate
步骤2:验证
Run:
Fix any errors before continuing.
python scripts/validate.py fields.json运行:
修复所有错误后再继续。
python scripts/validate.py fields.jsonStep 3: Execute
步骤3:执行
Run:
python scripts/process.py input.pdf fields.json output.pdfundefined运行:
python scripts/process.py input.pdf fields.json output.pdfundefinedConditional Workflow (Decision Tree)
条件工作流(决策树)
markdown
undefinedmarkdown
undefinedWorkflow Decision Tree
工作流决策树
Creating new content? -> Follow "Creation workflow"
Editing existing content? -> Follow "Editing workflow"
Reviewing content? -> Follow "Review workflow"
undefined创建新内容? -> 遵循“创建工作流”
编辑现有内容? -> 遵循“编辑工作流”
审核内容? -> 遵循“审核工作流”
undefinedFeedback Loop
反馈循环
markdown
1. Make edits
2. Validate: `python scripts/validate.py`
3. If validation fails -> fix issues -> go to step 2
4. Only proceed when validation passesmarkdown
1. 进行编辑
2. 验证:`python scripts/validate.py`
3. 如果验证失败 -> 修复问题 -> 返回步骤2
4. 仅在验证通过后继续Checklist Pattern (for complex tasks)
清单模式(适用于复杂任务)
markdown
Copy this checklist and track progress:
- [ ] Step 1: Analyze input
- [ ] Step 2: Create plan
- [ ] Step 3: Validate plan
- [ ] Step 4: Execute
- [ ] Step 5: Verify outputMore patterns in references/patterns.md.
markdown
复制此清单并跟踪进度:
- [ ] 步骤1:分析输入
- [ ] 步骤2:制定计划
- [ ] 步骤3:验证计划
- [ ] 步骤4:执行
- [ ] 步骤5:验证输出更多模式请参考references/patterns.md。
Scripts
脚本
When your skill includes executable code:
- Solve, don't punt: Handle errors explicitly instead of letting them fail
- Justify constants: No magic numbers - document why each value was chosen
- Prefer execution over loading: Scripts run without entering context; only output consumes tokens
- Clarify intent: "Run " (execute) vs "See
analyze.py" (read as reference)analyze.py - List dependencies in SKILL.md and verify availability
当技能包含可执行代码时:
- 解决问题,而非回避:显式处理错误,而非让其失败
- 解释常量:避免魔法数字——记录每个值的选择原因
- 优先执行而非加载:脚本运行时不会进入上下文;仅输出会消耗令牌
- 明确意图:“Run ”(执行) vs “See
analyze.py”(作为参考读取)analyze.py - 在SKILL.md中列出依赖项并验证其可用性
Testing
测试
Build Evaluations First
先构建评估用例
Create evaluations before writing extensive instructions - this proves the skill solves a real problem. Run Claude on representative tasks without the skill and document the failures; build ~3 scenarios that test those gaps; measure a baseline; then write the minimum instructions needed to pass. Iterate against the baseline.
在编写详细指令之前创建评估用例——这能证明技能解决了实际问题。在不使用技能的情况下让Claude处理代表性任务并记录失败情况;构建约3个测试这些短板的场景;测量基准;然后编写通过测试所需的最少指令。根据基准迭代优化。
Triggering Tests
触发测试
Should trigger:
- "Help me set up a new project in [Service]"
- "I need to create a project" (paraphrased)
Should NOT trigger:
- "What's the weather?" (unrelated)
- "Write Python code" (too generic)应触发:
- "Help me set up a new project in [Service]"
- "I need to create a project"(改写后的表述)
不应触发:
- "What's the weather?"(无关内容)
- "Write Python code"(过于通用)Functional Tests
功能测试
Test normal operations, edge cases, and out-of-scope requests. Run the same request 3-5 times to check consistency.
测试正常操作、边缘情况和超出范围的请求。同一请求运行3-5次以检查一致性。
Debug Triggering
调试触发问题
Ask Claude: "When would you use the [skill-name] skill?" - it quotes the description back. Adjust based on what's missing.
询问Claude:“When would you use the [skill-name] skill?”——它会返回描述内容。根据缺失的信息进行调整。
Troubleshooting
故障排除
| Symptom | Cause | Fix |
|---|---|---|
| Skill never loads | Description too vague | Add specific triggers and key terms |
| Skill loads for wrong tasks | Description too broad | Add negative triggers, be more specific |
| Instructions not followed | Too verbose or buried | Put critical instructions at top, use headers |
| Slow/degraded responses | SKILL.md too large | Move content to references/, keep under 500 lines |
| "Could not find SKILL.md" | Wrong filename | Must be exactly |
| "Invalid skill name" | Spaces or capitals | Use kebab-case: |
| 症状 | 原因 | 修复方法 |
|---|---|---|
| 技能从未加载 | 描述过于模糊 | 添加特定触发词和关键术语 |
| 技能在错误任务中加载 | 描述过于宽泛 | 添加否定触发词,表述更具体 |
| 未遵循指令 | 指令过于冗长或被隐藏 | 将关键指令放在顶部,使用标题 |
| 响应缓慢/性能下降 | SKILL.md过大 | 将内容移至references/,保持在500行以内 |
| "Could not find SKILL.md" | 文件名错误 | 必须严格为 |
| "Invalid skill name" | 包含空格或大写字母 | 使用kebab-case格式: |
Distribution
分发
| Surface | How to Deploy |
|---|---|
| Claude.ai | Settings > Features > Upload zip |
| Claude Code (personal) | |
| Claude Code (project) | |
| Claude Code (plugin) | |
| API | Upload via the Skill Management API, use via the Messages API |
| Enterprise | Managed settings (org-wide) |
Skills don't sync across surfaces - deploy separately to each.
| 平台 | 部署方式 |
|---|---|
| Claude.ai | 设置 > 功能 > 上传zip包 |
| Claude Code(个人) | |
| Claude Code(项目) | |
| Claude Code(插件) | |
| API | 通过Skill Management API上传,通过Messages API使用 |
| 企业版 | 管理设置(全组织范围) |
Skills不会在各平台间同步——需单独部署到每个平台。
Using Skills with the API
通过API使用Skills
Custom skills are uploaded through the Skill Management API; -type skills are pre-built by Anthropic. Both are used identically - pass them in the Messages API parameter, each as where is or . Up to 8 Skills per request. Requires the code execution tool and the beta headers and (plus for file upload/download). The API code execution environment has no network access and no runtime package installation - bundle dependencies or use pre-installed packages.
anthropiccontainer{type, skill_id, version}typeanthropiccustomcode-execution-2025-08-25skills-2025-10-02files-api-2025-04-14自定义技能通过Skill Management API上传;类型的技能由Anthropic预构建。两者的使用方式相同——在Messages API的参数中传递,格式为,其中为或。每个请求最多可使用8个Skills。需要代码执行工具和Beta头信息、(加上文件上传/下载所需的)。API代码执行环境无网络访问权限且无法安装运行时包——请捆绑依赖项或使用预安装的包。
anthropiccontainer{type, skill_id, version}typeanthropiccustomcode-execution-2025-08-25skills-2025-10-02files-api-2025-04-14Security
安全
- Only use skills from trusted sources
- No XML angle brackets in frontmatter (injection risk)
- Audit all bundled scripts and resources before using third-party skills
- Be cautious of skills that fetch from external URLs
- 仅使用可信来源的Skills
- 前置元数据中不要包含XML尖括号(存在注入风险)
- 在使用第三方Skills前审核所有捆绑的脚本和资源
- 谨慎使用从外部URL获取内容的Skills
Additional References
额外参考
- Description writing guide - detailed examples and anti-patterns
- Patterns and workflows - advanced patterns with MCP, subagents, iterative refinement
- Claude Code features - context:fork, dynamic injection, argument substitution
- Quality checklist - pre-upload validation checklist
- ClawHub publishing - schema, moderation pipeline, reason codes catalog, pre-publish checklist
metadata.openclaw
- 描述撰写指南 - 详细示例和反模式
- 模式与工作流 - 包含MCP、子Agent、迭代优化的高级模式
- Claude Code功能 - context:fork、动态注入、参数替换
- 质量清单 - 上传前验证清单
- ClawHub发布指南 - schema、审核流程、原因代码目录、发布前清单
metadata.openclaw