教程

Claude Code Skills 完全指南:创建自定义技能、Bundled Skills 与高级模式

Claude Code Skills 完全指南:5 个内置 Bundled Skills(/simplify 并行 3 Agent/\batch Git Worktree 并行/\debug 会话日志/\loop 定时执行/\claude-api 自动激活)、3 步创建自定义 Skill(目录/SKILL.md/测试)、存储位置与优先级(Enterprise/Personal/Project/Plugin 命名空间)、Frontmatter 完整配置(name/description/disable-model-invocation/tools)、两种内容类型(参考型内联/任务型手动)、高级模式($ARGUMENTS 字符串替换/支持文件目录/动态注入上下文/子 Agent 执行),以及三种共享方式和故障排查。

2026/3/85分钟 阅读ClaudeEagle

Skills(技能)是 Claude Code 最强大的扩展机制——创建一个 SKILL.md 文件,Claude 就能将其加入工具箱,在合适时自动使用,或通过 /技能名 直接调用。

旧版 .claude/commands/ 自定义命令已合并到 Skills,现有文件继续有效,但 Skills 支持更多功能(支持文件目录、前置元数据、自动调用控制、子 Agent 执行)。

内置 Bundled Skills

Claude Code 自带 5 个 Bundled Skills,每次会话均可用:

