monitored-ralph-loopGenerate copy-paste bash scripts for Ralph Wiggum/AI agent loops (Codex, Claude Code, OpenCode, Goose). Use when asked for a "Ralph loop", "Ralph Wiggum loop", or an AI loop to plan/build code via PROMPT.md + AGENTS.md, SPECS, and IMPLEMENTATION_PLAN.md, including PLANNING vs BUILDING modes, backpressure, sandboxing, and completion conditions.
Install via ClawdBot CLI:
clawdbot install Endogen/monitored-ralph-loopEnhanced Ralph pattern with event-driven notifications ā Codex/Claude calls OpenClaw when it needs attention instead of polling.
Each iteration spawns a fresh agent session with clean context. This is intentional:
codex exec is a new process with no memory of previous runsIMPLEMENTATION_PLAN.md, AGENTS.md, git historyIf OpenClaw is rate-limited when Codex sends a wake notification:
.ralph/pending-notification.txtproject/
āāā PROMPT.md # Loaded each iteration (mode-specific)
āāā AGENTS.md # Project context, test commands, learnings
āāā IMPLEMENTATION_PLAN.md # Task list with status
āāā specs/ # Requirements specs
ā āāā overview.md
ā āāā <feature>.md
āāā .ralph/
āāā ralph.log # Execution log
āāā pending-notification.txt # Current pending notification (if any)
āāā last-notification.txt # Previous notification (for reference)
.ralph/pending-notification.txt:
{
"timestamp": "2026-02-07T02:30:00+01:00",
"project": "/home/user/my-project",
"message": "DONE: All tasks complete.",
"iteration": 15,
"max_iterations": 20,
"cli": "codex",
"status": "pending"
}
Status values:
pending ā Wake failed or not attempteddelivered ā Wake succeededWhen coming back online after rate limit or downtime, check for pending notifications:
# Find all pending notifications across projects
find ~/projects -name "pending-notification.txt" -path "*/.ralph/*" 2>/dev/null
# Or check a specific project
cat /path/to/project/.ralph/pending-notification.txt
| Prefix | Action |
|--------|--------|
| DONE: | Report completion to user, summarize what was built |
| PLANNING_COMPLETE: | Inform user, ask if ready for BUILDING mode |
| PROGRESS: | Log it, update user if significant |
| DECISION: | Present options to user, wait for answer, inject into AGENTS.md |
| ERROR: | Check logs (.ralph/ralph.log), analyze, help or escalate |
| BLOCKED: | Escalate to user immediately with full context |
| QUESTION: | Present to user, get clarification, inject into AGENTS.md |
To answer a decision/question for the next iteration:
echo "## Human Decisions
- [$(date '+%Y-%m-%d %H:%M')] Q: <question>? A: <answer>" >> AGENTS.md
The next Codex session will read AGENTS.md and see the answer.
After processing a notification, clear it:
mv .ralph/pending-notification.txt .ralph/last-notification.txt
Ask for (if not provided):
codex, claude, opencode, goosePLANNING, BUILDING, or BOTHBreak the goal into topics of concern ā specs/*.md:
# specs/overview.md
## Goal
<one-sentence JTBD>
## Tech Stack
- Language: Python 3.11
- Framework: FastAPI
- Database: SQLite
- Frontend: HTMX + Tailwind
## Success Criteria
- [ ] Criterion 1
- [ ] Criterion 2
# AGENTS.md
## Project
<brief description>
## Commands
- **Install**: `pip install -e .`
- **Test**: `pytest`
- **Lint**: `ruff check .`
- **Run**: `python -m app`
## Backpressure
Run after each implementation:
1. `ruff check . --fix`
2. `pytest`
## Human Decisions
<!-- Decisions made by humans are recorded here -->
## Learnings
<!-- Agent appends operational notes here -->
# Ralph PLANNING Loop
## Goal
<JTBD>
## Context
- Read: specs/*.md
- Read: Current codebase structure
- Update: IMPLEMENTATION_PLAN.md
## Rules
1. Do NOT implement code
2. Do NOT commit
3. Analyze gaps between specs and current state
4. Create/update IMPLEMENTATION_PLAN.md with prioritized tasks
5. Each task should be small (< 1 hour of work)
6. If requirements are unclear, list questions
## Notifications
When you need input or finish planning:bash
openclaw gateway wake --text "PLANNING:
Use prefixes:
- `DECISION:` ā Need human input on a choice
- `QUESTION:` ā Requirements unclear
- `DONE:` ā Planning complete
## Completion
When plan is complete and ready for building, add to IMPLEMENTATION_PLAN.md:
STATUS: PLANNING_COMPLETE
Then notify:bash
openclaw gateway wake --text "DONE: Planning complete. X tasks identified." --mode now
# Ralph BUILDING Loop
## Goal
<JTBD>
## Context
- Read: specs/*.md, IMPLEMENTATION_PLAN.md, AGENTS.md
- Implement: One task per iteration
- Test: Run backpressure commands from AGENTS.md
## Rules
1. Pick the highest priority incomplete task from IMPLEMENTATION_PLAN.md
2. Investigate relevant code before changing
3. Implement the task
4. Run backpressure commands (lint, test)
5. If tests pass: commit with clear message, mark task done
6. If tests fail: try to fix (max 3 attempts), then notify
7. Update AGENTS.md with any operational learnings
8. Update IMPLEMENTATION_PLAN.md with progress
## Notifications
Call OpenClaw when needed:bash
openclaw gateway wake --text "
Prefixes:
- `DECISION:` ā Need human input (e.g., "SQLite vs PostgreSQL?")
- `ERROR:` ā Tests failing after 3 attempts
- `BLOCKED:` ā Missing dependency, credentials, or unclear spec
- `PROGRESS:` ā Major milestone complete (optional)
- `DONE:` ā All tasks complete
## Completion
When all tasks are done:
1. Add to IMPLEMENTATION_PLAN.md: `STATUS: COMPLETE`
2. Notify:bash
openclaw gateway wake --text "DONE: All tasks complete. Summary:
Use the provided scripts/ralph.sh:
# Default: 20 iterations with Codex
./scripts/ralph.sh 20
# With Claude Code
RALPH_CLI=claude ./scripts/ralph.sh 10
# With tests
RALPH_TEST="pytest" ./scripts/ralph.sh
For independent tasks, use git worktrees:
# Create worktrees for parallel work
git worktree add /tmp/task-auth main
git worktree add /tmp/task-upload main
# Spawn parallel sessions (each is clean/fresh)
exec pty:true background:true workdir:/tmp/task-auth command:"codex exec --full-auto 'Implement user authentication...'"
exec pty:true background:true workdir:/tmp/task-upload command:"codex exec --full-auto 'Implement image upload...'"
Track sessions:
| Session ID | Worktree | Task | Status |
|------------|----------|------|--------|
| abc123 | /tmp/task-auth | Auth module | running |
| def456 | /tmp/task-upload | Image upload | running |
Each Codex notifies independently. Check .ralph/pending-notification.txt in each worktree.
codex exec is a fresh session ā no memory between calls--full-auto: Auto-approve in workspace (sandboxed)--yolo: No sandbox, no approvals (dangerous but fast)--dangerously-skip-permissions: Auto-approve (use in sandbox)opencode run "$(cat PROMPT.md)"goose run "$(cat PROMPT.md)"ā ļø Auto-approve flags are dangerous. Always:
git reset --hard ready as escape hatch# 1. Create project directory
mkdir my-project && cd my-project && git init
# 2. Copy templates from skill
cp /path/to/ralph-loop/templates/* .
mv PROMPT-PLANNING.md PROMPT.md
# 3. Create specs
mkdir specs
cat > specs/overview.md << 'EOF'
## Goal
Build a web app that...
## Tech Stack
- Python 3.11 + FastAPI
- SQLite
- HTMX + Tailwind
## Features
1. Feature one
2. Feature two
EOF
# 4. Edit PROMPT.md with your goal
# 5. Run the loop
./ralph.sh 20
# specs/overview.md
## Goal
Web app for cataloguing antique items with metadata, images, and categories.
## Tech Stack
- Python 3.11 + FastAPI
- SQLite + SQLAlchemy
- HTMX + Tailwind CSS
- Local file storage for images
## Features
1. CRUD for items (name, description, age, purchase info, dimensions)
2. Image upload (multiple per item)
3. Tags and categories
4. Search and filter
5. Multiple view modes (grid, list, detail)
The agent will:
Generated Mar 1, 2026
A startup needs to quickly build a REST API for their new mobile app. Using the Ralph Loop, they can generate specs, plan endpoints, and implement them in BUILDING mode with backpressure testing, ensuring code quality and rapid iteration.
A financial institution wants to modernize an old codebase. The PLANNING mode helps break down the refactoring into small, manageable tasks, while BUILDING mode implements them with sandboxing to avoid breaking existing functionality.
An edtech company develops interactive learning modules. The Ralph Loop automates generating specs for each module, planning content structure, and building code with event-driven notifications to handle user feedback loops efficiently.
An online retailer needs to add new features like real-time inventory tracking. The loop uses AGENTS.md for context, iterates through tasks in IMPLEMENTATION_PLAN.md, and leverages file-based notifications to manage rate limits during peak loads.
A hardware startup builds firmware for smart devices. The Ralph Loop helps plan and implement code updates, with backpressure commands for testing on simulated environments, ensuring reliability before deployment.
Offer the Ralph Loop as a cloud-based service where users pay monthly for automated code generation and project management. Revenue comes from tiered plans based on usage limits and support levels.
Provide expert services to integrate the Ralph Loop into client workflows, tailoring it for specific industries like finance or healthcare. Revenue is generated through project-based contracts and ongoing maintenance.
Release the core Ralph Loop as open source to build a community, while monetizing advanced features like enhanced notifications, analytics dashboards, or enterprise support. Revenue comes from premium add-ons and support packages.
š¬ Integration Tip
Integrate the Ralph Loop into existing CI/CD pipelines by hooking notifications to tools like Slack or Jira, and use AGENTS.md to store project-specific commands for seamless automation.
Captures learnings, errors, and corrections to enable continuous improvement. Use when: (1) A command or operation fails unexpectedly, (2) User corrects Clau...
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
Search and analyze your own session logs (older/parent conversations) using jq.
Typed knowledge graph for structured agent memory and composable skills. Use when creating/querying entities (Person, Project, Task, Event, Document), linking related objects, enforcing constraints, planning multi-step actions as graph transformations, or when skills need to share state. Trigger on "remember", "what do I know about", "link X to Y", "show dependencies", entity CRUD, or cross-skill data access.
Ultimate AI agent memory system for Cursor, Claude, ChatGPT & Copilot. WAL protocol + vector search + git-notes + cloud backup. Never lose context again. Vibe-coding ready.
Headless browser automation CLI optimized for AI agents with accessibility tree snapshots and ref-based element selection