Back to Catalog
Agentic AI
Planning & Control Flow
Spec-Driven Loop
Run the same prompt against a fixed spec in a deterministic outer loop until the spec is satisfied.
Intent & Description
🎯 Intent
Run the same prompt against a fixed spec in a deterministic outer loop until the spec is satisfied.
📋 Context
A team works on a task with a clear or steadily-improvable specification — a long bug-fix list, a feature build that decomposes into small chunks, a migration whose end state is well-defined. Each iteration can move the codebase a little closer to the spec without trying to land everything at once. The team has a test suite or similar gate that can tell whether the spec has been satisfied.
💡 Solution
- An outer shell loop (
while :; do cat PROMPT.md | claude-code; done) runs the same prompt repeatedly. - The prompt encodes one task at a time, references a fix_plan.md that the agent itself updates, and ends with a test invocation that gates the next iteration. - Sub-agents are used for parallel reads; build/test stays serial.
Real-world Use Case
- A task has a clear (or improvable) spec and incremental iteration adds value.
- Each iteration’s output can be gated by a test or check.
- An outer shell loop can run the same prompt repeatedly without supervision.
Source
Advantages
- Brutally simple; no orchestration framework required.
- Self-improving in practice as the agent updates the spec it learns.
Disadvantages
- Easy to burn tokens on the wrong shape if the spec is underspecified.
- Hard to share state between iterations beyond what the agent writes to disk.