Claude Code Skills 完全指南
掌握模块化能力扩展的核心机制
核心机制: 模型自主调用 | 配置方式: SKILL.md + 资源文件 | 应用场景: 专业领域知识、复杂工作流、团队协作
🎯 什么是 Claude Skills?
Claude Skills 是包含指令、脚本和资源的模块化能力包,让 Claude 能够在相关任务时自动识别并使用专业知识。
核心特性
正在加载图表...
Skills vs 其他机制
Skills 与其他功能的对比:
| 特性 | Skills | Slash Commands | Hooks | MCP Tools |
|---|---|---|---|---|
| 调用方式 | 模型自主 | 用户手动 | 事件触发 | 模型调用 |
| 适用场景 | 复杂工作流 | 快速操作 | 自动化检查 | 外部集成 |
| 配置复杂度 | 中等 | 低 | 中等 | 高 |
| 可移植性 | 跨平台 | Claude Code | Claude Code | 需服务器 |
| 执行时机 | 智能判断 | 立即执行 | 生命周期 | 按需调用 |
设计哲学: “Skills 用于打包专业知识和复杂流程,让 Claude 在需要时自动获得超能力”
🏗️ Claude Skills 系统架构
整体架构图
正在加载图表...
📁 Skill 存储位置
三种存储层级
正在加载图表...
目录结构示例
📝 SKILL.md 文件结构
完整格式说明
YAML Frontmatter 字段详解
1. name (必需)
格式要求:
- 只能包含小写字母、数字和连字符
- 最大长度 64 字符
- 使用动名词形式(gerund):
processing-pdfs,analyzing-data
示例:
name: code-review-helper
name: api-documentation-generator
name: database-schema-validator2. description (必需)
关键要求:
- 必须说明做什么 AND 何时使用
- 最大长度 1024 字符
- 使用第三人称: “Processes…” 而非 “I can process…”
- 包含具体触发场景
好的 description:
# ✅ 明确功能和触发条件
description: Analyzes Excel spreadsheets and generates pivot tables when the user asks to summarize or analyze tabular data from .xlsx files
# ✅ 指定使用场景
description: Reviews pull request code for security vulnerabilities and performance issues when analyzing Git diffs or reviewing code changes不好的 description:
# ❌ 过于笼统
description: Helps with data
# ❌ 没有触发条件
description: Processes Excel files
# ❌ 第一人称
description: I can help you analyze spreadsheets3. allowed-tools (可选)
用途: 限制 Skill 可以使用的工具,提高安全性
格式: 逗号分隔的工具列表
示例:
# 只读 Skill
allowed-tools: Read,Glob,Grep
# 代码分析 Skill
allowed-tools: Read,Bash(eslint *),Bash(prettier --check *)
# 完全访问(默认)
# 不指定 allowed-tools 字段工具名称:
Read- 读取文件Write- 写入文件Edit- 编辑文件Glob- 文件模式匹配Grep- 内容搜索Bash- Shell 命令Bash(command)- 特定命令
4. tags (可选)
用途: 分类和组织 Skills
示例:
tags:
- testing
- automation
- typescript🔄 Skills 工作流程
Skill 调用流程
正在加载图表...
渐进式披露机制
正在加载图表...
🚀 创建 Skill 实战
步骤 1: 规划 Skill
正在加载图表...
步骤 2: 创建目录结构
步骤 3: 编写 SKILL.md
步骤 4: 添加参考资料
步骤 5: 添加示例
📚 实战示例库
示例 1: Excel 分析 Skill
示例 2: API 文档生成 Skill
示例 3: 测试生成 Skill
🎓 最佳实践
15 条黄金法则
正在加载图表...
Skill 编写检查清单
✅ 元数据检查
- name 使用 gerund 形式(processing-data)
- name 只包含小写、数字、连字符
- description 说明”做什么”和”何时用”
- description 使用第三人称
- description 包含具体触发场景
- 如需限制,设置 allowed-tools
- 添加相关 tags
✅ 内容质量
- SKILL.md < 500 行
- 包含 Overview 部分
- 步骤清晰可执行
- 提供具体示例
- 说明输出格式
- 包含最佳实践
- 错误处理说明
✅ 文件组织
- 详细内容放在 reference.md
- 示例放在 examples.md
- 脚本放在 scripts/ 目录
- 避免嵌套引用(最多一层)
✅ 测试验证
- 在 Haiku 上测试
- 在 Sonnet 上测试
- 在 Opus 上测试
- 测试边界情况
- 测试错误处理
- 验证输出格式
✅ 团队协作
- 添加 README 说明
- 文档变更记录
- 提交到项目 Git
- 团队成员审查
🔧 调试与优化
常见问题排查
正在加载图表...
性能优化技巧
1. 控制文件大小
<!-- ❌ 不好: SKILL.md 包含所有内容 -->
---
name: my-skill
description: ...
---
# My Skill
## Instructions
[500+ lines of detailed instructions]
## Examples
[200 lines of examples]
## Reference
[300 lines of reference material]<!-- ✅ 好: 拆分内容 -->
---
name: my-skill
description: ...
---
# My Skill
## Instructions
[Core instructions < 100 lines]
For detailed reference, see [reference.md](./reference.md)
For examples, see [examples.md](./examples.md)2. 使用脚本处理确定性任务
<!-- ❌ 让 Claude 处理复杂计算 -->
## Instructions
Calculate the SHA256 hash of each file and compare with expected values...
<!-- ✅ 使用脚本 -->
## Instructions
Run the verification script:
\`\`\`bash
python scripts/verify_hashes.py
\`\`\`3. 优化 description 匹配
# ❌ 过于宽泛
description: Helps with data analysis
# ✅ 具体场景
description: Analyzes CSV and Excel files to generate statistical summaries and visualizations when the user requests data analysis or asks to summarize tabular data🌐 Skills 生态系统
官方 Skills
📄 Document Skills
- pdf - PDF 处理和表单填充
- xlsx - Excel 电子表格创建和编辑
- docx - Word 文档操作
- pptx - PowerPoint 演示文稿
🎨 Creative Skills
- algorithmic-art - 生成式艺术创作
- canvas-design - 视觉设计
- slack-gif-creator - GIF 动画
💼 Enterprise Skills
- brand-guidelines - 品牌规范
- internal-comms - 内部沟通
- theme-factory - 主题定制
🔧 Developer Skills
- mcp-builder - MCP 服务器生成
- webapp-testing - Web 应用测试
- artifacts-builder - Claude 工件构建
社区 Skills 资源
📚 GitHub 仓库
- anthropics/skills - 官方示例 Skills 库
- obra/superpowers - 20+ 经过实战检验的核心 Skills
- TDD、调试、协作模式
- Git worktrees、分支管理
- 并行代理工作流
- awesome-claude-skills - 精选社区 Skills 集合
- claude-code-skill-factory - Skill 生成工具包
🎓 学习资源
📖 案例研究: 完整 Skill 开发流程
场景: 创建数据库迁移 Skill
正在加载图表...
完整实现
💡 总结
Claude Skills 是模块化能力扩展的强大机制:
核心优势:
- 🎯 智能调用 - Claude 自主判断何时使用
- 📦 模块化 - 可组合、可移植、易维护
- ⚡ 高效 - 按需加载,上下文优化
- 💪 强大 - 支持脚本、工具、MCP 集成
三种存储位置:
- 个人 Skills - ~/.claude/skills/ (个人工作流)
- 项目 Skills - .claude/skills/ (团队共享)
- 插件 Skills - 插件市场(社区贡献)
核心文件结构:
- SKILL.md - 核心指令和元数据(必需)
- reference.md - 详细参考资料(可选)
- examples.md - 使用示例(可选)
- scripts/ - 可执行脚本(可选)
最佳实践:
- 保持单一职责
- 编写明确的 description
- 使用渐进式披露(SKILL.md < 500行)
- 提供具体示例
- 跨模型测试
- 使用脚本处理确定性任务
- 通过 Git 共享团队 Skills
适用场景:
- 复杂多步骤工作流
- 专业领域知识
- 团队标准和规范
- 可重复的任务自动化
开始使用 Claude Skills,为 Claude 装备超能力! 🚀
相关资源
- Claude Code Hooks 完全指南 - 事件驱动的自动化工作流
- Claude Code 系统提示词完整解析 - 43 个系统提示词详解
- Claude Code 2.0 深度架构分析 - 完整架构分析
- Claude Code 介绍 - 快速入门指南
✨ 准备好创建你的第一个 Skill 了吗? ✨
从简单的工作流开始,逐步打造专属的 AI 能力库