| name | autonomous-loops |
| description | Patterns for autonomous agent loops — sequential pipelines, parallel generation, continuous PR loops, and de-sloppify passes. Use when setting up automated workflows, CI/CD agent loops, batch processing with Claude, or multi-agent orchestration. Covers loop architecture from simple sequential to RFC-driven DAG orchestration. |
Autonomous Loop Patterns
Six loop architectures of increasing sophistication. Pick the simplest one that fits.
1. Sequential Pipeline
Each step is isolated (fresh context). Order matters, exit codes propagate.
claude -p "Implement auth module per spec in PLAN.md" && \
claude -p "Review changes, fix issues, run tests" && \
claude -p "Write commit message, commit"
Use when: Simple linear tasks, each step is independent.
2. De-Sloppify Pipeline
Two focused agents beat one constrained agent.
claude -p "Implement feature X with full TDD"
claude -p "Review all changes. Remove: tests of language behavior, console.logs, dead code, over-engineering. Run test suite."
Use when: Any implementation task. Always follow implementation with cleanup.
3. Parallel Generation
Spawn N agents with different creative directions. Each gets an iteration number to prevent duplicates.
for i in $(seq 1 5); do
claude -p "Iteration $i: Generate solution for X. Be creative, try approach $i." &
done
wait
claude -p "Review all 5 solutions in output/. Pick the best, explain why."
Use when: Creative/exploratory tasks where multiple approaches might work.
4. Continuous PR Loop
Agent runs in a loop: create PR → wait for CI → fix failures → repeat.
Key elements:
SHARED_TASK_NOTES.md bridges context gaps between iterations
- Auto-fix failing CI checks
- Configurable max-runs, max-cost, completion signals
- Merge queue with conflict recovery
Use when: Automated PR workflows, CI-driven development.
5. Spec-Driven DAG Orchestration
Most sophisticated: decompose spec into tiered work units with dependency DAG.
- Each unit runs through quality pipeline in isolated worktree
- Separate context windows per stage (reviewer ≠ author)
- Merge queue with eviction recovery
Use when: Large features with multiple interdependent components.
Decision Flow
Need strict CI/PR control? → Continuous PR loop
Need RFC decomposition? → DAG orchestration
Need exploratory parallel gen? → Parallel generation
Simple linear task? → Sequential pipeline
Any implementation task? → Always add de-sloppify pass
Failure Modes to Watch
- Loop churn without measurable progress → freeze, audit, reduce scope
- Repeated retries with same root cause → investigate, don't retry
- Merge queue stalls → check for dependency cycles
- Cost drift from unbounded escalation → set
--max-budget-usd