跳到正文

命令行参考 ​

spec-first CLI 负责确定性操作:检查、初始化、升级、清理、task pack 校验和计划审计。研发工作流本身在宿主会话里运行,用 spec-* 入口调用。

Spec-First runtime assets

命令总览 ​

bash
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 仓库根目录打开终端,运行以下命令。

bash
spec-first quickstart

quickstart 检查 Node.js、Git 和已安装的宿主 CLI,再进入 spec-first init。检测到唯一宿主时会自动选中它。未检测到或检测到多个时,由你选择。按提示确认写入后,在同一目录重新打开所选宿主。

-y/--yes 只在恰好检测到一个宿主时跳过交互。检测到零个或多个宿主时,使用该参数会以退出码 2 结束。

doctor ​

bash
spec-first doctor
spec-first doctor --claude
spec-first doctor --json

doctor 只读检查,不需要重新 init:

字段含义
install_healthNode、Git 与 package 级检查
runtime_asset_healthinit 生成的 managed runtime assets 是否完整
host_readiness指定宿主的 CLI、runtime 与项目接入情况
decision_input_health当前为 not_checked;运行环境就绪状态不在这里编译
workflow_runnabilityverified、simulated 或 not_verified

doctor 不安装 MCP servers,也不判断需求或代码质量。--verbose 显示全部检查明细,--json 供脚本消费。运行环境由 spec-runtime-setup 负责。

init ​

bash
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 <zhen>`
--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 ​

bash
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 ​

bash
spec-first clean --claude
spec-first clean --claude --dry-run
spec-first clean --workspace-orphans
spec-first clean --workspace-graph --repos a,b --dry-run

clean 删除 spec-first 管理的宿主 runtime assets,不卸载 npm 包或插件。它不会删除 docs/brainstorms/、docs/plans/、docs/tasks/、docs/solutions/,也不修改 .gitignore。workspace orphan 默认只预览,追加 --confirm 才删除。执行前建议先看 git status。

tasks hash ​

bash
spec-first tasks hash docs/plans/<plan>.md

计算 source plan 的 canonical body hash。spec-write-tasks 派生 task pack 时用这个 hash 保持可追溯。

tasks validate ​

bash
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 ​

bash
spec-first plans audit
spec-first plans audit --status completed --json

只读扫描 docs/plans/*.md,盘点计划的生命周期字段(active、partially-shipped、completed、superseded)。completed 只表示文件里的状态标记,不证明测试、合并或发布已经完成。

session ​

bash
spec-first session register [--id <id>] [--json]
spec-first session list [--json]

可选的多 actor 协作提示。会话记录写到 .spec-first/sessions/<id>.json,只说明“这个 worktree 上是否还有其他 agent 在工作”,不是锁、审批或任务进度。记录超过 24 小时没有 heartbeat 会被视为过期。普通使用不需要手工维护。

repair-worktree ​

bash
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> 检查

下一步 ​