Autonomous LoopsSAFE
everything-claude-code 中文翻译项目:完整的 Claude Code 配置集合(agents, skills, hooks, commands, rules, MCPs)。源自 Anthropic 黑客松获胜者的实战配置,助力中文工程师高效理解与使用 Claude Code。
Overview
everything-claude-code 中文翻译项目:完整的 Claude Code 配置集合(agents, skills, hooks, commands, rules, MCPs)。源自 Anthropic 黑客松获胜者的实战配置,助力中文工程师高效理解与使用 Claude Code。
012f775295c3OBSERVED · 2026-10-12Host compatibility
What the documentation claims. We have not run a compatibility test.
| Host | Status | Notes |
|---|---|---|
| claude-code | mentioned | |
| codex | mentioned |
What it tells the agent
The instruction file, verbatim from the audited commit — this is the text the model reads, and the surface the audit's instruction layer examines. Quoted here so you can judge it without cloning anything.
---
name: autonomous-loops
description: "自主运行 Claude Code 循环的模式与架构 —— 从简单的顺序流水线到 RFC 驱动的多智能体 DAG 系统。"
origin: ECC
---
# 自主循环技能 (Autonomous Loops Skill)
用于自主运行 Claude Code 循环的模式、架构和参考实现。涵盖了从简单的 `claude -p` 流水线到完整的 RFC 驱动多智能体(multi-agent)DAG 编排的所有内容。
## 适用场景
- 设置无需人工干预即可运行的自主开发工作流(Workflows)
- 为你的问题选择合适的循环架构(简单 vs 复杂)
- 构建 CI/CD 风格的持续开发流水线
- 运行具有合并协调机制的并行智能体(Agents)
- 在循环迭代之间实现上下文(Context)持久化
- 为自主工作流添加质量门禁(Quality gates)和清理环节
## 循环模式频谱 (Loop Pattern Spectrum)
从最简单到最复杂:
| 模式 | 复杂度 | 最适用于 |
|---------|-----------|----------|
| [顺序流水线 (Sequential Pipeline)](#1-sequential-pipeline-claude--p) | 低 | 日常开发步骤、脚本化工作流 |
| [NanoClaw REPL](#2-nanoclaw-repl) | 低 | 交互式持久化会话 |
| [无限智能体循环 (Infinite Agentic Loop)](#3-infinite-agentic-loop) | 中 | 并行内容生成、规约驱动的工作 |
| [持续 Claude PR 循环 (Continuous Claude PR Loop)](#4-continuous-claude-pr-loop) | 中 | 带有 CI 门禁的多日迭代项目 |
| [去杂质模式 (De-Sloppify Pattern)](#5-the-de-sloppify-pattern) | 附加项 | 任何实现步骤后的质量清理 |
| [Ralphinho / RFC 驱动的 DAG](#6-ralphinho--rfc-driven-dag-orchestration) | 高 | 大型功能、带合并队列的多单元并行工作 |
---
## 1. 顺序流水线 (Sequential Pipeline, `claude -p`)
**最简单的循环。** 将日常开发分解为一系列非交互式的 `claude -p` 调用。每次调用都是一个带有明确提示词(Prompt)的专注步骤。
### 核心见解
> 如果你无法理解这样的循环,那就意味着你甚至无法在交互模式下驱动 LLM 修复你的代码。
`claude -p` 标志(flag)以非交互方式运行 Claude Code 并提供提示词,完成后退出。通过链式调用构建流水线:
```bash
#!/bin/bash
# daily-dev.sh — 功能分支的顺序流水线
set -e
# 第 1 步:实现功能
claude -p "阅读 docs/auth-spec.md 中的规约。在 src/auth/ 中实现 OAuth2 登录。先写测试 (TDD)。不要创建任何新的文档文件。"
# 第 2 步:去杂质 (De-sloppify, 清理环节)
claude -p "检查上一次提交更改的所有文件。删除任何不必要的类型测试、过度防御性的检查或对语言特性的测试(例如,测试 TypeScript 泛型是否工作)。保留真实的业务逻辑测试。清理后运行测试套件。"
# 第 3 步:验证
claude -p "运行完整的构建、代码检查(lint)、类型检查和测试套件。修复任何失败。不要添加新功能。"
# 第 4 步:提交
claude -p "为所有暂存的更改创建一个约定式提交(conventional commit)。使用 'feat: add OAuth2 login flow' 作为消息。"
```
### 关键设计原则
1. **每个步骤都是隔离的** — 每次 `claude -p` 调用都有一个新的上下文窗口(Context window),这意味着步骤之间不会有上下文污染。
2. **顺序很重要** — 步骤按顺序执行。每一步都建立在前一步留下的文件系统状态之上。
3. **负面指令是危险的** — 不要说“不要测试类型系统”。相反,添加一个单独的清理步骤(参见 [去杂质模式](#5-the-de-sloppify-pattern))。
4. **退出码会传播** — `set -e` 会在失败时停止流水线。
### 变体
**使用模型路由 (Model Routing):**
```bash
# 使用 Opus 进行调研(深度推理)
claude -p --model opus "分析代码库架构并编写添加缓存的计划..."
# 使用 Sonnet 进行实现(快速且强大)
claude -p "根据 docs/caching-plan.md 中的计划实现缓存层..."
# 使用 Opus 进行审查(彻底)
claude -p --model opus "检查所有更改是否存在安全问题、竞态条件和边界情况..."
```
**带有环境上下文:**
```bash
# 通过文件传递上下文,而不是增加提示词长度
echo "重点领域:auth 模块,API 速率限制" > .claude-context.md
claude -p "阅读 .claude-context.md 获取优先级信息。按顺序处理它们。"
rm .claude-context.md
```
**带有 `--allowedTools` 限制:**
```bash
# 只读分析阶段
claude -p --allowedTools "Read,Grep,Glob" "审计此代码库的安全漏洞..."
# 只写实现阶段
claude -p --allowedTools "Read,Write,Edit,Bash" "实现 security-audit.md 中的修复方案..."
```
---
## 2. NanoClaw REPL
**ECC 内置的持久化循环。** 一个具有会话意识的 REPL,它同步调用 `claude -p` 并带有完整的对话历史。
```bash
# 启动默认会话
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. 无限智能体循环 (Infinite Agentic Loop)
**双提示词系统**,用于协调并行子智能体(sub-agents)进行规约驱动的生成。由 disler 开发(致谢:@disler)。
### 架构:双提示词系统
```
提示词 1 (编排器 Orchestrator) 提示词 2 (子智能体 Sub-Agents)
┌─────────────────────┐ ┌──────────────────────┐
│ 解析规约文件 │ │ 接收完整上下文 │
│ 扫描输出目录 │ 部署 │ 读取分配的编号 │
│ 计划迭代 │────────────│ 严格遵守规约 │
│ 分配创意方向 │ N 个智能体 │ 生成唯一的输出 │
│ 管理波次 │ │ 保存到输出目录 │
└─────────────────────┘ └──────────────────────┘
```
### 模式
1. **规约分析** — 编排器读取定义生成内容的规约文件(Markdown)。
2. **目录侦察** — 扫描现有输出以找到最高的迭代编号。
3. **并行部署** — 启动 N 个子智能体,每个子智能体都获得:
- 完整的规约
- 唯一的创意方向
- 特定的迭代编号(无冲突)
- 现有迭代的快照(用于确保唯一性)
4. **波次管理** — 对于无限模式,部署 3-5 个智能体为一个波次,直到上下文耗尽。
### 通过 Claude Code 命令实现
创建 `.claude/commands/infinite.md`:
```markdown
从 $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 个为一波次循环,直到上下文过低。
```
**调用:**
```bash
/project:infinite specs/component-spec.md src/ 5
/project:infinite specs/component-spec.md src/ infinite
```
### 分批策略
| 数量 | 策略 |
|-------|----------|
| 1-5 | 所有智能体同时运行 |
| 6-20 | 每批 5 个 |
| infinite | 3-5 个一波,逐步提升复杂度 |
### 关键见解:通过分配确保唯一性
不要指望智能体自我区分。编排器会**分配**给每个智能体特定的创意方向和迭代编号。这可以防止并行智能体之间出现重复的概念。
---
## 4. 持续 Claude PR 循环 (Continuous Claude PR Loop)
**生产级 Shell 脚本**,在持续循环中运行 Claude Code,创建 PR、等待 CI 并自动合并。由 AnandChowdhary 开发(致谢:@AnandChowdhary)。
### 核心循环
```
┌─────────────────────────────────────────────────────┐
│ 持续 CLAUDE 迭代 (CONTINUOUS CLAUDE ITERATION) │
│ │
│ 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 (squash/merge/rebase) │
│ 9. 返回 main 分支 → 重复 │
│ │
│ 限制条件:--max-runs N | --max-cost $X │
│ --max-duration 2h | 完成信号 │
└─────────────────────────────────────────────────────┘
```
### 安装
```bash
curl -fsSL https://raw.githubusercontent.com/AnandChowdhary/continuous-claude/HEAD/install.sh | bash
```
### 使用
```bash
# 基础:10 次迭代
continuous-claude --prompt "为所有未测试的函数添加单元测试" --max-runs 10
# 限制成本
Trust audit
SAFEgrade B · trust 89/100 Nothing in the source contradicts what it says it does. Grade A is reserved for packages that have also passed the behavioural sandbox.
| Layer | What it checks | Result |
|---|---|---|
| L0 | Provenance & inventory | PASS |
| L1 | Static analysis of the code | NA |
| L2 | Instruction surface (what it tells the agent) | PASS |
| L3 | Class-specific surface | PASS |
| L4 | Behavioural (sandbox) | SKIPPED |
What the source does
- Filesystem
- none-observed
- Network
- none-observed
- Shell
- none-observed
- Dependencies
- pinned
- Secrets in source
- none-found
Findings (1)
curl -fsSL https://raw.githubusercontent.com/AnandChowdhary/continuous-claude/HEAD/install.sh | bash
Gates applied: no_behavioural_pass.
012f775295c3full audit observations/trust-audit/skill/xu-xiang__autonomous-loops.json · Report an issue / request a re-scanAudit history
Every audit this skill has had.
| Date | Source | Verdict | Grade | Score | Change |
|---|---|---|---|---|---|
| 2026-10-12 | 012f775295c3 | SAFE | B | 89 | first audit |
Questions
What does the Autonomous Loops skill do?
everything-claude-code 中文翻译项目:完整的 Claude Code 配置集合(agents, skills, hooks, commands, rules, MCPs)。源自 Anthropic 黑客松获胜者的实战配置,助力中文工程师高效理解与使用 Claude Code。
Is Autonomous Loops safe to install?
The audit found nothing in the source that contradicts what it says it does, and graded it B (89/100). Grade A is held back for packages that have also passed a sandboxed behavioural run, which is why a clean skill reads B.
What can Autonomous Loops access on my machine?
The audit observed no filesystem, network or shell use at all in its source.
Which assistants does Autonomous Loops work with?
Its documentation mentions claude-code and codex. That is what the text claims, not a compatibility test we ran.
How current is this page?
The grade is for one exact copy of the source (012f775295c3), read on 2026-10-12. The repository is watched, and a new audit runs when it changes — this is the first audit.