Ralph 自主编码循环生态
Geoffrey Huntley 提出的 “Ralph 技术”:把 AI 编码 Agent 套进
while true循环,让它对着同一份任务列表反复执行直到完成。 04-14 跟 Hermes Agent 调研后整理。
起源与核心思想
- 命名出处:Geoffrey Huntley 博文《Ralph》(2025)
- 核心循环:
while true; do claude -p "$(cat PROMPT.md)"; done - 哲学:“概率辐射”——单次执行不必完美,统计意义上整个方向在收敛即可
- 适用:测试覆盖率提升、批量重构、文档补全、Issue 批处理这类可量化进度的任务
两个原版对比(用户问)
| 维度 | frankbria/ralph-claude-code | snarktank/ralph |
|---|---|---|
| 主脚本 | 纯 Bash, 2500+ 行 | Bash, ~100 行 |
| 测试 | 566 个测试,重型工程 | 0 测试,极简 |
| AI 引擎 | 仅 Claude Code | Claude Code + Amp 双引擎 |
| 迭代模型 | 有状态 —— --resume 保留 session | 无状态(每轮新 session) |
| 待办格式 | Markdown | JSON 结构化 |
| GitHub ⭐ | 较少 | 16.7k ⭐, 1.7k fork |
结论: 想开箱即用、轻量 → snarktank/ralph。想可观测、可恢复、企业级 → frankbria/ralph-claude-code。两者哲学完全不同,前者”少即是多”,后者”工程化保障”。
优化版生态(snarktank/ralph 衍生)
Tier 1(最值得关注)
1. AnandChowdhary/continuous-claude — 1.3k ⭐
Ralph + GitHub PR 自动化:跑完自动 commit → 建 PR → 等 CI → 绿了 auto-merge → 继续下一题。支持 --max-cost 预算上限。
- 仓库:https://github.com/AnandChowdhary/continuous-claude
- v0.22.1 / 158 commits / MIT / 单文件 Bash 2491 行 / 3 真人 + 2 bot 贡献者
- 起源:作者被合同要求把测试覆盖率从 0% → 80%,写了个
while true; do claude ...; done然后睡觉 - 关键能力:worktree 隔离、
--max-iterations、--max-cost、自动 commit/PR/merge
2. ClaytonFarr/ralph-playbook — 946 ⭐, 243 fork
不是代码而是方法论文档。把 Ralph 拆成 3 阶段:
- 定义需求(PRD/Spec)
- 规划循环(task plan)
- 构建循环(执行 + checkpoint)
带完整 PLAN.md / 模板 / checkpoint 流程。文档型仓库。
Tier 2(值得一试)
- super-ralph — Ralph + 多 Agent 并行
- Ollama 适配版 —— 25 commits ahead of upstream,把 Claude Code 替换成本地 Ollama
- 大量 fork 但多数只有零星 commit
生态发现路径
https://github.com/snarktank/ralph/forks可查看所有 fork- HN 讨论搜 “Ralph technique” / “Ralph loop”
- “awesome-claude-code” 类聚合仓库会列出生态
与 Hermes Agent 的关系
Hermes 的 delegate_task(acp_command="claude") 已经能 spawn Claude Code 子进程,理论上可以在 Hermes 里实现轻量 Ralph 循环:
while not done():
delegate_task(
acp_command="claude",
prompt="continue: " + open("PROMPT.md").read(),
max_turns=80,
)但 Hermes 单 agent 同时只允许 3 个并发子任务,Ralph 内部的多轮迭代靠 Claude Code 自己的 --resume,详见 acp-claude-code-integration 与 hermes-agent-setup 关于 stdin/--max-turns 的踩坑。
相关页面
- hermes-agent-setup — 启动 Claude Code 子代理的工程实践
- acp-claude-code-integration — ACP runtime 接入
- copilot-anthropic-proxy — 所有 Claude Code 调用走的代理
- multi-agent-architecture