返回播客Claude
Claude Code skills
从零构建你的第一个技能
So, let's create a skill.
来创建一个 skill。
This skill will teach Claude how we would like it to explain code using visual diagrams and analogies.
这个 skill 将教 Claude 如何用视觉图表和类比来解释代码。
[music]
[music]
Then, we'll look at what happens under the hood when Claude uses it.
接下来,看看 Claude 在使用它时内部发生了什么。
First, [music] let's create a directory for your skill.
首先,[music] 为你的 skill 创建一个目录。
We're going to be making a personal skill, so it'll live in many projects, so it will go in your home directory.
这是个人 skill,会用于多个项目,所以放在主目录下。
Take into consideration that we're creating a directory with the skill name inside of the skills directory.
注意,我们是在 skills 目录里创建以 skill 名称命名的子目录。
Now create the skill.
现在创建这个 skill。
The name identifies your skill.
name 字段标识你的 skill。
The description tells Claude when to use it.
其中的 description 字段告诉 Claude 何时使用该 skill。
This is the matching criteria.
这是匹配条件。
And then everything after the second dashes is the instructions that Claude follows.
第二个分隔线之后的所有内容,就是 Claude 遵循的指令。
Cloud code loads skills at startup.
启动时,Claude Code 会加载所有 skill。
So restart your session.
重启你的会话。
Then verify it's available.
然后验证它是否可用。
You should see PR description in the list.
你应该能在列表中看到 PR description。
Now test it.
现在测试它。
Make some changes on a branch and say, "Write a PR description for my changes."
在分支上做一些改动,然后说:「帮我写这些改动的 PR description。」
Claude will then show you that it's using the PR description skill.
随后,Claude 会提示它正在使用 PR description 这个 skill。
After that, it'll check your diff and write a description following your template.
之后,它会检查你的 diff,按你的模板写一份描述。
Same format every single time.
每次格式都一样。
When Cloud Code starts, it scans four locations for skills.
Claude Code 启动时,会扫描四个位置的 skill。
Enterprise paths, your personal Claude skills, the project's Claude skills, and installed plugins.
扫描范围包括:enterprise 授权路径、你本人的 Claude skill、当前项目的 Claude skill,还有已安装的 plugin。
It loads only the name and description of each skill, not the full content.
它只加载每个 skill 的名称和描述,不加载完整内容。
This is important later.
这一点后面很重要。
When you send a request, Claude compares it to the descriptions of your skills.
你发送请求时,Claude 会将其与 skill 的描述进行对比。
Explain what this function does matches a skill described as explain code with visual diagrams because the intent overlaps.
「解释这个函数的作用」能匹配描述为「用视觉图表解释代码」的 skill,因为意图相符。
It will then ask you to confirm loading up the skill.
随后会要求你确认是否加载该 skill。
This confirmation step keeps you aware of what context Claude is using.
这个确认步骤让你随时知道 Claude 在使用什么上下文。
After you confirm, Claude reads the complete file and follows its instructions.
确认后,Claude 读取完整文件并按其指令执行。
Now, let's say you clone a Git repository and have an overlapping skill name.
假设你克隆了一个 Git 仓库,里面有同名的 skill。
Well, which one wins?
哪个优先?
Here's the priority list.
这是优先级列表。
The highest is enterprise, which lives in the manage settings.
最高是 enterprise,存放在管理设置中。
Two is the personal, which lives in your root directory configuration like we're doing right now.
第二是 personal,存放在根目录配置中,就是我们现在做的。
Three is the project which is the claw directory inside of your repository.
第三是 project,即仓库内的 .claude 目录。
And the lowest is the plugins where you store your plugins that you got online.
最低是 plugins,存放你从网上获取的 plugin。
This lets organizations enforce standards while allowing individual customization through differently named skills.
这样组织可以统一标准,同时允许通过不同名称的 skill 进行个人定制。
If your company has an enterprise code review skill and you create a personal code review skill, the enterprise version of that takes precedence.
如果公司有 enterprise 代码审查 skill,而你也创建了个人代码审查 skill,enterprise 版本优先。
To avoid conflicts, use descriptive names.
避免冲突,请使用描述性名称。
Instead of review, use front-end PR review or security review.
避免用泛称,要用有区分度的名字,例如把 review 改成 front-end PR review,或者叫 security review。
To update a skill, edit it skill.md file.
要更新一个 skill,直接编辑对应的 skill.md 文件。
Simple.
就这样。
To remove one, delete its directory.
删除一个 skill,删除其目录即可。
Restart clock code after changes for them to take effect.
修改后重启 Claude Code 使其生效。
Creating a skill means making a directory with a skill.md file containing metadata and instructions.
创建 skill 就是创建一个包含 skill.md 文件的目录,文件中含元数据和指令。
Claude loads skill names and descriptions at startup.
Claude 在启动时加载 skill 的名称和描述。
matches incoming requests against those descriptions and asks for confirmation before loading the full content.
将传入的请求与这些描述进行匹配,并在加载完整内容前请求确认。
Priority rules handling name conflicts.
优先级规则处理命名冲突。
Enterprise overrides personal personal overrides project overrides plugins.
四个层级从高到低:enterprise,personal,project,plugins。每一层会覆盖比它低的层级。
[music]
[music]
Edit the skill.md file to update a skill and restart cloud code for changes to take effect.
编辑 skill.md 文件来更新 skill,重启 Claude Code 使改动生效。