Communitygithub.com

自主循环(兼容保留)

一套用于构建 Claude Code 自主循环的模式与架构——从简单的顺序管道到 RFC 驱动的多智能体 DAG 系统。仅保留用于兼容性:如需新的自主循环指南,请使用 continuous-agent-loop。

自主循环(兼容保留) 是什么?

**autonomous-loops** 技能提供了一套从简单到复杂的自主循环模式与架构,专门用于 Claude Code 环境,使其能够连续、自主地执行开发任务。该技能涵盖了五种主要模式:顺序管道(`claude -p`)、NanoClaw REPL(持久会话)、无限智能体循环(规范驱动的并行生成)、持续 Claude PR 循环(生产级 CI/CD 集成),以及“去冗余”模式(用于质量清理)。最复杂的模式是 RFC 驱动的 DAG 编排,支持大规模、并行多智能体工作流,并带有合并队列。该技能详细介绍了每种模式的适用场景、实现步骤、核心原理和关键配置选项,并提供了 Bash 脚本、Claude Code 命令和 Markdown 注释文件等具体实现参考。用户可根据任务复杂度选择合适的架构,在减少人工干预的同时提高开发效率和代码质量。

兼容平台✓Claude Code✓Codex CLI~Cursor✓Antigravity
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/autonomous-loops

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

自主循环技能(兼容保留)

兼容性说明 (v1.8.0):autonomous-loops 将保留一个版本。 现在的标准技能名称为 continuous-agent-loop。新的循环指南 应创建在该规范名称下,而本技能保留仅用于避免 破坏现有工作流。

用于在循环中自主运行 Claude Code 的模式、架构和参考实现。涵盖了从简单的 claude -p 管道到完整的 RFC 驱动的多智能体 DAG 编排。

何时使用

  • 设置无需人工干预即可自主运行的开发工作流
  • 为你的问题选择正确的循环架构(简单 vs 复杂)
  • 构建 CI/CD 风格的持续开发管道
  • 运行具有合并协调功能的并行智能体
  • 在循环迭代间实现上下文持久化
  • 为自主工作流添加质量门和清理步骤

循环模式谱系

从最简单到最复杂:

模式复杂度最佳使用场景
顺序管道低日常开发步骤,脚本化工作流
NanoClaw REPL低交互式持久会话
无限智能体循环中并行内容生成,规范驱动的工作
持续 Claude PR 循环中需要 CI 门控的多日迭代项目
去冗余模式附加在任何实现步骤之后进行质量清理
Ralphinho / RFC 驱动 DAG高大型功能,需要合并队列的多单元并行工作

1. 顺序管道 (claude -p)

最简单的循环。 将日常开发分解为一系列非交互式的 claude -p 调用。每次调用都是一个具有清晰提示的聚焦步骤。

核心洞察

如果你连这种循环都想不出来,那说明你甚至无法在交互模式下驱动 LLM 来修复你的代码。

claude -p 标志以非交互方式运行 Claude Code,执行提示后退出。通过链式调用构建管道:

#!/bin/bash
# daily-dev.sh — 用于功能分支的顺序管道

set -e

# 步骤 1:实现功能
claude -p "阅读 docs/auth-spec.md 中的规范。在 src/auth/ 中实现 OAuth2 登录。先写测试(TDD)。不要创建任何新的文档文件。"

# 步骤 2:去冗余(清理步骤)
claude -p "审查上一次提交更改的所有文件。删除任何不必要的类型测试、过度防御性检查或对语言功能的测试(例如,测试 TypeScript 泛型是否工作)。保留真实的业务逻辑测试。清理后运行测试套件。"

# 步骤 3:验证
claude -p "运行完整的构建、lint、类型检查和测试套件。修复所有失败。不要添加新功能。"

# 步骤 4:提交
claude -p "为所有暂存的更改创建一个符合规范的提交。使用 'feat: add OAuth2 login flow' 作为提交信息。"

关键设计原则

  1. 每个步骤都是隔离的 — 每次 claude -p 调用都有一个全新的上下文窗口,步骤间无上下文泄漏。
  2. 顺序很重要 — 步骤按顺序执行。每个步骤都基于前一个步骤留下的文件系统状态。
  3. 负面指令很危险 — 不要写“不要测试类型系统”。相反,添加一个单独的清理步骤(参见去冗余模式)。
  4. 退出码会传播 — set -e 会在失败时停止管道。

变体

带模型路由:

# 使用 Opus 进行研究(深度推理)
claude -p --model opus "分析代码库架构并编写添加缓存的计划..."

# 使用 Sonnet 进行实现(快速且能力强)
claude -p "根据 docs/caching-plan.md 中的计划实现缓存层..."

# 使用 Opus 进行审查(彻底)
claude -p --model opus "审查所有更改是否存在安全问题、竞态条件和边界情况..."

带环境上下文:

# 通过文件传递上下文,而不是增加提示长度
 echo "关注领域:auth 模块,API 速率限制" > .claude-context.md
claude -p "阅读 .claude-context.md 了解优先级。按顺序处理它们。"
rm .claude-context.md

带 --allowedTools 限制:

# 只读分析步骤
claude -p --allowedTools "Read,Grep,Glob" "审计此代码库中的安全漏洞..."

# 只写实现步骤
claude -p --allowedTools "Read,Write,Edit,Bash" "实施来自 security-audit.md 的修复..."

2. NanoClaw REPL

ECC 内置的持久循环。 一个会话感知的 REPL,同步调用 claude -p,并携带完整的对话历史。

# 启动默认会话
node scripts/claw.js

# 带命名会话和技能上下文
CLAW_SESSION=my-project CLAW_SKILLS=tdd-workflow,security-review node scripts/claw.js

工作原理

  1. 从 ~/.claude/claw/{session}.md 加载对话历史
  2. 每个用户消息都作为上下文与完整历史一起发送给 claude -p
  3. 响应被追加到会话文件中(将 Markdown 作为数据库)
  4. 会话在重启后持久存在

何时使用 NanoClaw 对比顺序管道

使用场景NanoClaw顺序管道
交互式探索是否
脚本化自动化否是
会话持久化内置手动
上下文累积每轮增长每一步都是新的
CI/CD 集成较差优秀

详见 /claw 命令文档。


3. 无限智能体循环

一个双提示系统,用于编排并行子智能体进行规范驱动的生成。由 disler 开发。

架构:双提示系统

提示 1(编排器)                    提示 2(子智能体)
┌─────────────────────┐           ┌──────────────────────┐
│ 解析规范文件          │           │ 接收完整上下文         │
│ 扫描输出目录          │  部署     │ 读取分配的数字         │
│ 规划迭代              │──────────│ 完全遵循规范           │
│ 分配创意方向          │  N 个智能体│ 生成独特输出           │
│ 管理批次              │           │ 保存到输出目录         │
└─────────────────────┘           └──────────────────────┘

模式

  1. 规范分析 — 编排器读取一个定义要生成内容的规范文件(Markdown)
  2. 目录侦察 — 扫描现有输出以找到最高的迭代编号
  3. 并行部署 — 启动 N 个子智能体,每个智能体获得:
    • 完整规范
    • 一个独特的创意方向
    • 一个特定的迭代编号(无冲突)
    • 现有迭代的快照(用于保证独特性)
  4. 批次管理 — 对于无限模式,部署 3-5 个智能体的批次,直到上下文耗尽

通过 Claude Code 命令实现

创建 .claude/commands/infinite.md:

从 $ARGUMENTS 解析以下参数:
1. spec_file — 规范 markdown 的路径
2. output_dir — 保存迭代结果的目录
3. count — 整数 1-N 或 "infinite"

阶段 1:阅读并深入理解规范。
阶段 2:列出 output_dir,找到最高迭代编号。从 N+1 开始。
阶段 3:规划创意方向 — 每个智能体获得一个不同的主题/方法。
阶段 4:并行部署子智能体(使用 Task 工具)。每个智能体接收:
  - 完整规范文本
  - 当前目录快照
  - 分配给它们的迭代编号
  - 它们独特的创意方向
阶段 5(无限模式):以 3-5 个为一组循环,直到上下文不足。

调用:

/project:infinite specs/component-spec.md src/ 5
/project:infinite specs/component-spec.md src/ infinite

批处理策略

数量策略
1-5所有智能体同时启动
6-20每批 5 个
无限每批 3-5 个,逐步增加复杂度

关键洞察:通过分配保证独特性

不要依赖智能体自行区分。编排器分配给每个智能体一个特定的创意方向和迭代编号。这可以防止并行智能体生成重复概念。


4. 持续 Claude PR 循环

一个生产级的 shell 脚本,在一个持续循环中运行 Claude Code,创建 PR,等待 CI,并自动合并。由 AnandChowdhary 创建。

核心循环

┌─────────────────────────────────────────────────────┐
│  持续 CLAUDE 迭代                                   │
│                                                     │
│  1. 创建分支 (continuous-claude/iteration-N)        │
│  2. 运行 claude -p,使用增强提示                      │
│  3. (可选)审查者步骤 — 单独的 claude -p              │
│  4. 提交更改(claude 生成信息)                       │
│  5. 推送并创建 PR(gh pr create)                    │
│  6. 等待 CI 检查(轮询 gh pr checks)                 │
│  7. CI 失败?→ 自动修复步骤(claude -p)              │
│  8. 合并 PR(压缩/合并/变基)                         │
│  9. 回到主分支 → 重复                                │
│                                                     │
│  限制方式:--max-runs N | --max-cost $X             │
│            --max-duration 2h | 完成信号              │
└─────────────────────────────────────────────────────┘

安装

警告: 请从其仓库安装 continuous-claude,并在安装前审查代码。不要直接将外部脚本通过管道传给 bash。

使用

# 基础:10 次迭代
continuous-claude --prompt "为所有未测试的函数添加单元测试" --max-runs 10

# 成本限制
continuous-claude --prompt "修复所有 linter 错误" --max-cost 5.00

# 时间限制
continuous-claude --prompt "提高测试覆盖率" --max-duration 8h

# 带代码审查步骤
continuous-claude \
  --prompt "添加认证功能" \
  --max-runs 10 \
  --review-prompt "运行 npm test && npm run lint,修复任何失败"

# 通过工作树并行执行
continuous-claude --prompt "添加测试" --max-runs 5 --worktree tests-worker &
continuous-claude --prompt "重构代码" --max-runs 5 --worktree refactor-worker &
wait

跨迭代上下文:SHARED_TASK_NOTES.md

关键的创新:SHARED_TASK_NOTES.md 文件在迭代之间持久存在:

## 进度
- [x] 为 auth 模块添加了测试 (iteration 1)
- [x] 修复了 token 刷新中的边界情况 (iteration 2)
- [ ] 仍需:速率限制测试,错误边界测试

## 后续步骤
- 接下来专注于速率限制模块
- tests/helpers.ts 中的模拟设置可以重用

Claude 在迭代开始时读取此文件,并在迭代结束时更新它。这弥补了独立 claude -p 调用之间的上下文差距。

CI 失败恢复

当 PR 检查失败时,持续 Claude 会自动:

  1. 通过 gh run list 获取失败的运行 ID
  2. 生成一个新的 claude -p,携带 CI 修复上下文
  3. Claude 通过 gh run view 检查日志、修复代码、提交、推送
  4. 重新等待检查结果(最多 --ci-retry-max 次尝试)

完成信号

Claude 可以通过输出来表示“我完成了”:

continuous-claude \
  --prompt "修复问题跟踪器中的所有错误" \
  --completion-signal "CONTINUOUS_CLAUDE_PROJECT_COMPLETE" \
  --completion-threshold 3  # 连续收到 3 次信号后停止

连续三次迭代发送完成信号将停止循环,防止在已完成的工作上浪费运行。

关键配置

标志用途
--max-runs N在 N 次成功迭代后停止
--max-cost $X在花费 $X 后停止
--max-duration 2h在时间过去后停止
--merge-strategy squashsquash、merge 或 rebase
--worktree <name>通过 git 工作树并行执行
--disable-commits试运行模式(无 git 操作)
--review-prompt "..."每次迭代添加审查者步骤
--ci-retry-max N自动修复 CI 失败(默认:1)

5. 去冗余模式

任何循环的附加模式。 在每个实现步骤之后添加一个专门的清理/重构步骤。

问题

当你要求 LLM 使用 TDD 实现时,它会过于字面地理解“写测试”:

  • 测试 TypeScript 类型系统是否工作(测试 typeof x === 'string')
  • 对类型系统已经保证的事情进行过度的防御性运行时检查
  • 测试框架行为而非业务逻辑
  • 掩盖实际代码的过多错误处理

为什么不用负面指令?

在实现者提示中添加“不要测试类型系统”或“不要添加不必要的检查”会带来下游影响:

  • 模型对所有测试都变得犹豫不决
  • 它会跳过合法的边界情况测试
  • 质量会不可预测地下降

解决方案:单独的步骤

与其约束实现者,不如让它彻底执行。然后添加一个专门的清理智能体:

# 步骤 1:实现(让它彻底)
claude -p "使用完整的 TDD 实现该功能。彻底进行测试。"

# 步骤 2:去冗余(单独的上下文,聚焦清理)
claude -p "审查工作树中的所有更改。删除:
- 验证语言/框架行为而非业务逻辑的测试
- 类型系统已经强制执行的冗余类型检查
- 针对不可能状态的过度防御性错误处理
- Console.log 语句
- 被注释掉的代码

保留所有业务逻辑测试。清理后运行测试套件以确保没有破坏任何东西。"

在循环上下文中

for feature in "${features[@]}"; do
  # 实现
  claude -p "使用 TDD 实现 $feature。"

  # 去冗余
  claude -p "清理步骤:审查更改,删除测试/代码冗余,运行测试。"

  # 验证
  claude -p "运行构建 + lint + 测试。修复任何失败。"

  # 提交
  claude -p "提交,信息为:feat: 添加 $feature"
done

关键洞察

与其添加具有下游质量影响的负面指令,不如添加一个单独的去冗余步骤。两个聚焦的智能体胜过一个有约束的智能体。


6. Ralphinho / RFC 驱动 DAG 编排

最复杂的模式。 一个 RFC 驱动、多智能体的管道,利用 DAG(有向无环图)和合并队列进行大规模并行开发。

核心架构:DAG 工作流

工作流描述                                  ┌──────────────────┐
┌──────────────────────────┐               │  智能体 1:RFC 草案 │
│ RFC:为 OAuth2 添加       │               └────────┬─────────┘
│ 支持 OIDC                 │                        │
│                          │               ┌──────────────────┐
│ 依赖:auth.rs,           │               │  智能体 2:实现     │
│ config.rs                │               └────────┬─────────┘
│                          │                        │
│ 子任务:                  │               ┌──────────────────┐
│ - 编写 RFC (1)           │               │  智能体 3:测试     │
│ - 实现 OIDC (2)          │               └────────┬─────────┘
│ - 编写测试 (3)           │                        │
│ - 集成测试 (4)           │               ┌──────────────────┐
└──────────────────────────┘               │  智能体 4:集成     │
                                            └──────────────────┘

模式如何运作

  1. 编写 RFC — 第一个智能体编写一个详细的 RFC,定义功能、依赖关系和子任务。RFC 充当“真相来源”。
  2. 解析 DAG — 编排器读取 RFC,构建一个子任务间的依赖图。
  3. 并行执行 — 无依赖的智能体并行启动。每个智能体获得:
    • RFC 的相关部分作为上下文
    • 其特定子任务的范围
    • 输入文件(例如,先决条件的 PR)
  4. 合并队列 — 当智能体完成时,其更改被放入一个合并队列中。排序考虑依赖关系。
  5. 自动合并 — 一旦所有依赖的 PR 合并,子任务就会自动合并到主分支。
  6. 反馈循环 — 失败会创建一个新的迭代,更新 RFC,重新触发受影响的子任务。

关键组件

  • RFC 文件:位于 rfcs/ 中,定义所有子任务、依赖关系和验收标准
  • DAG 解析器:读取 RFC 并构建依赖图
  • 智能体工厂:为每个子任务生成新的 Claude Code 实例
  • 合并队列:GitHub PR 的排序列表,尊重依赖关系(例如,gh pr merge)
  • 状态跟踪器:监控所有子任务的进度,检测停滞或失败

何时使用

因素推荐?
任务可以分解为独立的子任务是
子任务有明确的依赖关系是
你有一个 CI 系统来验证合并是
团队有多个开发人员并行工作是的,非常适合
任务很小(< 5 个文件)否,顺序管道更简单

实现

完整的实现超出了本技能的范围,但这里是一个起点:

# dag-orchestrator.sh(概念性示例)
# 1. 解析 RFC
RFC_FILE="rfcs/$1"

# 2. 提取子任务
# (假设一个 RFC 格式,其中描述子任务)

# 3. 为每个子任务生成智能体
for subtask in $(parse_subtasks "$RFC_FILE"); do
  claude -p "根据 RFC 实现子任务 '$subtask'。RFC 位于 $RFC_FILE。" &
done
wait

# 4. 解决合并冲突并合并

有关更复杂的版本,请参阅 continuous-claude 仓库中的 ralphinho 分支。


选择循环

你的需求推荐模式
“我需要运行 3 个顺序的 bash-like 步骤”1. 顺序管道
“我想要一个持久的、交互式的会话”2. NanoClaw REPL
“多次并行生成独特的内容”3. 无限智能体循环
“一个持续运行多日、带 CI 的自主代理”4. 持续 Claude PR 循环
“我在任何实现后都需要清理”5. 去冗余模式
“一个分解为多个子任务的大型功能”6. Ralphinho / RFC 驱动 DAG

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能