# 斜杠命令参考

参考代码在 `references/`。OpenProgram 自己的设计：[斜杠命令](https://fzkuji.github.io/OpenProgram/docs/reference/design/cli/slash-commands.zh.html)。

## 功能矩阵

| 功能 | claude-code | opencode | openclaw | hermes | pi-mono |
| --- | --- | --- | --- | --- | --- |
| 文件系统扫描 | 递归，防符号链接 | glob | 无 | 单目录 | 无 |
| frontmatter 字段数 | 15+ | 5 | 不适用 | 约 6 | 0 |
| `$ARGUMENTS` | 有 | 有 | 无 | 有 | 无 |
| `$0..$9` | 有 | 有 | 无 | 无 | 无 |
| 命名 `$name` | 有 | 无 | 无 | 无 | 无 |
| `${ENV_VAR}` | 有 | 无 | 无 | 有 | 无 |
| `` !`shell` `` | 有 | 无 | 无 | 有，带超时 | 无 |
| `@file` | 无 | 无 | 无 | 无 | 无 |
| 按 `paths` 条件激活 | 有 | 无 | 无 | 无 | 无 |
| `context: fork` | 有 | `subtask` | 无 | 无 | 无 |
| `effort` | 有 | 无 | 无 | 无 | 无 |
| MCP 自动成斜杠命令 | 有 | 无 | 无 | 无 | 无 |
| 内嵌 hook | 有 | 无 | 无 | 无 | 无 |
| 多目录覆盖 | 有 | 无 | 无 | 无 | 无 |
| realpath 去重 | 有 | 无 | 无 | 无 | 无 |
| i18n | 无 | 无 | 有 | 无 | 无 |
| provider 路由 | 无 | 无 | 有 | 无 | 无 |
| 平台过滤 | 无 | 无 | 无 | 有 | 无 |
| 依赖检查 | 无 | 无 | `requires`、`install` | 无 | 无 |
| 热重载 | 有 | 无 | 无 | 无 | 无 |

五个都有 description 字段。三个及以上都有 name、description、正文模板、frontmatter 解析和区分执行模式。

## OpenProgram 采用什么

| 项目 | 采用 |
| --- | --- |
| claude-code | 整体设计：`context: fork`、`paths`、`hooks`、`effort`、realpath 去重、MCP 自动成斜杠命令 |
| opencode | `$0-9` 和 `arguments[]` |
| openclaw | `requires` 作为独立字段、安装提示；描述 i18n 记为可借鉴 |
| hermes | `!` shell 块的超时、平台过滤的想法 |
| pi-mono | 只在 `type: local` 内建命令上硬编码；其余是反例 |

## 各项目

**claude-code**

[公开的 Skills 文档](https://code.claude.com/docs/en/skills)

| 方面 | 细节 |
| --- | --- |
| 位置 | 企业、个人 `~/.claude/skills/`、项目 `.claude/skills/`、嵌套、`--add-dir`、插件 |
| 重名时 | 企业优先于个人，个人优先于项目；`.claude/commands/` 让位于 skill |
| 符号链接、重载 | 多个位置指向同一目标时只加载一次。监听 skill 目录，改动在运行中的会话里生效 |
| 正文 | `$ARGUMENTS`、`$N`、`$name`、`${CLAUDE_SKILL_DIR}`、`${CLAUDE_SESSION_ID}`、`${CLAUDE_PROJECT_DIR}`、`${CLAUDE_EFFORT}`、`` !`cmd` `` 和 ```` ```! ```` 块。命令失败则中止本次调用 |
| 参数 | 引号让多词参数保持完整。没有占位符接收的参数以 `ARGUMENTS: <value>` 追加 |
| 模式 | 内联；`context: fork` 在 subagent 中运行 |
| Frontmatter | `name`、`description`、`when_to_use`、`argument-hint`、`arguments`、`disable-model-invocation`、`user-invocable`、`allowed-tools`、`disallowed-tools`、`model`、`effort`、`context`、`agent`、`background`、`hooks`、`paths`、`shell` |

**opencode**

`references/opencode/packages/opencode/src/config/command.ts`

| 方面 | 细节 |
| --- | --- |
| 来源 | glob `{command,commands}/**/*.md`，绝对路径。Effect Schema 校验并与内容合并。无去重、watch 或条件激活 |
| frontmatter | `template`（必填）、`description`、`agent`、`model`（ConfigModelID）、`subtask`（boolean） |
| 模板 | 纯文本展开，`$ARGUMENTS`、`$0-9`；`arguments:` 声明列表 |
| 特色 | 五个中类型安全最强；`subtask: true` 是简化的 fork；MCP skill 返回惰性 Promise |

**openclaw**

`references/openclaw/src/auto-reply/commands-registry.*`

| 方面 | 细节 |
| --- | --- |
| 来源 | 数据驱动的硬编码注册表，无文件系统扫描，按 provider 映射（Slack、Mattermost） |
| `ChatCommandDefinition` | `key`、`nativeName`、`nativeAliases?`、`description`、`descriptionLocalizations?`、`scope`（`text` 或 `native`）、`args?`、`acceptsArgs` |
| 特色 | `resolveNativeName` 和 pluginProvider hook；i18n；参数选择菜单（`CommandArgChoiceContext`），类似 Discord 下拉 |
| Skill | `SKILL.md` frontmatter 含 `emoji`、`requires.anyBins`、`requires.config`、`install[]` |

**hermes-agent**

`references/hermes-agent/tools/skills_tool.py`、`agent/skill_commands.py`、`agent/skill_preprocessing.py`

| 方面 | 细节 |
| --- | --- |
| 来源 | 单目录 `~/.hermes/skills/`：内置、hub 安装和编辑过的条目共存；`get_external_skills_dirs()` 扩展。trusted_roots 带路径穿越防护 |
| frontmatter | `metadata.hermes.config`（变量）、`platforms`；`metadata.hermes.*` 优先于顶层字段 |
| 正文 | `_substitute_template_vars`、`_expand_inline_shell`（超时）、注入 `[Skill config: ...]` |
| 特色 | 平台过滤、134 条提示注入模式、`_secret_capture_callback` |

**pi-mono**

`references/pi-ai/packages/coding-agent/src/core/slash-commands.ts`

硬编码内建（settings、model、export、import、fork、clone），不扫描。`SlashCommandSource` 有 extension、prompt、skill，实际只用 builtin。代表完全没有扩展机制的取舍。

## 同步

1. `cd references && git pull`，例如每季度一次。
2. 用上面的表逐项对比各项目。决定新字段、模板语法、模式和安全约束是否进入[斜杠命令](https://fzkuji.github.io/OpenProgram/docs/reference/design/cli/slash-commands.zh.html)。
3. 更新本页。
