Planning & Control Flow

Spec-Driven Loop

Run the same prompt against a fixed spec in a deterministic outer loop until the spec is satisfied.

Problem

Agents that try to plan and implement the whole feature in a single turn are brittle because they have to hold too many decisions in one context and they cannot back out of a bad early commitment. Agents driven from a free-form chat wander, lose their plan, and produce work that is hard to resume after an interruption. Custom orchestration frameworks add their own complexity for what should be a simple loop. The team wants something brutally simple — re-run the agent against the spec until the spec is satisfied — without losing the ability to inspect, pause, and resume.

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. Subagents are used for parallel reads; build/test stays serial.

When to use

  • 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.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related