Run AI coding agents in persistent, self-healing sessions with automatic retry and completion notification.
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.
tmux installedralphy-cli: npm install -g ralphy-clicodex (Codex CLI) or claude (Claude Code)~/.tmux/sock (default /tmp socket gets reaped by macOS)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"
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"
ralphy --codex --parallel --prd PRD.md
tmux -S ~/.tmux/sock capture-pane -t my-task -p | tail -20
tmux -S ~/.tmux/sock list-sessions
tmux -S ~/.tmux/sock kill-session -t my-task
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 codeecho "EXITED: $EXIT_CODE" — visible in tmux pane outputopenclaw system event — fires a wake event so OpenClaw notifies you immediatelysleep 999999 — keeps the shell alive so output remains readableRalph 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.
| Scenario | Tool |
|---|---|
| ---------- | ------ |
| Multi-step features, PRD checklists | ralphy --codex --prd PRD.md |
| Tasks that have stalled before | ralphy --codex "task" (auto-retry) |
| Tiny focused fixes, one-file changes | codex exec --full-auto "task" |
| Parallel work on different tasks | ralphy --codex --parallel --prd PRD.md |
| Skip tests/lint for speed | ralphy --codex --fast "task" |
| Use Claude Code instead of Codex | ralphy --claude "task" |
~/.tmux/sock) — the default /tmp socket gets cleaned up.git log, git diff, and process output before concluding it failed./opt/homebrew/bin: if tools aren't found.~/.codex/log/codex-tui.log for auth errors. May need codex auth login.git log --oneline -3 and git diff --stat.tmux -S ~/.tmux/sock has-session -t and restart if needed.共 1 个版本