技能系统
技能是带有 YAML 前言的 Markdown 文件,将专门的提示词注入到对话中。Claude Code 附带 17 个捆绑技能,并支持项目和用户级别的自定义技能。
/skill-name 调用(像斜杠命令),
但它们的工作方式不同:它们将提示词注入到对话中,而不是运行本地代码。
模型也可以在检测到相关任务时自动调用技能。
架构
技能系统有 7 个核心组件,协同工作以加载、发现、展示和执行技能。
| Component | File | Purpose |
|---|---|---|
| SkillTool | src/tools/SkillTool/ | 模型调用以执行技能的工具 |
| Bundled Skills | src/skills/bundled/ | 编译到 CLI 二进制中的技能 |
| Skill Loader | src/skills/loadSkillsDir.ts | 从磁盘目录加载技能 |
| Skill Discovery | src/utils/skills/skillChangeDetector.ts | 运行时动态检测新技能 |
| Skill Listing | src/utils/attachments.ts | 每轮将技能列表注入 system-reminder |
| Usage Tracking | src/utils/suggestions/skillUsageTracking.ts | 用于排名建议的指数衰减跟踪 |
| Skill Improvement | src/utils/hooks/skillImprovement.ts | 自动改进技能提示词的后采样 hook |
加载源(优先级顺序)
技能从 9 个不同的源加载。当名称冲突时,更高优先级的源覆盖更低优先级的源。
| # | Source | Path | Scope |
|---|---|---|---|
| 1 | Managed (policy) | <managed_path>/.claude/skills/ | 企业 / 组织范围 |
| 2 | User | ~/.claude/skills/ | 个人,所有仓库 |
| 3 | Project | .claude/skills/ (and parents up to home) | 项目,与团队共享 |
| 4 | Additional dirs | --add-dir <path>/.claude/skills/ | 会话特定 |
| 5 | Legacy commands | ~/.claude/commands/ and .claude/commands/ | 已弃用格式 |
| 6 | Bundled | Compiled into the binary | 内置 |
| 7 | Plugin | Installed via marketplace | 插件作用域 |
| 8 | MCP | From connected MCP servers | 服务器作用域 |
| 9 | Dynamic | Discovered at runtime when files are touched | 路径条件 |
技能文件格式
技能位于 .claude/skills/<name>/SKILL.md。
目录名成为技能名称。旧版单文件格式(<name>.md)已弃用。
关键前言字段
| Field | Type | Description |
|---|---|---|
| name | string | 显示名称(默认为目录名) |
| description | string | 技能列表中显示的简短描述 |
| allowed-tools | string[] | 技能可使用的工具白名单(如 Bash(npm:*)、Read) |
| when_to_use | string | 模型应何时自动调用此技能 |
| argument-hint | string | 类型提示中显示的参数提示文本 |
| model | sonnet|opus|haiku|inherit | 覆盖此技能的模型 |
| effort | low|medium|high|max | 覆盖努力/思考级别 |
| context | inline|fork | inline:在当前对话中展开;fork:在隔离子代理中运行 |
| user-invocable | boolean | 用户是否可以用 /name 调用 |
| disable-model-invocation | boolean | 阻止模型自动调用此技能 |
| paths | string[] | 触摸文件时条件激活的 glob 模式 |
| hooks | object | 会话作用域生命周期 hooks(PreToolUse、PostToolUse) |
| skills | string | 运行时预加载的逗号分隔技能列表 |
内容变量
| Variable | Description |
|---|---|
| $ARGUMENTS or $1, $2 | 用户调用技能时传递的参数 |
| ${CLAUDE_SKILL_DIR} | 技能文件的基础目录 |
| ${CLAUDE_SESSION_ID} | 当前会话 ID |
| !`command` | 内联 shell 执行:输出在加载时注入到提示词中 |
捆绑技能
17 个技能编译到二进制文件中。10 个对所有用户可用,5 个仅 Anthropic 内部使用, 2 个由功能标志控制。
公开技能(10)
Writes settings.json changes. Contains the complete settings schema, hook patterns, permissions syntax, and a 7-step hook verification flow.
Reference for editing keybindings.json. Auto-invoked when user asks about keybindings. Not user-invocable.
Reads the tail of the debug log and runs a 5-step investigation process. Suggests launching the claude-code-guide subagent.
Runs a 3-phase code review: identify changes, launch 3 parallel review agents (code reuse, code quality, efficiency), then fix issues.
Large-scale change orchestrator. Decomposes work into 5-30 units, spawns one background agent per unit with worktree isolation, tracks progress.
Schedules a recurring task via CronCreate. Converts plain English intervals to cron expressions and runs the task immediately.
Schedules remote agents via RemoteTrigger. Interactive wizard for creating, listing, and running scheduled agent tasks.
Loads 247KB of bundled API documentation. Auto-detects project language and provides task-specific routing for Claude API/SDK usage.
Activates Chrome browser automation tools. Only enabled when Chrome extension is detected.
Generates an analytical report of your Claude Code usage sessions. Lazy-loaded.
Anthropic 内部技能(5)
Verifies a code change works by actually running the application. Reference files provide examples for CLI and server verification patterns.
Generates random filler text from verified 1-token English words. Default 10,000 tokens, max 500,000. Used for long-context testing.
4-step process to capture a repeatable workflow as a SKILL.md. Interviews the user in 4 rounds via AskUserQuestion, then generates the file.
4-step memory review: gather all memory layers, classify each entry by destination (CLAUDE.md, local, team, auto), identify cleanup opportunities, present proposals.
Diagnoses frozen or slow Claude Code sessions by inspecting processes, CPU samples, and debug logs. Reports via Slack MCP. Never kills processes.
功能标志控制的技能(2)
Consolidates daily logs into structured MEMORY.md entries. Runs overnight in KAIROS autonomous mode.
Bug hunting and review artifact skill.
发现系统
Automatic surfacing
Skills are listed in system-reminder messages each turn. Budget: 1% of context window. Bundled skills are never truncated.
Path-based activation
Skills with paths: in frontmatter only activate when the model touches files matching those glob patterns.
Dynamic discovery
When reading/writing files, Claude walks parent directories looking for .claude/skills/ directories. Enables nested skill hierarchies per package.
File watcher
chokidar monitors skill directories and auto-reloads when files change. You can edit skills live during a session.
Usage tracking
Exponential decay with 7-day half-life. More recently and frequently used skills rank higher in suggestions.
Experimental search
A remote search system (EXPERIMENTAL_SKILL_SEARCH) can discover canonical skills from a backend. Cached locally with _canonical_ prefix.
创建自定义技能
将 SKILL.md 文件放入这些目录中的任何一个。
目录名成为斜杠命令名称。
| Location | Scope | When discovered |
|---|---|---|
| ~/.claude/skills/<name>/SKILL.md | Personal, all repos | Startup |
| .claude/skills/<name>/SKILL.md | Project, shared with team | Startup + dynamic |
| <subdir>/.claude/skills/ | Nested, per-package | When files in subdir are touched |
| ~/.claude/commands/<name>.md | Personal (legacy, deprecated) | Startup |
| .claude/commands/<name>.md | Project (legacy, deprecated) | Startup |
最小技能
---
description: Run tests and fix failures
user-invocable: true
---
Run the test suite. If tests fail, fix them. Fork 上下文示例
带有 context: fork 的技能在隔离的子代理中运行。
输出不会污染主上下文,它可以使用不同的模型,并且有自己的 token 预算。
---
name: Security Audit
description: Run a security audit in an isolated agent
context: fork
agent: general-purpose
model: opus
effort: high
user-invocable: true
---
Perform a thorough security audit of the current codebase.
Check for OWASP top 10, hardcoded secrets, and insecure dependencies.