Commands 与 Skills
Commands 和 Tools 容易混淆,但它们解决的问题不同。
Slash commands
Slash command 是用户主动触发的能力,例如:
text
/help
/model
/compact
/memory1
2
3
4
2
3
4
它的主要用户是人。
在 Claude Code 里,commands.ts 负责把内建命令、skills、plugin commands、MCP skills 等来源合并成命令列表。
源码里需要区分几个函数:
loadAllCommands():合并内建 commands、skills、plugin commands。getCommands():按用户状态和isEnabled过滤当前可用命令。getSkillToolCommands():筛出模型可通过 SkillTool 调用的 prompt command。getSlashCommandToolSkills():筛出 slash command 工具可展示的 skills。
不是所有 slash command 都能被模型调用。builtin、非 prompt 类型、disableModelInvocation 等都会被过滤。
Skills
Skill 更像“可按需加载的操作手册”。
模型不需要在系统提示里长期携带所有技能全文,只需要先知道:
- skill 名称。
- 简短描述。
- 什么时候使用。
真正需要时,再通过 SkillTool 加载完整 SKILL.md。
这是一种非常值得学习的设计:把长能力说明从 system prompt 中延迟加载。
自研 Agent 怎么做
第一版可以这样:
text
commands/
compact.md
memory.md
skills/
code-review/
SKILL.md
debugging/
SKILL.md1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
命令给用户用,Skill 给模型用。
最小 skill metadata:
yaml
name: debugging
description: Use when diagnosing a failing test or runtime bug.
allowedTools:
- read_file
- grep
- bash1
2
3
4
5
6
2
3
4
5
6
小结
Commands 是用户操作入口,Skills 是模型能力入口。把它们分开,Agent 的交互层和能力层会更清晰。