A complete, agent-agnostic scaffold for building software autonomously with a test-gated agent loop.
Progress lives in files and git, not in the model's context window. Each iteration starts fresh; the agent re-derives state by reading the spec, plan, and code. One task per iteration. The gate is truth.
This template was distilled from the LibreDB build β an embedded, FoundationDB-style multi-model database built mostly autonomously with ~200 tests at full coverage β and aligned with current research on long-running agents:
- Recursive Language Models (RLM) β context as an external environment; programmatic decomposition
- RLM paper (arXiv)
- LangChain Dynamic Subagents β orchestration as code (
task(), loops,Promise.all) - Claude Code Dynamic Workflows β scripts that fan out subagents at scale
- Claude Code Workflows docs
- Cursor: Scaling long-running autonomous coding β planner/worker separation, fresh context per cycle
- Claude Code Agent Teams β subagent definitions for specialized teammates
This template is the reference method of the Open-Spek
standard: it is the machinery that turns a Spek β the
complete knowledge required to create software β into a verified implementation. The first
end-to-end proof is open-spek/jsonq: a type-safe JSON
query engine whose every line was generated by this loop from a frozen Spek (252 tests,
100 percent coverage), with the full friction log preserved in its
loop/TEMPLATE-FEEDBACK.md.
| Layer | Purpose |
|---|---|
| Human inputs | Frozen spec, manifesto, design, toolchain, phases, acceptance criteria |
| Loop machinery | Prompt, plan, progress log, runner script, completion marker |
| Guardrails | Honesty contract, TDD gate, one-task-per-iteration, no interactive pauses |
| Scale patterns | Dynamic workflows / subagents for fan-out inside a milestone (optional) |
The template contains no application code β only documentation, placeholders, and scripts that drive the agent.
./loop/scripts/scaffold.sh /path/to/my-new-project "My Project"
cd /path/to/my-new-project
git init && git add . && git commit -m "chore: initialize loop engineering scaffold"Complete the checklist in docs/SETUP-CHECKLIST.md. At minimum:
- Write
MANIFESTO.mdβ what the project is and refuses to be - Lock
docs/DESIGN.mdβ engineering decisions and acceptance criteria - Choose toolchain and define the gate in
docs/TOOLCHAIN.md - Copy and fill
CLAUDE.md(orAGENTS.mdfor other agents) - Run planning mode once to produce
loop/IMPLEMENTATION_PLAN.md - Set milestone acceptance criteria in
loop/ACCEPTANCE.md
cp loop/config/loop.env.example loop/config/loop.env
# Edit: AGENT_CMD, GATE_CMD, COMPLETION_SENTINEL, etc.# Sandbox strongly recommended (Docker, clean branch, no uncommitted human edits)
./loop/scripts/loop.sh 50Watch the first 5β10 iterations closely. Steer by inputs (prompt, spec, plan), not by hand-fixing agent output.
When .loop/COMPLETE appears and you verify the gate yourself:
- Tag or merge the milestone
- Update
HANDOFF.md, regenerateIMPLEMENTATION_PLAN.mdfor the next phase - Update
loop/ACCEPTANCE.mdandloop/config/loop.envcompletion sentinel - Run the loop again
.
βββ README.md β you are here
βββ CLAUDE.md.template β copy to CLAUDE.md (Claude Code)
βββ AGENTS.md.template β copy to AGENTS.md (other coding agents)
βββ MANIFESTO.md.template β copy to MANIFESTO.md
βββ docs/
β βββ DESIGN.md.template β copy to docs/DESIGN.md
β βββ TOOLCHAIN.md.template β copy to docs/TOOLCHAIN.md
β βββ ARCHITECTURE.md.template β optional; grows with the project
β βββ BRAINSTORM.md.template β human brainstorm before DESIGN.md
β βββ MILESTONE-PLAYBOOK.md β human workflow between loop runs
β βββ SETUP-CHECKLIST.md β human pre-flight checklist
βββ loop/
β βββ LOOP-ENGINEERING.md β full operating manual (read before running)
β βββ PROMPT.md.template β build-mode iteration prompt
β βββ PROMPT-PLANNING.md.template β planning-mode prompt
β βββ IMPLEMENTATION_PLAN.md.template
β βββ PROGRESS.md.template
β βββ HANDOFF.md.template
β βββ ACCEPTANCE.md.template
β βββ TEMPLATE-FEEDBACK.md.template β human-owned friction log (feeds this template)
β βββ config/loop.env.example
β βββ scripts/
β βββ loop.sh β generic agent loop runner
β βββ gate.sh.example β gate script template
β βββ scaffold.sh β copy template into new project
βββ .claude/
β βββ workflows/README.md β when to use dynamic workflows inside a milestone
β βββ agents/*.template β subagent role definitions
βββ examples/README.md β the reference builds (jsonq, LibreDB)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HUMAN (between milestones) β
β brainstorm β manifesto β design β toolchain β phases β
β β acceptance criteria β implementation plan β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β frozen inputs
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LOOP (within a milestone) β
β fresh context β orient β ONE task β TDD β gate β commit β
β β tick plan β log progress β exit β repeat β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β optional, inside hard tasks
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DYNAMIC WORKFLOWS / SUBAGENTS (RLM-style fan-out) β
β agent writes orchestration script β task() per unit β
β β synthesize β return result to iteration β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Loop Engineering predates Open-Spek β it was distilled from the LibreDB build β and it runs without a complete Spek: the human input above only needs to be a locked design, not a ratified Spek. Open-Spek later adopted this template as its reference method, not because the loop is Open-Spek, but because a ratified Spek plus this loop produced jsonq as the standard's first proof. The two compose; neither requires the other.
You engineer the inputs and the environment; the loop does the keystrokes.
Status: Claude Code is the only supported runner today. The non-Claude paths below are the intended design, not the working state β see
docs/AGENT-AGNOSTIC.mdfor confirmed defects, the fix plan, and the acceptance bar before other agents are supported.
The runner defaults to Claude Code (claude -p). Configure AGENT_CMD in loop/config/loop.env for others:
| Agent | Typical invocation | Notes |
|---|---|---|
| Claude Code | claude -p |
--dangerously-skip-permissions for unattended runs |
| Cursor Agent | cursor agent or IDE-driven |
Use same PROMPT.md; run iterations manually or via automation |
| Codex CLI | project-specific | Map to equivalent non-interactive prompt flag |
| Gemini CLI | project-specific | Ensure fresh process per iteration |
| OpenCode / others | project-specific | Same file layout; swap AGENT_CMD |
Requirements for any agent:
- Fresh context per iteration (new process, not accumulated chat)
- Non-interactive mode for unattended runs
- Tool access to read/write files, run shell (gate), git commit
- Optional: workflow/subagent support for fan-out patterns
- Run on a dedicated branch in a clean working tree
- Never edit the repo while the loop runs β pause first
- Use iteration caps and budget limits
- Keep the per-iteration timeout (
LOOP_ITERATION_TIMEOUT) β hung agent processes (e.g. usage limits mid-iteration) are otherwise invisible to the runner - Block destructive tools (
rm, force push) in agent config - Prefer Docker / sandbox for
--dangerously-skip-permissionsequivalents - Completion is a marker file (
.loop/COMPLETE), never grep of prose
MIT β use freely. Attribution appreciated but not required.