跳转到正文
全部文章
TUTORIAL·October 25, 2026·阅读约 5 分钟

如何编写一个能在Claude Code及其他平台运行的代理技能

作者:VCA Newsroom

本文为自动翻译,可能包含错误。 查看英文原文

智能体技能是教 AI 编码智能体执行可重复流程的最简单方法,例如团队如何编写变更日志、运行版本发布或审查迁移。技能就是一个包含 SKILL.md 文件的文件夹。现在,Anthropic 已将该标准捐赠给了 Linux 基金会的智能体 AI 基金会 (https://www.anthropic.com/news/donating-agent-skills-to-the-agentic-ai-foundation),并且根据 Anthropic 的说法,已有超过 70 个平台支持该标准,因此学习编写既可移植又实用的技能非常值得。

本指南将使用官方的智能体技能规范 (https://agentskills.io/specification) 和 Claude Code 技能文档 (https://code.claude.com/docs/en/skills),逐步完成技能的构建。

步骤 1:在正确的位置创建文件夹

技能是一个目录,其名称与技能名称匹配,并且至少包含一个 SKILL.md 文件:

changelog-entry/
├── SKILL.md          # required: metadata + instructions
├── scripts/          # optional: executable code
├── references/       # optional: extra docs the agent reads on demand
└── assets/           # optional: templates, schemas, data files

在 Claude Code 中,将其放在以下两个位置之一:

  • 项目技能: .claude/skills/changelog-entry/SKILL.md。提交后,你的整个团队都会收到通知。

  • 个人技能: ~/.claude/skills/changelog-entry/SKILL.md,可在该机器上的所有项目中使用。

步骤 2:确保名称正确

name 的规范非常严格:

  • 1-64 个字符

  • 仅限小写字母、数字和连字符

  • 不允许有前导或尾随连字符,也不允许双连字符(--)

  • 必须与父目录名称匹配

因此,changelog-entry 是有效的,而 Changelog-Entry、-changelog 和 changelog--entry 则无效。Claude Code 在这方面比较宽容,因为如果您省略目录名称,name 会默认使用目录名称。其他工具可能并非如此,因此请显式设置目录名称,并确保其与文件夹名称完全一致。

步骤 3:编写触发描述

description 字段是文件中最重要的一行。代理在启动时仅加载每个技能的 name 和 description,每个技能大约 100 个标记(根据规范)。它们仅根据这些文本来决定是否激活技能。规范允许最多 1024 个字符,并要求你使用具体的关键词来描述技能的功能和使用时机。

比较:

# Poor: too vague to match anything
description: Helps with changelogs.

# Good: says what it does, when to use it, and includes trigger words
description: Writes a CHANGELOG.md entry for the current change in Keep a Changelog format, dated YYYY-MM-DD with the commit SHA. Use when the user asks to log, record or document a change, release or fix.

步骤 4:编写说明

以下是一个完整的最小技能示例:

---
name: changelog-entry
description: Writes a CHANGELOG.md entry for the current change in Keep a Changelog format, dated YYYY-MM-DD with the commit SHA. Use when the user asks to log, record or document a change, release or fix.
---

# Changelog entry

1. Read the staged diff (`git diff --staged`) to understand the change.
2. Open CHANGELOG.md. Create it with a `# Changelog` heading if it is missing.
3. Add the entry under today's date (YYYY-MM-DD) in one of these sections:
   Added, Changed, Fixed, Removed.
4. Write one line per change: what changed and why, not how.
5. Append the short commit SHA in parentheses once the commit exists.

## Example
- Fixed: checkout total ignored discount codes on renewals (a1b2c3d)

## Edge cases
- Docs-only change: use "Changed" and say "docs".
- Several unrelated changes: write one line per change, never one merged line.

正文没有格式规则。规范建议使用分步说明、输入/输出示例和特殊情况,以上就是这种格式。

步骤 5:对任何较长的内容使用渐进式披露

根据规范,代理分三个层级加载技能:

  1. 元数据(名称和描述)在启动时加载所有技能。

  2. 说明(完整的 SKILL.md 正文)在技能激活时加载。将它们控制在 5000 个标记以内,500 行以内。

  3. 资源(scripts/、references/、assets/)仅在任务需要时加载。

如果您的样式指南篇幅过长,请勿将其粘贴到 SKILL.md 中。请将其移动到 references/STYLE.md 并使用相对路径 See [the style guide](references/STYLE.md) 进行链接。保持引用层级为一层,因为指向其他文件的嵌套文件链会使代理难以跟踪。

第 6 步:确定其可移植性

该规范定义了一个小型核心:name 和 description 是必需的,而 license、compatibility、metadata 和实验性的 allowed-tools 是可选的。Claude Code 在此基础上添加了自己的扩展。一些有用的扩展包括:

  • disable-model-invocation: true:只有您可以运行它(通过 /changelog-entry),Claude 不会自动加载它。这非常适合任何具有副作用的操作,例如部署。

  • argument-hint 和 $ARGUMENTS:传递参数,如 /deploy staging 所示。

  • paths:将自动激活限制为匹配的文件。

Claude Code 会静默忽略它无法识别的字段,但其他代理不保证会遵循 Claude 特有的字段。经验法则:将基本行为放在正文中,并将扩展字段视为锦上添花的功能。 如果某个技能需要特定的工具或软件包,请在 compatibility 中说明,例如 Requires git and jq。

第 7 步:验证和测试

规范中包含一个引用验证器:

skills-ref validate ./changelog-entry

它会检查 frontmatter 和命名规则。然后测试实际触发情况。在 Claude Code 中,使用简单的语言提出请求,例如“将此修复记录到变更日志中”,并确认技能无需您命名即可加载。如果未触发,解决方法几乎总是修改描述,因此请添加用户实际使用的文字。您也可以直接使用 /changelog-entry 运行它。

关于信任的说明

技能可以捆绑脚本,因此安装他人的技能意味着您的代理可能会运行他们的代码。在添加第三方技能之前,请阅读 SKILL.md 和 scripts/ 中的所有内容。技能作者和用户的安全指南是该标准在新管理框架下提出的首要任务之一。

本周编写一个技能,用于您反复向代理解释的任务。这是最快看到您的指令开始累积的方法。

Auto-generated by Vibe Coding Academy on 2026年10月25日, grounded in the real sources linked above. We review for accuracy, but please verify time-sensitive details against the primary sources.

SECOND OPINION · BY VIBE CODING ACADEMY

Your agent says it’s done. What needs checking?

Paste your coding-agent conversation for supported claims, visible problems, and useful next steps. Reviews only the material you provide; no account needed to start.

Review a session