本章总览
src/skills/(24+ TS 文件 + bundled markdown 资源,catalog 约 4096 行)实现 Claude Code 的 Skill / 斜杠命令 系统:磁盘 SKILL.md 加载、bundled 内置 skill、MCP prompt 转 skill、以及 SkillTool 模型 invocation。本模块四篇子章节覆盖加载、bundled、MCP、工具集成全链路。
总览图
渲染图表中…
学完本章你应该能
- 区分 skill(prompt command)与普通 slash command
- 理解 LoadedFrom 来源:skills / bundled / plugin / managed / mcp
- 掌握 initBundledSkills 启动注册顺序
- 会从子章节进入加载、bundled、MCP、SkillTool 深度讲解
建议学习步骤
- 浏览 SourceTree 含 skills/ 与 bundled/ 子树
- 读 skills-loading 理解 loadSkillsDir
- 读 bundled-skills 理解 verify / remember / claude-api
- 读 skill-tool-integration 串起模型调用路径
模块在架构中的位置
skills 是 src/ 下的一级目录,共 24 个文件、4,096 行。建议结合「系统架构」章节理解它与其他层的调用关系。
概览
| 指标 | 数值 |
|---|---|
| 行数 | 4,096 |
| 文件 | 24 |
子章节导航
| 子章节 | 主题 | 核心路径 |
|---|---|---|
| skills-loading | 磁盘加载与 bundledSkills 注册表 | loadSkillsDir.ts, bundledSkills.ts |
| bundled-skills | 内置 verify / remember / claude-api 等 | bundled/index.ts, bundled/*.ts |
| mcp-skills | MCP prompt → skill 转换 | mcpSkills.ts, mcpSkillBuilders.ts |
| skill-tool-integration | SkillTool 与命令注册 | tools/SkillTool/SkillTool.ts, commands.ts |
数据流简图:
启动 main.tsx → initBundledSkills()
→ registerBundledSkill (bundledSkills.ts)
→ getCommands() merges disk skills (loadSkillsDir) + bundled + MCP
用户 /skill 或模型 SkillTool
→ findCommand → getPromptForCommand / executeForkedSkill
→ query 循环注入 prompt blocks
skills 与 commands 模块边界
commands.ts 聚合所有 Command(builtin slash、skill、plugin);skills/ 专注 skill 格式(SKILL.md frontmatter、prompt command type)。
| 概念 | 位置 |
|---|---|
| Command 类型定义 | types/command.js |
| 磁盘 skill 扫描 | skills/loadSkillsDir.ts |
| 内置 skill | skills/bundled/*.ts |
| MCP skill 构建 | skills/mcpSkills.ts + mcpSkillBuilders.ts |
| 模型 invocation | tools/SkillTool/SkillTool.ts |
| REPL 热重载 | REPL useSkillsChange → setLocalCommands |
catalog 行数含 bundled 下大量 claude-api markdown 资源,非全为 TS 逻辑。
点击文件跳转子章节。bundled/claude-api/ 含多语言 API 文档 markdown,由 claudeApi.ts 懒加载。
本章小结与延伸
skills = 用户可调用能力目录。建议:skills-loading → bundled-skills → mcp-skills → skill-tool-integration。 继续学习: