$npx -y skills add affaan-m/ECC --skill autonomous-loopsPatterns and architectures for autonomous Claude Code loops — from simple sequential pipelines to RFC-driven multi-agent DAG systems.
| 1 | # Autonomous Loops Skill |
| 2 | |
| 3 | > Compatibility note (v1.8.0): `autonomous-loops` is retained for one release. |
| 4 | > The canonical skill name is now `continuous-agent-loop`. New loop guidance |
| 5 | > should be authored there, while this skill remains available to avoid |
| 6 | > breaking existing workflows. |
| 7 | |
| 8 | 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. |
| 9 | |
| 10 | ## When to Use |
| 11 | |
| 12 | - Setting up autonomous development workflows that run without human intervention |
| 13 | - Choosing the right loop architecture for your problem (simple vs complex) |
| 14 | - Building CI/CD-style continuous development pipelines |
| 15 | - Running parallel agents with merge coordination |
| 16 | - Implementing context persistence across loop iterations |
| 17 | - Adding quality gates and cleanup passes to autonomous workflows |
| 18 | |
| 19 | ## Loop Pattern Spectrum |
| 20 | |
| 21 | From simplest to most sophisticated: |
| 22 | |
| 23 | | Pattern | Complexity | Best For | |
| 24 | |---------|-----------|----------| |
| 25 | | [Sequential Pipeline](#1-sequential-pipeline-claude--p) | Low | Daily dev steps, scripted workflows | |
| 26 | | [NanoClaw REPL](#2-nanoclaw-repl) | Low | Interactive persistent sessions | |
| 27 | | [Infinite Agentic Loop](#3-infinite-agentic-loop) | Medium | Parallel content generation, spec-driven work | |
| 28 | | [Continuous Claude PR Loop](#4-continuous-claude-pr-loop) | Medium | Multi-day iterative projects with CI gates | |
| 29 | | [De-Sloppify Pattern](#5-the-de-sloppify-pattern) | Add-on | Quality cleanup after any Implementer step | |
| 30 | | [Ralphinho / RFC-Driven DAG](#6-ralphinho--rfc-driven-dag-orchestration) | High | Large features, multi-unit parallel work with merge queue | |
| 31 | |
| 32 | --- |
| 33 | |
| 34 | ## 1. Sequential Pipeline (`claude -p`) |
| 35 | |
| 36 | **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. |
| 37 | |
| 38 | ### Core Insight |
| 39 | |
| 40 | > 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. |
| 41 | |
| 42 | The `claude -p` flag runs Claude Code non-interactively with a prompt, exits when done. Chain calls to build a pipeline: |
| 43 | |
| 44 | ```bash |
| 45 | #!/bin/bash |
| 46 | # daily-dev.sh — Sequential pipeline for a feature branch |
| 47 | |
| 48 | set -e |
| 49 | |
| 50 | # Step 1: Implement the feature |
| 51 | claude -p "Read the spec in docs/auth-spec.md. Implement OAuth2 login in src/auth/. Write tests first (TDD). Do NOT create any new documentation files." |
| 52 | |
| 53 | # Step 2: De-sloppify (cleanup pass) |
| 54 | claude -p "Review all files changed by the previous commit. Remove any unnecessary type tests, overly defensive checks, or testing of language features (e.g., testing that TypeScript generics work). Keep real business logic tests. Run the test suite after cleanup." |
| 55 | |
| 56 | # Step 3: Verify |
| 57 | claude -p "Run the full build, lint, type check, and test suite. Fix any failures. Do not add new features." |
| 58 | |
| 59 | # Step 4: Commit |
| 60 | claude -p "Create a conventional commit for all staged changes. Use 'feat: add OAuth2 login flow' as the message." |
| 61 | ``` |
| 62 | |
| 63 | ### Key Design Principles |
| 64 | |
| 65 | 1. **Each step is isolated** — A fresh context window per `claude -p` call means no context bleed between steps. |
| 66 | 2. **Order matters** — Steps execute sequentially. Each builds on the filesystem state left by the previous. |
| 67 | 3. **Negative instructions are dangerous** — Don't say "don't test type systems." Instead, add a separate cleanup step (see [De-Sloppify Pattern](#5-the-de-sloppify-pattern)). |
| 68 | 4. **Exit codes propagate** — `set -e` stops the pipeline on failure. |
| 69 | |
| 70 | ### Variations |
| 71 | |
| 72 | **With model routing:** |
| 73 | ```bash |
| 74 | # Research with Opus (deep reasoning) |
| 75 | claude -p --model opus "Analyze the codebase architecture and write a plan for adding caching..." |
| 76 | |
| 77 | # Implement with Sonnet (fast, capable) |
| 78 | claude -p "Implement the caching layer according to the plan in docs/caching-plan.md..." |
| 79 | |
| 80 | # Review with Opus (thorough) |
| 81 | claude -p --model opus "Review all changes for security issues, race conditions, and edge cases..." |
| 82 | ``` |
| 83 | |
| 84 | **With environment context:** |
| 85 | ```bash |
| 86 | # Pass context via files, not prompt length |
| 87 | echo "Focus areas: auth module, API rate limiting" > .claude-context.md |
| 88 | claude -p "Read .claude-context.md for priorities. Work through them in order." |
| 89 | rm .claude-context.md |
| 90 | ``` |
| 91 | |
| 92 | **With `--allowedTools` restrictions:** |
| 93 | ```bash |
| 94 | # Read-only analysis pass |
| 95 | claude -p --allowedTools "Read,Grep,Glob" "Audit this codebase for security vulnerabilities..." |
| 96 | |
| 97 | # Write-only implementation pass |
| 98 | claude -p --allowedTools "Read,Write,Edit,Bash" "Implement the fixes from security-audit.md..." |
| 99 | ``` |
| 100 | |
| 101 | --- |
| 102 | |
| 103 | ## 2. NanoClaw REPL |
| 104 | |
| 105 | **ECC's built-in persistent loop.** A session-aware REPL that calls `claude -p` synchronously with full conversation history. |
| 106 | |
| 107 | ```bash |
| 108 | # Start the default session |
| 109 | node scripts/claw.js |
| 110 | |
| 111 | # Named session with skill context |
| 112 | CLAW_SESSION=my-project CLAW_SKILLS=tdd-workflow,security |