Iterative AI development loops. Same prompt. Persistent progress.
Based on ghuntley.com/ralph
What is Ralph? • Installation • Quick Start • Commands
Tired of agents breaking your local environment?
OpenAgent gives each task an isolated Linux workspace. Self-hosted. Git-backed.
Ralph is a development methodology where an AI agent receives the same prompt repeatedly until it completes a task. Each iteration, the AI sees its previous work in files and git history, enabling self-correction and incremental progress.
This package provides a CLI-only implementation (no OpenCode plugin).
# The essence of Ralph:
while true; do
opencode run "Build feature X. Output <promise>DONE</promise> when complete."
doneThe AI doesn't talk to itself. It sees the same prompt each time, but the files have changed from previous iterations. This creates a feedback loop where the AI iteratively improves its work until success.
| Benefit | How it works |
|---|---|
| Self-Correction | AI sees test failures from previous runs, fixes them |
| Persistence | Walk away, come back to completed work |
| Iteration | Complex tasks broken into incremental progress |
| Automation | No babysitting—loop handles retries |
| Observability | Monitor progress with --status, see history and struggle indicators |
| Mid-Loop Guidance | Inject hints with --add-context without stopping the loop |
Prerequisites: Bun and OpenCode
npm install -g @th0rgal/ralph-wiggumbun add -g @th0rgal/ralph-wiggumgit clone https://github.com/Th0rgal/ralph-wiggum
cd opencode-ralph-wiggum
./install.shgit clone https://github.com/Th0rgal/ralph-wiggum
cd opencode-ralph-wiggum
.\install.ps1This installs:
ralphCLI command (global)
# Simple task with iteration limit
ralph "Create a hello.txt file with 'Hello World'. Output <promise>DONE</promise> when complete." \
--max-iterations 5
# Build something real
ralph "Build a REST API for todos with CRUD operations and tests. \
Run tests after each change. Output <promise>COMPLETE</promise> when all tests pass." \
--max-iterations 20ralph "<prompt>" [options]
Options:
--max-iterations N Stop after N iterations (default: unlimited)
--completion-promise T Text that signals completion (default: COMPLETE)
--model MODEL OpenCode model to use
--prompt-file, --file, -f Read prompt content from a file
--no-stream Buffer OpenCode output and print at the end
--verbose-tools Print every tool line (disable compact tool summary)
--no-plugins Disable non-auth OpenCode plugins for this run
--no-commit Don't auto-commit after iterations
--help Show help# Check status of active loop (run from another terminal)
ralph --status
# Add context/hints for the next iteration
ralph --add-context "Focus on fixing the auth module first"
# Clear pending context
ralph --clear-contextThe --status command shows:
- Active loop info: Current iteration, elapsed time, prompt
- Pending context: Any hints queued for next iteration
- Iteration history: Last 5 iterations with tools used, duration
- Struggle indicators: Warnings if agent is stuck (no progress, repeated errors)
╔══════════════════════════════════════════════════════════════════╗
║ Ralph Wiggum Status ║
╚══════════════════════════════════════════════════════════════════╝
🔄 ACTIVE LOOP
Iteration: 3 / 10
Elapsed: 5m 23s
Promise: COMPLETE
Prompt: Build a REST API...
📊 HISTORY (3 iterations)
Total time: 5m 23s
Recent iterations:
🔄 #1: 2m 10s | Bash:5 Write:3 Read:2
🔄 #2: 1m 45s | Edit:4 Bash:3 Read:2
🔄 #3: 1m 28s | Bash:2 Edit:1
⚠️ STRUGGLE INDICATORS:
- No file changes in 3 iterations
💡 Consider using: ralph --add-context "your hint here"
Guide a struggling agent without stopping the loop:
# In another terminal while loop is running
ralph --add-context "The bug is in utils/parser.ts line 42"
ralph --add-context "Try using the singleton pattern for config"Context is automatically consumed after one iteration.
This package is CLI-only. If OpenCode tries to load a ralph-wiggum plugin,
remove it from your OpenCode plugin list (opencode.json), or run:
ralph "Your task" --no-pluginsInstall Bun: https://bun.sh
❌ Bad:
Build a todo API
✅ Good:
Build a REST API for todos with:
- CRUD endpoints (GET, POST, PUT, DELETE)
- Input validation
- Tests for each endpoint
Run tests after changes. Output <promise>COMPLETE</promise> when all tests pass.
❌ Bad:
Make the code better
✅ Good:
Refactor auth.ts to:
1. Extract validation into separate functions
2. Add error handling for network failures
3. Ensure all existing tests still pass
Output <promise>DONE</promise> when refactored and tests pass.
# Safety net for runaway loops
ralph "Your task" --max-iterations 20Good for:
- Tasks with automatic verification (tests, linters, type checking)
- Well-defined tasks with clear completion criteria
- Greenfield projects where you can walk away
- Iterative refinement (getting tests to pass)
Not good for:
- Tasks requiring human judgment
- One-shot operations
- Unclear success criteria
- Production debugging
┌─────────────────────────────────────────────────────────────┐
│ │
│ ┌──────────┐ same prompt ┌──────────┐ │
│ │ │ ───────────────▶ │ │ │
│ │ ralph │ │ OpenCode │ │
│ │ CLI │ ◀─────────────── │ │ │
│ │ │ output + files │ │ │
│ └──────────┘ └──────────┘ │
│ │ │ │
│ │ check for │ modify │
│ │ <promise> │ files │
│ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ Complete │ │ Git │ │
│ │ or │ │ Repo │ │
│ │ Retry │ │ (state) │ │
│ └──────────┘ └──────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
- Ralph sends your prompt to OpenCode
- OpenCode works on the task, modifies files
- Ralph checks output for completion promise
- If not found, repeat with same prompt
- AI sees previous work in files
- Loop until success or max iterations
ralph-wiggum/
├── bin/ralph.js # CLI entrypoint (npm wrapper)
├── ralph.ts # Main loop implementation
├── package.json # Package config
├── install.sh / install.ps1 # Installation scripts
└── uninstall.sh / uninstall.ps1 # Uninstallation scripts
During operation, Ralph stores state in .opencode/:
ralph-loop.state.json- Active loop stateralph-history.json- Iteration history and metricsralph-context.md- Pending context for next iteration
npm uninstall -g @th0rgal/ralph-wiggumnpm uninstall -g @th0rgal/ralph-wiggumCheck out OpenAgent - a dashboard for orchestrating AI agents with workspace management, real-time monitoring, and multi-agent workflows.
MIT
