命令行参考
spec-first CLI 负责确定性操作:检查、初始化、升级、清理、task pack 校验和计划审计。研发工作流本身在宿主会话里运行,用 spec-* 入口调用。
命令总览
spec-first --help
spec-first --version
spec-first quickstart [-y|--yes]
spec-first doctor [--claude|--codex|--cursor|--kiro|--qoder|--opencode|--zcode|--pi] [--json] [--verbose]
spec-first init [--claude] [--codex] [--cursor] [--kiro] [--qoder] [--opencode] [--zcode] [--pi] [-y] [--all-repos|--repo <path>] [-u <name>] [--lang <zh|en>] [--dry-run]
spec-first update [--dry-run]
spec-first clean (--claude|--codex|--cursor|--kiro|--qoder|--opencode|--zcode|--pi) [--dry-run]
spec-first clean --workspace-orphans [--confirm]
spec-first clean --workspace-graph [--repos a,b] [--dry-run]
spec-first repair-worktree [--dry-run]
spec-first tasks hash <plan-path> [--json]
spec-first tasks validate <task-pack-path> [--json] [--repo=<path>|--repo <path>]
spec-first plans audit [--status <canonical>] [--json]
spec-first session <register|heartbeat|unregister|list> [options]spec-* 不是 CLI 子命令,而是 init 之后由宿主加载的工作流入口。CLI 准备确定性事实,工作流负责语义判断和工程交接。
quickstart
第一次使用时,在目标 Git 仓库根目录打开终端,运行以下命令。
spec-first quickstartquickstart 检查 Node.js、Git 和已安装的宿主 CLI,再进入 spec-first init。检测到唯一宿主时会自动选中它。未检测到或检测到多个时,由你选择。按提示确认写入后,在同一目录重新打开所选宿主。
-y/--yes 只在恰好检测到一个宿主时跳过交互。检测到零个或多个宿主时,使用该参数会以退出码 2 结束。
doctor
spec-first doctor
spec-first doctor --claude
spec-first doctor --jsondoctor 只读检查,不需要重新 init:
| 字段 | 含义 |
|---|---|
install_health | Node、Git 与 package 级检查 |
runtime_asset_health | init 生成的 managed runtime assets 是否完整 |
host_readiness | 指定宿主的 CLI、runtime 与项目接入情况 |
decision_input_health | 当前为 not_checked;运行环境就绪状态不在这里编译 |
workflow_runnability | verified、simulated 或 not_verified |
doctor 不安装 MCP servers,也不判断需求或代码质量。--verbose 显示全部检查明细,--json 供脚本消费。运行环境由 spec-runtime-setup 负责。
init
spec-first init
spec-first init -y -u <name> --lang zh
spec-first init --dry-run| 参数 | 作用 |
|---|---|
--claude / --codex | 初始化主要支持的宿主 |
--cursor / --kiro / --qoder / --opencode / --zcode / --pi | 显式启用对应的预览宿主 |
-y / --yes | 跳过提示;未指定宿主时只初始化 Claude Code 和 Codex |
--all-repos / --repo <path> | 父 workspace 下选择全部或指定 child 仓库 |
-u <name> | 写入 developer profile |
| `--lang <zh | en>` |
--sync-user-language / --no-sync-user-language | 是否同步用户级的语言设置 |
--dry-run | 只预览将要写入的内容,不修改任何文件 |
init 无参数时进入交互式流程:选择宿主、确认 developer name、选择语言、预览写入计划、确认或取消。非 TTY 环境必须使用 -y,否则退出码为 2。写入前总会预览受管文件,不会自动 stage 或提交。
初始化后重启宿主或开启新会话,spec-* 工作流入口即可使用。
CLI 与宿主入口的分界
spec-first init 把源码里的工作流投射成各宿主的 runtime。要改变工作流的行为,应修改源码资产,而不是手改 .claude/、.codex/、.agents/skills/、.cursor/、.kiro/、.qoder/、.zcode/ 里的生成文件。
update
spec-first update --dry-run
spec-first update确认当前命令来自 npm 全局安装后,update 会先升级这份 CLI,再刷新当前目标中已经安装过的宿主。工作流仍在宿主会话中按需运行。
- 升级后自动运行一次
spec-first init来刷新 runtime;无法安全刷新时,会给出可直接复制的 fallback 命令。 - 如果当前副本来自 Claude plugin、本地源码、
npx、npm link或来源不明,update不会安装第二份全局包,只给出更新指引。 --dry-run只查询目标版本和刷新范围,不修改项目。
注意:update 成功不代表宿主已经加载了新的入口。刷新后仍需重启宿主。
clean
spec-first clean --claude
spec-first clean --claude --dry-run
spec-first clean --workspace-orphans
spec-first clean --workspace-graph --repos a,b --dry-runclean 删除 spec-first 管理的宿主 runtime assets,不卸载 npm 包或插件。它不会删除 docs/brainstorms/、docs/plans/、docs/tasks/、docs/solutions/,也不修改 .gitignore。workspace orphan 默认只预览,追加 --confirm 才删除。执行前建议先看 git status。
tasks hash
spec-first tasks hash docs/plans/<plan>.md计算 source plan 的 canonical body hash。spec-write-tasks 派生 task pack 时用这个 hash 保持可追溯。
tasks validate
spec-first tasks validate docs/tasks/<task-pack>.md --repo .验证 task pack 的身份、与 source plan 的关系和 hash、task contract 的结构字段,以及 repo-relative path、dependencies、wave、stop_if 等基础约束。
它不判断任务拆分是否合理、方案是否最优或代码能否合并,这些由 spec-doc-review、spec-work 和 spec-code-review 负责。
plans audit
spec-first plans audit
spec-first plans audit --status completed --json只读扫描 docs/plans/*.md,盘点计划的生命周期字段(active、partially-shipped、completed、superseded)。completed 只表示文件里的状态标记,不证明测试、合并或发布已经完成。
session
spec-first session register [--id <id>] [--json]
spec-first session list [--json]可选的多 actor 协作提示。会话记录写到 .spec-first/sessions/<id>.json,只说明“这个 worktree 上是否还有其他 agent 在工作”,不是锁、审批或任务进度。记录超过 24 小时没有 heartbeat 会被视为过期。普通使用不需要手工维护。
repair-worktree
spec-first repair-worktree --dry-run预览失效 worktree 指针的修复指引。只有工作流或错误提示明确要求时才需要运行。
常见错误
| 症状 | 处理 |
|---|---|
spec-first: command not found | 检查全局 npm bin 是否在 PATH,或改用 npx -y spec-first@latest --help |
非 TTY 中运行 init 失败 | 使用 spec-first init -y,并按需指定宿主、-u、--lang |
doctor 显示 not_verified | 重新运行 spec-first init 并重启宿主 |
update 提示已跳过升级 | 当前副本不是 npm 全局安装;按提示用原来的安装方式升级 |
| 找不到工作流入口 | 确认已在仓库根目录 init,并已重启宿主;用 spec-first doctor --<host> 检查 |
下一步
- 快速开始:从安装到第一个工作流
- 工作流命令总览:宿主内的 16 个公开工作流
- 深入解析地图:CLI、runtime 与证据边界
- 产物目录与 Git 边界:CLI 和工作流会写哪些文件