Skill调用方式说明
/simplify用户调用审查近期修改文件,并行启动 3 个 Agent(代码复用/质量/效率),汇总修复
/batch <指令>用户调用大规模并行代码变更——分解为 5-30 个独立单元,每个单元一个 Git Worktree Agent,各自实现并开 PR
/debug [描述]用户调用读取 Session Debug 日志,排查当前 Claude Code 会话问题
/loop [间隔] <提示>用户调用按时间间隔重复执行提示词,监控部署/PR/构建结果
/claude-api自动/用户加载 Claude API 参考(Python/TS/Java/Go/Ruby/C#/PHP),代码导入 anthropic 时自动激活

创建第一个 Skill(3 步)

第一步:创�� Skill 目录

bash
# 个人 Skill(所有项目可用)
mkdir -p ~/.claude/skills/explain-code

# 项目 Skill(仅本项目)
mkdir -p .claude/skills/explain-code

第二步:编写 SKILL.md

markdown
---
name: explain-code
description: Explains code with visual diagrams and analogies. Use when explaining how code works, teaching about a codebase, or when the user asks "how does this work?"
---

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, structure, or relationships
3. **Walk through the code**: Explain step-by-step what happens
4. **Highlight a gotcha**: What's a common mistake or misconception?

第三步:测试

# 自动调用(Claude 根据 description 判断) How does this code work? # 直接调用 /explain-code src/auth/login.ts

Skill 存储位置与优先级

位置路径作用范围
Enterprise托管设置组织所有用户
Personal~/.claude/skills/<name>/SKILL.md你的所有项目
Project.claude/skills/<name>/SKILL.md本项目所有协作者
Plugin<plugin>/skills/<name>/SKILL.md插件启用的项目

同名 Skill 优先级:Enterprise > Personal > Project。Plugin Skill 使用 plugin-name:skill-name 命名空间,不会冲突。

Monorepo 自动发现:编辑 packages/frontend/ 中的文件时,Claude Code 自动发现 packages/frontend/.claude/skills/ 中的 Skills。

Frontmatter 配置参考

yaml
---
name: review-pr              # Slash 命令名称(/review-pr)
description: |               # 帮助 Claude 决定何时自动加载
  Reviews pull requests for code quality.
  Use when reviewing PRs or checking code changes.
disable-model-invocation: true  # 禁止 Claude 自动调用,只能手动 /invoke
tools: [Read, Bash]          # 限制此 Skill 可用的工具
---
字段默认值说明
name文件目录名Slash 命令名称
description帮助 Claude 决定自动加载时机
disable-model-invocationfalse为 true 时只能用户手动调用
tools全部限制该 Skill 可使用的工具列表

两种 Skill 内容类型

参考型:添加 Claude 应用到当前工作的知识(规范、模式、风格指南)。以内联方式运行,可与对话上下文共用。

markdown
---
name: api-conventions
description: API design patterns for this codebase
---

When writing API endpoints:
- Use RESTful naming conventions
- Return consistent error formats
- Include request validation

任务型:给 Claude 分步操作指令(部署、提交、代码生成)。通常手动调用,加 disable-model-invocation: true

高级模式

字符串替换

在 SKILL.md 中可使用占位符:

markdown
$ARGUMENTS     # 用户在 /skill-name 后输入的参数
$CURRENT_FILE  # 当前打开的文件路径
$SELECTION     # 当前选中的文本

支持文件目录

explain-code/ ├── SKILL.md # 主指令(必须) ├── template.md # Claude 填写的模板 ├── examples/ │ └── sample.md # 示例输出 └── scripts/ └── validate.sh # Claude 可执行的脚本

在 SKILL.md 中引用这些文件,Claude 知道它们的位置和用途。

动态注入上下文

markdown
---
name: review-pr
description: Reviews pull requests
---

First, run: `git diff main`
Then review the output for:
- Security vulnerabilities
- Performance issues

Claude 执行命令并将输出纳入分析上下文。

在子 Agent 中运行 Skill

markdown
---
name: research
description: Deep research using isolated agent
---

Use the Explore agent to research this topic thoroughly:
1. Search for relevant files
2. Read and analyze key sections  
3. Return a structured summary

在子 Agent(Explore agent)中运行,避免污染主会话上下文。

共享 Skills

  • 通过插件:打包为插件后分发,支持版本管理,可发布到市场
  • 通过项目:提交 .claude/skills/ 到 git,团队共享
  • 通过个人目录~/.claude/skills/ 仅本人使用

故障排查

问题解决方案
Skill 未触发检查 description 是否清晰描述触发场景
Skill 触发太频繁disable-model-invocation: true,改为手动调用
Claude 看不到所有 Skill检查目录结构(每个 Skill 一个目录,SKILL.md 在目录内)

原文:Extend Claude with skills - Claude Code Docs | 来源:Anthropic 官方文档

相关文章推荐

教程Claude Code Skills 进阶指南:四大内置技能、动态上下文注入、Subagent 运行与参数传递Claude Code Skills 进阶完整指南:四大内置 Skill(/simplify 三 Agent 并行优化/batch 5-30 单元并行大规模变更//debug 会话调试//claude-api 自动加载 API 参考)、目录结构和四级存储位置(优先级规则)、完整 Frontmatter 字段(disable-model-invocation/context/tools.allow/deny)、参考型 vs 任务型内容对比、动态上下文注入($GIT_STATUS/$CURRENT_SCHEMA)、context:fork 在 Subagent 运行、$ARGUMENTS 参数传递。2026/3/6教程Claude Code Skills 自定义命令:打造你的团队专属 AI 工作流Claude Code Skills 自定义命令完整教程:Skills vs CLAUDE.md 使用场景对比、内置 Skills 速览(/batch/simplify/loop)、SKILL.md 文件格式与 Frontmatter 配置、四大实用 Skills 示例(代码审查/部署检查/功能开发/团队 OnBoarding)、传参方式、子代理执行与 Git 团队共享。2026/3/14教程Claude Code 插件开发指南:plugin.json 结构、Skills/Hooks/MCP 集成与官方市场提交Claude Code 插件开发完整指南:独立配置 vs 插件对比(命名空间/适用场景)、5 步快速创建(目录/plugin.json 清单字段/Skill/本地 --plugin-dir 测试/分享)、完整插件目录结构(.claude-plugin/commands/skills/agents/hooks/mcp/.lsp.json/settings.json)、各组件配置示例(Skills SKILL.md/LSP 服务器.lsp.json/默认 settings.json agent 键)、从独立配置迁移步骤对比表、三步调试方法,以及通过 claude.ai 和 Console 提交官方市场的方式。2026/3/8教程Claude Code 插件开发指南:从 plugin.json 到 Skills/Agents/Hooks 打包发布全流程Claude Code Plugin 开发完整指南:独立配置 vs Plugin 选型(短名称 vs 命名空间)、5 分钟创建第一个 Plugin(plugin.json Manifest + SKILL.md)、Plugin 目录结构(skills/agents/hooks/settings/lsp)、LSP 服务器集成、随 Plugin 发布默认 Hooks 设置、--plugin-dir 本地测试、从独立配置迁移(名称变化说明)、Git/npm 发布方式,以及 /plugin install/list/enable/disable/remove 用户命令。2026/3/6教程Claude Code Skills 完全指南:创建自定义技能、内置技能与子代理执行Claude Code Skills 完全指南:三个内置技能(/simplify、/batch、/debug)、创建自定义 Skill 的完整步骤、Frontmatter 字段参考(invocation/tools 控制)、动态上下文注入、子代理执行,以及 Skills 的共享和发现方式。2026/3/2教程Claude Code Plugins 开发完整指南:从创建 Manifest 到发布到官方市场Claude Code Plugin 开发完整指南:从创建 plugin.json 清单、添加 Skills/Subagent/Hooks/MCP/LSP 服务器,到本地测试、团队分发和提交到 Anthropic 官方市场。附安全审查 Plugin 完整示例和现有配置迁移步骤。2026/2/28