SpecClaw — Spec-Driven Development
Overview
SpecClaw brings structured, spec-driven development to OpenClaw agents. It manages the full lifecycle: propose → plan → build → verify → archive.
Directory Structure
When initialized (.specclaw/ exists in project root):
CODEBLOCK0
Commands
The user triggers commands conversationally. Recognize these patterns:
specclaw init
Trigger: "specclaw init", "initialize specclaw", "set up spec-driven development"
- 1. Create
.specclaw/ directory structure - Generate
config.yaml from template (see templates/config.yaml) - Ask user for project name/description
- Create initial INLINECODE5
- Add
.specclaw/ tracking to git
specclaw propose "<idea>"
Trigger: "specclaw propose", "propose a change", "new feature proposal"
- 1. Create INLINECODE8
- Generate
proposal.md from template - Include: problem statement, proposed solution, scope, impact, open questions
- Present proposal to user for review
- Update INLINECODE10
- GitHub sync (if
github.sync is true): Run bash skill/scripts/gh-sync.sh create .specclaw <change> to create a GitHub Issue for the proposal. (gh-sync.sh create requires proposal.md — validation is enforced by validate-change.sh.)
specclaw plan <change>
Trigger: "specclaw plan", "plan the feature", "generate spec for"
- 1. Validate: Run
bash skill/scripts/validate-change.sh .specclaw <change> plan. If it fails, report missing prerequisites and stop. - Read the proposal
- Analyze existing codebase (file structure, patterns, dependencies)
- Generate:
-
spec.md — functional requirements, acceptance criteria, edge cases
-
design.md — technical approach, architecture, file changes map
-
tasks.md — ordered implementation tasks with dependencies
- 5. Present plan summary to user
- Update status
- GitHub sync (if enabled): Run
bash skill/scripts/gh-sync.sh update .specclaw <change> to add the task checklist to the GitHub Issue.
specclaw build <change>
Trigger: "specclaw build", "implement the feature", "start building"
This is where OpenClaw shines. Follow this execution flow exactly:
Step 0 — Validate
Run bash skill/scripts/validate-change.sh .specclaw <change> build. If it fails, report missing prerequisites and stop.
Step 1 — Setup
Run the setup script to parse config, create a git branch, and get build configuration:
CODEBLOCK1
This returns JSON config including parallel_tasks, models.coding, git.strategy, and notifications.channel. Capture this output — you'll need parallel_tasks and model values throughout the build.
Worktree strategy: When git.strategy is "worktree-per-change", setup creates an isolated worktree at .specclaw/worktrees/<change>/. The worktree_path from the config JSON should be used as the cwd parameter when spawning coding agents via sessions_spawn, ensuring each change's agents work in complete isolation.
Parallel changes: With worktree-per-change strategy, multiple changes can be built simultaneously since each has its own worktree. No branch switching required.
Send a build started notification:
CODEBLOCK2
Step 2 — Parse Tasks
Get all actionable tasks:
CODEBLOCK3
This outputs JSON: INLINECODE34
For retries (re-running build on a change with prior failures):
CODEBLOCK4
Reset failed tasks to pending before re-executing:
CODEBLOCK5
Then re-parse with --status pending and continue from the appropriate wave.
Step 3 — Wave Loop
Execute tasks wave-by-wave. For each wave number (1, 2, 3...):
a. Filter tasks for this wave:
CODEBLOCK6
If no tasks returned for this wave, the build is complete — skip to Step 4.
Skip waves with blocked tasks: If a task's dependency failed in a prior wave, skip it and mark it failed:
CODEBLOCK7
b. For each task in the wave (up to parallel_tasks from config):
- 1. Mark in-progress:
CODEBLOCK8
- 2. Build context payload:
bash skill/scripts/build-context.sh .specclaw <change> <TASK_ID>
This outputs a complete context string containing: spec sections, design sections, task details, relevant source file contents, and constraints. Use this output directly as the agent's task.
- 3. Spawn coding agent:
CODEBLOCK10
c. Yield and wait:
After spawning all tasks in the wave batch, call sessions_yield to wait for agent completions. Results auto-announce back to you.
d. Process completed agents:
For each agent that succeeded:
- 1. Mark complete:
CODEBLOCK11
If this task previously failed (was [!] before): Run INLINECODE39
- 2. Git commit the changes:
CODEBLOCK12
- 3. Send a task complete notification:
CODEBLOCK13
e. Process failed agents:
For each agent that failed:
- 1. Mark failed:
CODEBLOCK14
- 2. Log error: Run
bash skill/scripts/log-error.sh .specclaw <change> <task_id> <wave> <agent_label> "<failure summary>" — pipe agent error output if available
- 3. Log the error in
status.md with the failure reason
- 4. Send a task failed notification:
CODEBLOCK15
- 5. Mark all dependent tasks in later waves as skipped/failed — they cannot proceed
- GitHub sync (if enabled): Run
bash skill/scripts/gh-sync.sh comment .specclaw <change> "❌ Task <task_id> failed: <summary>" to log the error on the issue.
f. GitHub sync (if enabled): Run bash skill/scripts/gh-sync.sh update .specclaw <change> to update task checkboxes.
g. Repeat for the next wave number until no pending tasks remain.
Step 4 — Finalize
Run the finalize script to execute tests and merge the branch:
CODEBLOCK16
This runs the configured test_command (if any) and merges the branch per git.strategy.
Step 5 — Post-Build Review
If automation.post_build_review is true in config, run an automated review before updating the dashboard:
a. Scope deviation check:
Compare files actually changed against files declared in tasks:
CODEBLOCK17
Cross-reference with files listed in each task in tasks.md. Flag any files changed but not declared in any task's Files: field.
b. Review prompt:
Evaluate the build and auto-log findings (~150 words max):
CODEBLOCK18
c. Auto-log scope deviations:
For any files changed outside declared task scope, automatically log as design_gap:
CODEBLOCK19
d. Pattern scan: Run bash skill/scripts/detect-patterns.sh .specclaw scan <change> to check for recurring patterns across changes.
e. If any patterns have recurrence >= 3, alert the user: "⚠️ Pattern PAT-XXX has N occurrences — consider promoting its prevention rule to agent context."
Step 6 — Update Dashboard
Regenerate the project status dashboard:
CODEBLOCK20
Step 7 — Notify
Send the build summary via the message tool to the configured notification channel:
CODEBLOCK21
If any tasks failed, include a remediation section:
CODEBLOCK22
Retry Flow
When specclaw build is called on a change that has failed tasks:
- 1. Parse failed tasks: INLINECODE54
- Reset each to pending: INLINECODE55
- Re-parse pending tasks and determine which waves need re-execution
- Execute only the waves containing reset tasks (and their dependents)
- Retried tasks automatically get previous error context via
build-context.sh
- 5. Finalize and notify as normal
Key Principles
- - Fresh context always — each agent gets ONLY what it needs via
build-context.sh. No stale context from prior tasks. This is critical for quality. - Parallel within waves — tasks in the same wave with no cross-dependencies spawn simultaneously, up to
parallel_tasks limit. - Sequential across waves — wave N+1 starts only after wave N completes.
- Fail-fast on dependencies — if a task fails, all tasks depending on it are immediately marked failed.
specclaw learn <change> "<insight>"
Trigger: "specclaw learn", "log a learning", "what did we learn", "capture insight"
Capture build learnings — spec gaps, design misses, and patterns discovered during implementation.
Log a learning:
CODEBLOCK23
Categories: spec_gap | design_gap | pattern | best_practice | agent_issue
Priorities: low | medium | INLINECODE67
List learnings for a change:
CODEBLOCK24
Promote a learning (mark for elevation to agent prompts/SKILL.md):
CODEBLOCK25
When to log:
- - After a build reveals a spec gap (requirements were unclear or missing)
- When a design decision needed mid-build adjustment
- When agents discovered a useful pattern worth reusing
- When parallel tasks created conflicts (duplicate code, shared dependencies)
- When an agent struggled with the context or instructions
Learnings are stored in .specclaw/changes/<change>/learnings.md and feed into the pattern detection system for cross-change analysis.
specclaw patterns
Trigger: "specclaw patterns", "check patterns", "recurring issues", "what keeps happening"
Track recurring patterns across changes — errors and learnings that repeat become prevention rules.
Scan a change for patterns:
bash skill/scripts/detect-patterns.sh .specclaw scan <change>
Reads errors.md and learnings.md, matches against existing patterns, creates new or increments existing.
List all patterns:
CODEBLOCK27
Promote a pattern (mark for elevation to agent prompts):
CODEBLOCK28
Auto-promotion: Patterns with 3+ occurrences are flagged ⚠️ — their prevention rules should be added to agent context templates or SKILL.md build instructions.
Pattern registry lives at .specclaw/patterns.md (global, not per-change).
specclaw verify <change>
Trigger: "specclaw verify", "validate implementation", "check against spec"
Validate that the implementation satisfies the spec's acceptance criteria.
Step 0: Validate
Run bash skill/scripts/validate-change.sh .specclaw <change> verify. If it fails (tasks not all complete), report and stop.
Step 1: Collect Evidence
Run bash skill/scripts/verify.sh collect .specclaw <change> to gather:
- - Acceptance criteria from spec.md
- Current content of all changed files
- Test/lint/build command results (if configured)
Step 2: Build Verify Context
Run bash skill/scripts/verify-context.sh .specclaw <change> to construct the verification agent's context payload from the evidence + Verify Agent prompt template.
Step 3: Spawn Verify Agent
Spawn a verification agent:
sessions_spawn(
task: <verify context payload>,
model: <config.yaml models.review>, # default: anthropic/claude-sonnet-4-5
mode: "run",
label: "specclaw-verify-<change>"
)
Wait for completion via
sessions_yield.
Step 4: Save Report
Save the agent's output as .specclaw/changes/<change>/verify-report.md.
Step 5: Update Status
Run bash skill/scripts/verify.sh update-status .specclaw <change> <verdict> where verdict is PASS, FAIL, or PARTIAL (extracted from the report).
Update status.md and run bash skill/scripts/update-status.sh .specclaw to refresh the dashboard.
Step 6: GitHub Sync (if enabled)
If github.sync is true, post verification summary as a comment:
INLINECODE80
Step 7: Notify
Send verification results via configured notification channel.
Auto-Verify
When automation.auto_verify: true in config.yaml, the build flow automatically triggers verification after a successful build (all tasks complete).
Remediation
If verdict is FAIL or PARTIAL:
- 1. List the failed acceptance criteria
- Suggest creating remediation tasks (new tasks targeting the gaps)
- The user can re-plan just the failed criteria or manually fix and re-verify
specclaw status
Trigger: "specclaw status", "project status", "what's the progress"
For a specific change: INLINECODE83
- 1. Read all changes in INLINECODE84
- Compile dashboard showing:
- Active changes with progress %
- Pending proposals
- Recently archived
- Overall project health
- 3. Update INLINECODE85
specclaw archive <change>
Trigger: "specclaw archive", "mark as done", "archive the change"
- 1. Validate: Run
bash skill/scripts/validate-change.sh .specclaw <change> archive. If it fails, report and stop. - Verify change is complete (all tasks done, verification passed)
- Move to INLINECODE88
- Update INLINECODE89
- GitHub sync (if enabled): Run
bash skill/scripts/gh-sync.sh close .specclaw <change> to close the issue. - Optionally create git tag
specclaw auto
Trigger: "specclaw auto", "autonomous mode", "auto-build"
- 1. Check
STATUS.md for next actionable item - If proposal exists without plan → generate plan
- If plan exists without implementation → build
- If built without verification → verify
- Respect
config.yaml limits (maxtasksper_run) - Notify user of results
Task Format in tasks.md
CODEBLOCK30
Status markers:
- -
[ ] — pending - INLINECODE95 — in progress
- INLINECODE96 — complete
- INLINECODE97 — failed (needs remediation)
Agent Context Preparation
Context construction is handled by the build-context.sh script:
CODEBLOCK31
The script automatically assembles a complete context payload containing:
- 1. Task header — task ID, title, and estimate
- Spec context — relevant sections from
spec.md (requirements, acceptance criteria) - Design context — relevant sections from
design.md (architecture, approach) - Task details — full task description, file list, and dependencies from INLINECODE101
- Source files — current contents of files listed in the task's
Files: field - Constraints — standard rules (follow patterns, write tests, stay in scope)
The output is a single string ready to pass directly as the task parameter to sessions_spawn. Do not manually construct context — always use the script to ensure consistency and freshness.
Configuration Reference
See templates/config.yaml for the full config schema.
Key settings:
- -
models.planning — model for proposals, specs, design (default: opus) - INLINECODE107 — model for implementation (default: codex)
- INLINECODE108 — model for verification (default: sonnet)
- INLINECODE109 — "branch-per-change", "direct", or "worktree-per-change"
- INLINECODE110 — where to send updates
- INLINECODE111 — limit for auto mode
Best Practices
- 1. Keep proposals focused — one change per proposal, small scope
- Review specs before building — garbage in, garbage out
- Wave-based execution — group independent tasks, respect dependencies
- Fresh context always — never let agents accumulate stale context
- Verify early — run verification after each wave, not just at the end
GitHub Integration (Optional)
When github.sync: true in config.yaml, SpecClaw creates a GitHub Issue per change and tracks progress as a task checklist. Requires gh CLI (authenticated) or GITHUB_TOKEN environment variable.
Run bash skill/scripts/gh-sync.sh setup to verify auth and create labels.
SpecClaw — 规范驱动开发
概述
SpecClaw 为 OpenClaw 智能体带来结构化、规范驱动的开发流程。它管理完整的生命周期:提议 → 规划 → 构建 → 验证 → 归档。
目录结构
初始化后(项目根目录存在 .specclaw/):
.specclaw/
├── config.yaml # 项目配置
├── STATUS.md # 项目仪表盘(自动生成)
├── patterns.md # 重复模式注册表(跨变更)
└── changes/
├── <变更名称>/
│ ├── proposal.md # 问题 + 解决方案 + 范围
│ ├── spec.md # 需求 + 验收标准
│ ├── design.md # 技术方案 + 文件映射
│ ├── tasks.md # 带状态标记的有序任务
│ ├── status.md # 进度跟踪
│ ├── errors.md # 构建错误日志(失败时自动生成)
│ ├── learnings.md # 构建经验(规范缺口、模式、洞察)
│ └── verify-report.md # 验证结果(自动生成)
└── archive/ # 已完成的变更
命令
用户通过对话触发命令。识别以下模式:
specclaw init
触发词: specclaw init, initialize specclaw, set up spec-driven development
- 1. 创建 .specclaw/ 目录结构
- 从模板生成 config.yaml(参见 templates/config.yaml)
- 询问用户项目名称/描述
- 创建初始 STATUS.md
- 将 .specclaw/ 添加到 git 跟踪
specclaw propose <想法>
触发词: specclaw propose, propose a change, new feature proposal
- 1. 创建 .specclaw/changes/<短横线格式名称>/
- 从模板生成 proposal.md
- 包含:问题陈述、建议解决方案、范围、影响、未解决问题
- 向用户展示提议以供审阅
- 更新 STATUS.md
- GitHub 同步(如果 github.sync 为 true):运行 bash skill/scripts/gh-sync.sh create .specclaw 为提议创建 GitHub Issue。(gh-sync.sh create 需要 proposal.md — validate-change.sh 会强制执行验证。)
specclaw plan <变更>
触发词: specclaw plan, plan the feature, generate spec for
- 1. 验证: 运行 bash skill/scripts/validate-change.sh .specclaw plan。如果失败,报告缺少的先决条件并停止。
- 读取提议
- 分析现有代码库(文件结构、模式、依赖关系)
- 生成:
- spec.md — 功能需求、验收标准、边界情况
- design.md — 技术方案、架构、文件变更映射
- tasks.md — 带依赖关系的有序实现任务
- 5. 向用户展示规划摘要
- 更新状态
- GitHub 同步(如果启用):运行 bash skill/scripts/gh-sync.sh update .specclaw 将任务清单添加到 GitHub Issue。
specclaw build <变更>
触发词: specclaw build, implement the feature, start building
这是 OpenClaw 大显身手的地方。 严格遵循以下执行流程:
第 0 步 — 验证
运行 bash skill/scripts/validate-change.sh .specclaw build。如果失败,报告缺少的先决条件并停止。
第 1 步 — 设置
运行设置脚本以解析配置、创建 git 分支并获取构建配置:
bash
bash skill/scripts/build.sh setup .specclaw
返回包含 paralleltasks、models.coding、git.strategy 和 notifications.channel 的 JSON 配置。捕获此输出 — 在整个构建过程中需要 paralleltasks 和 model 值。
工作树策略: 当 git.strategy 为 worktree-per-change 时,设置会在 .specclaw/worktrees// 创建一个隔离的工作树。配置 JSON 中的 worktreepath 应作为通过 sessionsspawn 生成编码智能体时的 cwd 参数,确保每个变更的智能体在完全隔离的环境中工作。
并行变更: 使用 worktree-per-change 策略时,由于每个变更都有自己的工作树,可以同时构建多个变更。无需切换分支。
发送构建开始通知:
🦞 构建开始
变更:
分支: specclaw/
任务: <总数> 个任务,共 <波次数> 波
第 2 步 — 解析任务
获取所有可执行任务:
bash
bash skill/scripts/parse-tasks.sh --status pending .specclaw/changes//tasks.md
输出 JSON:[{id: T1, title: ..., wave: 1, depends: [], files: [...], estimate: small}, ...]
对于重试(在先前有失败的变更上重新运行构建):
bash
bash skill/scripts/parse-tasks.sh --status failed .specclaw/changes//tasks.md
在重新执行前将失败任务重置为待处理:
bash
bash skill/scripts/update-task-status.sh .specclaw/changes//tasks.md pending
然后使用 --status pending 重新解析,并从适当的波次继续。
第 3 步 — 波次循环
逐波执行任务。对于每个波次编号(1, 2, 3...):
a. 过滤此波次的任务:
bash
bash skill/scripts/parse-tasks.sh --wave N --status pending .specclaw/changes//tasks.md
如果此波次没有返回任务,则构建完成 — 跳到第 4 步。
跳过有阻塞任务的任务: 如果某个任务的依赖项在先前的波次中失败,则跳过它并将其标记为失败:
bash
bash skill/scripts/update-task-status.sh .specclaw/changes//tasks.md failed
b. 对于波次中的每个任务(最多 parallel_tasks 个,来自配置):
- 1. 标记进行中:
bash
bash skill/scripts/update-task-status.sh .specclaw/changes/
/tasks.md ID> inprogress
- 2. 构建上下文负载:
bash
bash skill/scripts/build-context.sh .specclaw
输出包含以下内容的完整上下文字符串:规范章节、设计章节、任务详情、相关源文件内容和约束。直接使用此输出作为智能体的任务。
- 3. 生成编码智能体:
sessions_spawn(
task: ,
label: specclaw--,
mode: run,
model: <配置中的 models.coding>
)
c. 让出并等待:
生成波次批次中的所有任务后,调用 sessions_yield 等待智能体完成。结果会自动返回给您。
d. 处理完成的智能体:
对于每个成功的智能体:
- 1. 标记完成:
bash
bash skill/scripts/update-task-status.sh .specclaw/changes//tasks.md complete
如果此任务先前失败(之前为 [!]):运行 bash skill/scripts/log-error.sh .specclaw --resolve
- 2. Git 提交变更:
bash
bash skill/scripts/build.sh commit .specclaw ID> title>
- 3. 发送任务完成通知:
✅ 任务完成: ID> — title>
变更: name> | 波次: /waves>
e. 处理失败的智能体:
对于每个失败的智能体:
- 1. 标记失败:
bash
bash skill/scripts/update-task-status.sh .specclaw/changes//tasks.md failed
- 2. 记录错误: 运行 bash skill/scripts/log-error.sh .specclaw id> label> —