Autonomous Loops Skill
Compatibility note (v1.8.0):
autonomous-loopsis retained for one release. The canonical skill name is nowcontinuous-agent-loop. New loop guidance should be authored there, while this skill remains available to avoid breaking existing workflows.
Patterns, architectures, and reference implementations for running Claude Code autonomously in loops. Covers everything from simple claude -p pipelines to full RFC-driven multi-agent DAG orchestration.
When to Use
- Setting up autonomous development workflows that run without human intervention
- Choosing the right loop architecture for your problem (simple vs complex)
- Building CI/CD-style continuous development pipelines
- Running parallel agents with merge coordination
- Implementing context persistence across loop iterations
- Adding quality gates and cleanup passes to autonomous workflows
Loop Pattern Spectrum
From simplest to most sophisticated:
1. Sequential Pipeline (claude -p)
The simplest loop. Break daily development into a sequence of non-interactive claude -p calls. Each call is a focused step with a clear prompt.
Core Insight
If you can't figure out a loop like this, it means you can't even drive the LLM to fix your code in interactive mode.
The claude -p flag runs Claude Code non-interactively with a prompt, exits when done. Chain calls to build a pipeline:
Key Design Principles
- Each step is isolated — A fresh context window per
claude -pcall means no context bleed between steps. - Order matters — Steps execute sequentially. Each builds on the filesystem state left by the previous.
- Negative instructions are dangerous — Don't say "don't test type systems." Instead, add a separate cleanup step (see De-Sloppify Pattern).
- Exit codes propagate —
set -estops the pipeline on failure.
Variations
With model routing:
With environment context:
With --allowedTools restrictions:
2. NanoClaw REPL
ECC's built-in persistent loop. A session-aware REPL that calls claude -p synchronously with full conversation history.
How It Works
- Loads conversation history from
~/.claude/claw/{session}.md - Each user message is sent to
claude -pwith full history as context - Responses are appended to the session file (Markdown-as-database)
- Sessions persist across restarts
When NanoClaw vs Sequential Pipeline
See the /claw command documentation for full details.
3. Infinite Agentic Loop
A two-prompt system that orchestrates parallel sub-agents for specification-driven generation. Developed by disler (credit: @disler).
Architecture: Two-Prompt System
The Pattern
- Spec Analysis — Orchestrator reads a specification file (Markdown) defining what to generate
- Directory Recon — Scans existing output to find the highest iteration number
- Parallel Deployment — Launches N sub-agents, each with:
- The full spec
- A unique creative direction
- A specific iteration number (no conflicts)
- A snapshot of existing iterations (for uniqueness)
- Wave Management — For infinite mode, deploys waves of 3-5 agents until context is exhausted
Implementation via Claude Code Commands
Create .claude/commands/infinite.md:
Invoke:
Batching Strategy
Key Insight: Uniqueness via Assignment
Don't rely on agents to self-differentiate. The orchestrator assigns each agent a specific creative direction and iteration number. This prevents duplicate concepts across parallel agents.
4. Continuous Claude PR Loop
A production-grade shell script that runs Claude Code in a continuous loop, creating PRs, waiting for CI, and merging automatically. Created by AnandChowdhary (credit: @AnandChowdhary).
Core Loop
Installation
Warning: Install continuous-claude from its repository after reviewing the code. Do not pipe external scripts directly to bash.
Usage
Cross-Iteration Context: SHARED_TASK_NOTES.md
The critical innovation: a SHARED_TASK_NOTES.md file persists across iterations:
Claude reads this file at iteration start and updates it at iteration end. This bridges the context gap between independent claude -p invocations.
CI Failure Recovery
When PR checks fail, Continuous Claude automatically:
- Fetches the failed run ID via
gh run list - Spawns a new
claude -pwith CI fix context - Claude inspects logs via
gh run view, fixes code, commits, pushes - Re-waits for checks (up to
--ci-retry-maxattempts)
Completion Signal
Claude can signal "I'm done" by outputting a magic phrase:
Three consecutive iterations signaling completion stops the loop, preventing wasted runs on finished work.
Key Configuration
5. The De-Sloppify Pattern
An add-on pattern for any loop. Add a dedicated cleanup/refactor step after each Implementer step.
The Problem
When you ask an LLM to implement with TDD, it takes "write tests" too literally:
- Tests that verify TypeScript's type system works (testing
typeof x === 'string') - Overly defensive runtime checks for things the type system already guarantees
- Tests for framework behavior rather than business logic
- Excessive error handling that obscures the actual code
Why Not Negative Instructions?
Adding "don't test type systems" or "don't add unnecessary checks" to the Implementer prompt has downstream effects:
- The model becomes hesitant about ALL testing
- It skips legitimate edge case tests
- Quality degrades unpredictably
The Solution: Separate Pass
Instead of constraining the Implementer, let it be thorough. Then add a focused cleanup agent:
In a Loop Context
Key Insight
Rather than adding negative instructions which have downstream quality effects, add a separate de-sloppify pass. Two focused agents outperform one constrained agent.
6. Ralphinho / RFC-Driven DAG Orchestration
The most sophisticated pattern. An RFC-driven, multi-agent pipeline that decomposes a spec into a dependency DAG, runs each unit through a tiered quality pipeline, and lands them via an agent-driven merge queue. Created by enitrat (credit: @enitrat).
Architecture Overview
RFC Decomposition
AI reads the RFC and produces work units:
Decomposition Rules:
- Prefer fewer, cohesive units (minimize merge risk)
- Minimize cross-unit file overlap (avoid conflicts)
- Keep tests WITH implementation (never separate "implement X" + "test X")
- Dependencies only where real code dependency exists
The dependency DAG determines execution order:
Complexity Tiers
Different tiers get different pipeline depths:
This prevents expensive operations on simple changes while ensuring architectural changes get thorough scrutiny.
Separate Context Windows (Author-Bias Elimination)
Each stage runs in its own agent process with its own context window:
Critical design: The reviewer never wrote the code it reviews. This eliminates author bias — the most common source of missed issues in self-review.
Merge Queue with Eviction
After quality pipelines complete, units enter the merge queue:
File Overlap Intelligence:
- Non-overlapping units land speculatively in parallel
- Overlapping units land one-by-one, rebasing each time
Eviction Recovery: When evicted, full context is captured (conflicting files, diffs, test output) and fed back to the implementer on the next Ralph pass:
Data Flow Between Stages
Worktree Isolation
Every unit runs in an isolated worktree (uses jj/Jujutsu, not git):
Pipeline stages for the same unit share a worktree, preserving state (context files, plan files, code changes) across research → plan → implement → test → review.
Key Design Principles
- Deterministic execution — Upfront decomposition locks in parallelism and ordering
- Human review at leverage points — The work plan is the single highest-leverage intervention point
- Separate concerns — Each stage in a separate context window with a separate agent
- Conflict recovery with context — Full eviction context enables intelligent re-runs, not blind retries
- Tier-driven depth — Trivial changes skip research/review; large changes get maximum scrutiny
- Resumable workflows — Full state persisted to SQLite; resume from any point
When to Use Ralphinho vs Simpler Patterns
Choosing the Right Pattern
Decision Matrix
Combining Patterns
These patterns compose well:
-
Sequential Pipeline + De-Sloppify — The most common combination. Every implement step gets a cleanup pass.
-
Continuous Claude + De-Sloppify — Add
--review-promptwith a de-sloppify directive to each iteration. -
Any loop + Verification — Use ECC's
/verifycommand orverification-loopskill as a gate before commits. -
Ralphinho's tiered approach in simpler loops — Even in a sequential pipeline, you can route simple tasks to Haiku and complex tasks to Opus:
Anti-Patterns
Common Mistakes
-
Infinite loops without exit conditions — Always have a max-runs, max-cost, max-duration, or completion signal.
-
No context bridge between iterations — Each
claude -pcall starts fresh. UseSHARED_TASK_NOTES.mdor filesystem state to bridge context. -
Retrying the same failure — If an iteration fails, don't just retry. Capture the error context and feed it to the next attempt.
-
Negative instructions instead of cleanup passes — Don't say "don't do X." Add a separate pass that removes X.
-
All agents in one context window — For complex workflows, separate concerns into different agent processes. The reviewer should never be the author.
-
Ignoring file overlap in parallel work — If two parallel agents might edit the same file, you need a merge strategy (sequential landing, rebase, or conflict resolution).

