教程

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 官方完整指南:从入门到高级模式的权威教程Claude Code Skills 官方文档完整中文整理:Skills vs CLAUDE.md 核心区别;目录结构;存储位置和优先级;实时变更检测和 Monorepo 自动发现;完整 Frontmatter 字段参考(20+字段);字符串替换(动态参数);内容类型(参考类 vs 任务类);调用控制表;Skill 内容生命周期(压缩保留机制);三个高级模式(动态注入/路径限定/Subagent运行);以及内置 Bundled Skills 和权限控制方法。2026/5/10教程OpenClaw Skills 开发完全指南:从零编写高质量 SKILL.md 自定义技能文件OpenClaw Skills 开发完整教程:SKILL.md 文件结构详解、自动触发 vs 显式触发原理、三个实战模板(GitHub 仓库管理/每日信息简报/代码健康检查)、让技能精准自动触发的描述写法,以及技能质量标准和 clawhub.ai 使用方法。2026/4/19教程Claude Code SKILL.md 自定义技能教程:创建可复用 AI 工作流,告别重复配置Claude Code SKILL.md 自定义技能教程:4 种技能类型详解(领域知识、工作流、安全检查、支付约束),含团队共享配置和全局 Skill 设置,告别每次重复配置。2026/4/10教程Claude Code 插件系统完全指南:创建、分发和管理自定义插件Claude Code 插件系统完全指南:创建自定义 Skills、Agents、Hooks,支持团队共享和 Marketplace 分发。含完整目录结构、组件详解和开发技巧。2026/4/7教程Claude Code Skills 自定义命令:打造你的团队专属 AI 工作流Claude Code Skills 自定义命令完整教程:Skills vs CLAUDE.md 使用场景对比、内置 Skills 速览(/batch/simplify/loop)、SKILL.md 文件格式与 Frontmatter 配置、四大实用 Skills 示例(代码审查/部署检查/功能开发/团队 OnBoarding)、传参方式、子代理执行与 Git 团队共享。2026/3/14