Spec-driven development on OpenSpec, with mechanical spec-as-source enforcement: a custom 'spec-as-source' OpenSpec schema adds file-ownership (targets) and test-verification ([@test]) metadata to every capability spec, three scripts (link check, ownership check, manifest build) keep code and specs from drifting apart, plus requirement-gathering, spec-writer, work-review, and a session-handoff skill with a proactive context-warning hook.
73
92%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Advisory
Suggest reviewing before use
Drive the apply phase of an active OpenSpec change with a Ralph-style loop: a
shell runner re-invokes a headless agent as a fresh process per iteration,
each iteration implements exactly one task from the change's tasks.md, and
the runner itself re-checks the checklist and scripts/verify.sh after every
iteration. The loop converges only on mechanical evidence — zero unchecked
tasks AND green verification — never on the agent's claim of being done.
Use it for the long, mechanical middle of a change whose tasks are already well-decomposed. Do not use it for tasks that need judgment calls or design decisions: those belong in an interactive session. The phases around the loop stay human-gated — it never proposes, syncs, archives, or reviews.
Both must hold before starting; stop and fix if either fails:
tasks.md exists under openspec/changes/<name>/
(created by openspec-propose). If several changes are active, you must
name one.scripts/verify.sh exists and is executable (installed by
spec-as-source-setup). The loop is meaningless without its gate.Copy this skill's two templates into the project and make the runner executable:
mkdir -p scripts/ralph
cp <skill-dir>/templates/loop.sh scripts/ralph/loop.sh
cp <skill-dir>/templates/LOOP_PROMPT.md scripts/ralph/LOOP_PROMPT.md
cp <skill-dir>/templates/LOOP_FIX_PROMPT.md scripts/ralph/LOOP_FIX_PROMPT.md
chmod +x scripts/ralph/loop.shVerify the executable bit stuck (ls -l scripts/ralph/) — file-write tools
do not set it. If scripts/ralph/ already exists, the runner is installed;
do not overwrite local adaptations without asking.
Everything is an environment variable; nothing needs editing in the script:
| Variable | Default | Meaning |
|---|---|---|
AGENT_CMD | claude -p | Headless agent command; reads the prompt on stdin |
MAX_ITERATIONS | 25 | Hard cap on iterations |
MAX_CONSECUTIVE_FAILURES | 1 | Abort after N no-progress task iterations in a row |
MAX_FIX_ATTEMPTS | 10 | Abort after N consecutive repair iterations that leave verification red |
Verification-repair mode: a red scripts/verify.sh is never walked past.
From the next iteration the runner swaps in LOOP_FIX_PROMPT.md — fix the
code until it satisfies the spec, never touching specs or tasks.md — with
the verification output appended, and returns to task mode only when
verification is green again. Raise MAX_FIX_ATTEMPTS if you want the loop to
be more stubborn before giving the problem back to you.
Permissions trade-off (decide explicitly): the runner never adds
permission-bypass flags to AGENT_CMD. A default headless claude -p will
stall on permission prompts, so you must choose your risk level yourself —
e.g. AGENT_CMD="claude -p --permission-mode acceptEdits" on a trusted
branch, or a fully sandboxed/containerized run for anything stronger. Never
put a bypass flag you would not defend in a review.
First run advice: start small — MAX_ITERATIONS=3 — inspect the logs and
commits, then raise the cap once you trust the prompt discipline on this
project.
From the project root, on a dedicated branch (one commit per completed task will accumulate):
git checkout -b loop/<change-name>
MAX_ITERATIONS=3 bash scripts/ralph/loop.sh <change-name>Per-iteration logs land in scripts/ralph/logs/ (iter-N-agent.log,
iter-N-verify.log).
touch scripts/ralph/STOP — the loop aborts before the
next iteration. Remove the file to allow a new run.iter-N-*.log files;
the usual causes are an under-specified task (fix: split or clarify it in
tasks.md), a permission stall (fix: revisit AGENT_CMD), or a genuinely
red verification (fix interactively, then re-run — completed tasks stay
checked, so the loop resumes where it left off).git log is the audit trail, and a bad
iteration is one git revert away.The loop automates the derived artifact, never the source. It must not run —
and its prompt forbids the in-loop agent from running — openspec-propose,
spec-writer, openspec-sync-specs, openspec-archive-change, or
work-review. When the loop reports success, the change is implemented,
not done: run spec-verify and work-review yourself, then archive.
.tessl-plugin
skills
handoff
handoff-skill
openspec-apply-change
openspec-archive-change
openspec-explore
openspec-propose
openspec-sync-specs
prompt-loop
requirement-gathering
spec-as-source-setup
templates
openspec-schema
spec-as-source
templates
spec-ci-sync
spec-loop
spec-rebuild
spec-verify
spec-writer
work-review