代理技能

NEW

通过Claude自动应用的基于Markdown的自定义技能扩展Claude的功能

什么是代理技能?

技能是一个Markdown文件,用于教Claude如何执行特定任务。技能是模型调用的:Claude根据您的请求决定使用哪些技能。当您提出与技能描述匹配的问题时,Claude会自动应用该技能。

自动激活

Claude检测到技能相关时会自动应用

基于Markdown

包含YAML前置元数据和指令的简单SKILL.md文件

热重载

技能在创建或修改时会自动加载

技能存放位置

位置路径适用于
EnterpriseManaged SettingsAll users in organization
Personal~/.claude/skills/You, across all projects
Project.claude/skills/Anyone in this repository
Pluginskills/ in pluginAnyone with plugin installed

优先级顺序:Enterprise > Personal > Project > Plugin(名称冲突时较高优先)

SKILL.md 结构

简单技能

---
name: explaining-code
description: Explains code with visual diagrams and analogies. Use when explaining how code works.
---

When explaining code, always include:

1. **Start with an analogy**: Compare the code to something from everyday life
2. **Draw a diagram**: Use ASCII art to show the flow
3. **Walk through the code**: Explain step-by-step what happens
4. **Highlight a gotcha**: What's a common mistake?

高级技能

---
name: pdf-processing
description: Extract text, fill forms, merge PDFs. Use when working with PDF files.
allowed-tools: Read, Bash(python:*)
model: claude-opus-4-5-20251101
context: fork
---

# PDF Processing

## Quick start
Extract text:
```python
import pdfplumber
with pdfplumber.open("doc.pdf") as pdf:
    text = pdf.pages[0].extract_text()
```

For form filling, see [FORMS.md](FORMS.md).

可用的元数据字段

FieldRequiredDescription
nameYesLowercase letters, numbers, hyphens (max 64 chars)
descriptionYesWhat it does and when to use (max 1024 chars)
allowed-toolsNoRestrict tools Claude can use (e.g., Read, Grep, Bash)
modelNoOverride model (e.g., claude-opus-4-5-20251101)
contextNoSet to "fork" for isolated sub-agent context
agentNoAgent type when context: fork (Explore, Plan, etc.)
hooksNoDefine PreToolUse, PostToolUse, Stop handlers
user-invocableNoShow in slash menu (default: true)

带钩子的技能

技能可以定义在技能生命周期期间运行的钩子。钩子的作用域限定于技能,并在技能完成时自动清理。

示例:安全检查钩子

---
name: secure-operations
description: Perform operations with additional security checks
hooks:
  PreToolUse:
    - matcher: "Bash"
      hooks:
        - type: command
          command: "./scripts/security-check.sh $TOOL_INPUT"
          once: true
---

Security-first operations with automatic validation.

技能 vs 其他选项

Use ThisWhen You Want To...When It Runs
SkillsGive Claude specialized knowledgeClaude chooses when relevant
Slash CommandsCreate reusable promptsYou type /command
CLAUDE.mdSet project-wide instructionsLoaded every conversation
SubagentsDelegate to separate contextClaude delegates or explicit
HooksRun scripts on eventsOn specific tool events
MCP ServersConnect to external toolsClaude calls as needed

多文件技能(渐进式披露)

对于复杂的技能,请使用渐进式披露:将基本信息放在SKILL.md中,详细文档放在单独的文件中,Claude只在需要时才读取。

pdf-processing/
├── SKILL.md # Overview and navigation
├── FORMS.md # Loaded when needed
├── REFERENCE.md # Loaded when needed
└── scripts/
├── fill_form.py # Executed, not loaded
└── validate.py

Tip: 保持SKILL.md在500行以内。脚本可以执行而无需加载到上下文中。

测试您的技能

查看可用技能

What Skills are available?

测试技能

提出与技能描述匹配的问题:

How does this code work?

开始构建技能

创建您的第一个技能,用您团队的标准和工作流程扩展Claude的功能。

阅读完整文档