代理技能
NEW通过Claude自动应用的基于Markdown的自定义技能扩展Claude的功能
什么是代理技能?
技能是一个Markdown文件,用于教Claude如何执行特定任务。技能是模型调用的:Claude根据您的请求决定使用哪些技能。当您提出与技能描述匹配的问题时,Claude会自动应用该技能。
自动激活
Claude检测到技能相关时会自动应用
基于Markdown
包含YAML前置元数据和指令的简单SKILL.md文件
热重载
技能在创建或修改时会自动加载
技能存放位置
| 位置 | 路径 | 适用于 |
|---|---|---|
| Enterprise | Managed Settings | All users in organization |
| Personal | ~/.claude/skills/ | You, across all projects |
| Project | .claude/skills/ | Anyone in this repository |
| Plugin | skills/ in plugin | Anyone 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).可用的元数据字段
| Field | Required | Description |
|---|---|---|
| name | Yes | Lowercase letters, numbers, hyphens (max 64 chars) |
| description | Yes | What it does and when to use (max 1024 chars) |
| allowed-tools | No | Restrict tools Claude can use (e.g., Read, Grep, Bash) |
| model | No | Override model (e.g., claude-opus-4-5-20251101) |
| context | No | Set to "fork" for isolated sub-agent context |
| agent | No | Agent type when context: fork (Explore, Plan, etc.) |
| hooks | No | Define PreToolUse, PostToolUse, Stop handlers |
| user-invocable | No | Show 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 This | When You Want To... | When It Runs |
|---|---|---|
| Skills | Give Claude specialized knowledge | Claude chooses when relevant |
| Slash Commands | Create reusable prompts | You type /command |
| CLAUDE.md | Set project-wide instructions | Loaded every conversation |
| Subagents | Delegate to separate context | Claude delegates or explicit |
| Hooks | Run scripts on events | On specific tool events |
| MCP Servers | Connect to external tools | Claude 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?