← 返回
AI智能 中文

Coding Agent Loops

Run long-lived AI coding agents (Codex, Claude Code) in persistent tmux sessions with Ralph retry loops and completion hooks. Use when running multi-step cod...
在持久tmux会话中运行AI编码代理(Codex、Claude Code),使用Ralph重试循环和完成钩子处理多步骤编码任务。
luke-deltadesk
AI智能 clawhub v1.0.0 1 版本 99884.8 Key: 无需
★ 0
Stars
📥 867
下载
💾 58
安装
1
版本
#latest

概述

Coding Agent Loops

Run AI coding agents in persistent, self-healing sessions with automatic retry and completion notification.

Core Concept

Instead of one long agent session that stalls or dies, run many short sessions in a loop. Each iteration starts fresh — no accumulated context. The agent picks up where it left off via files and git history. This is the "Ralph loop" pattern.

Prerequisites

  • tmux installed
  • ralphy-cli: npm install -g ralphy-cli
  • A coding agent: codex (Codex CLI) or claude (Claude Code)
  • Stable tmux socket: always use ~/.tmux/sock (default /tmp socket gets reaped by macOS)

Quick Start

Single Task

tmux -S ~/.tmux/sock new -d -s my-task \
  "cd /path/to/repo && ralphy --codex 'Fix the authentication bug'; \
   EXIT_CODE=\$?; echo EXITED: \$EXIT_CODE; \
   openclaw system event --text 'Ralph loop my-task finished (exit \$EXIT_CODE) in \$(pwd)' --mode now; \
   sleep 999999"

PRD-Based Workflow (Preferred for Multi-Step Work)

tmux -S ~/.tmux/sock new -d -s feature-build \
  "cd /path/to/repo && ralphy --codex --prd PRD.md; \
   EXIT_CODE=\$?; echo EXITED: \$EXIT_CODE; \
   openclaw system event --text 'Ralph loop feature-build finished (exit \$EXIT_CODE) in \$(pwd)' --mode now; \
   sleep 999999"

Parallel Agents on Separate Tasks

ralphy --codex --parallel --prd PRD.md

Session Management

Check Progress

tmux -S ~/.tmux/sock capture-pane -t my-task -p | tail -20

List Active Sessions

tmux -S ~/.tmux/sock list-sessions

Kill a Session

tmux -S ~/.tmux/sock kill-session -t my-task

The Completion Hook (Mandatory)

Always append this to tmux commands:

; EXIT_CODE=$?; echo "EXITED: $EXIT_CODE"; \
openclaw system event --text "Ralph loop <name> finished (exit $EXIT_CODE) in $(pwd)" --mode now; \
sleep 999999

Why each part matters:

  • EXIT_CODE=$? — captures the agent's exit code
  • echo "EXITED: $EXIT_CODE" — visible in tmux pane output
  • openclaw system event — fires a wake event so OpenClaw notifies you immediately
  • sleep 999999 — keeps the shell alive so output remains readable

PRD Format

Ralph tracks completion via markdown checklists:

## Tasks
- [ ] Create the API endpoint
- [ ] Add input validation
- [ ] Write tests
- [x] Already done (skipped)

Ralph validates that all items are checked before accepting a completion signal from the agent.

When to Use What

ScenarioTool
----------------
Multi-step features, PRD checklistsralphy --codex --prd PRD.md
Tasks that have stalled beforeralphy --codex "task" (auto-retry)
Tiny focused fixes, one-file changescodex exec --full-auto "task"
Parallel work on different tasksralphy --codex --parallel --prd PRD.md
Skip tests/lint for speedralphy --codex --fast "task"
Use Claude Code instead of Codexralphy --claude "task"

Key Principles

  1. Always use tmux — background exec processes die on gateway/host restart. tmux sessions persist.
  2. Always use the stable socket (~/.tmux/sock) — the default /tmp socket gets cleaned up.
  3. Always add the completion hook — without it you won't know when the agent finishes.
  4. Log active sessions — record running sessions in daily notes or a tracking file so you don't lose awareness.
  5. Verify before declaring failure — after a process ends, check git log, git diff, and process output before concluding it failed.
  6. PATH in tmux — tmux may not inherit your full PATH. Prepend /opt/homebrew/bin: if tools aren't found.

Troubleshooting

  • Agent exits immediately: Check ~/.codex/log/codex-tui.log for auth errors. May need codex auth login.
  • Ralph marks tasks done but nothing committed: Ralph can mark PRD tasks complete even when the agent fails silently. Always verify via git log --oneline -3 and git diff --stat.
  • API rate limits (429s): Common when running multiple parallel agents. Ralph's retry handles this, but reduce parallelism if persistent.
  • Session disappeared: tmux sessions can die from OOM or system restarts. Check with tmux -S ~/.tmux/sock has-session -t and restart if needed.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 04:22 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

Proactive Agent

halthelobster
将AI智能体从任务执行者升级为主动预判需求、持续优化的智能伙伴。集成WAL协议、工作缓冲区、自主定时任务及实战验证模式。Hal Stack核心组件 🦞
★ 837 📥 213,335
developer-tools

Coding Sessions

luke-deltadesk
在持久化的tmux会话中运行长时间AI编程代理(Codex CLI、Claude Code、Ralph循环),配备完成钩子和自动监控功能。适用于...
★ 0 📥 754
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,362 📥 318,822