Ralph is a single-shot autonomous agent for OpenCode that breaks complex tasks into small, verifiable iterations.
Instead of trying to complete a big task in one shot (which often leads to context bloat and mistakes), Ralph:
- Does one small unit of work - creates a few files, fixes one error, adds one feature
- Commits progress - meaningful git commits after each step
- Updates state - tracks what's done, what's remaining, any blockers
- Exits - outputs a "promise" of current status
- Gets re-invoked - the plugin creates a fresh session and continues
This loop repeats until the task is DONE or BLOCKED. Each iteration has fresh context, so Ralph can handle tasks that would normally exceed context limits.
/ralph add user authentication with email/password --auto
Ralph might:
- Iteration 1: Create user model and migration
- Iteration 2: Add registration endpoint
- Iteration 3: Add login endpoint
- Iteration 4: Add middleware for protected routes
- Iteration 5: Write tests
- Iteration 6: Run tests, fix failures
- Iteration 7: Verify everything works, mark DONE
Copy the files to your OpenCode config directory:
# Create directories if they don't exist
mkdir -p ~/.config/opencode/plugin
mkdir -p ~/.config/opencode/command
# Copy files
cp plugin/ralph-auto-loop.ts ~/.config/opencode/plugin/
cp command/ralph.md ~/.config/opencode/command/
cp command/ralph-reset.md ~/.config/opencode/command/
# Copy package.json (or merge if you have existing dependencies)
cp package.json ~/.config/opencode/
# Install dependencies
cd ~/.config/opencode && npm install
# or: bun install / pnpm installRestart OpenCode after installation.
/ralph <goal> Run one iteration
/ralph <goal> --auto Auto-loop until done or blocked
/ralph <goal> --max 20 Set max iterations (default: 10, cap: 50)
/ralph <goal> --dry-run Plan only, no file changes
/ralph <goal> --strict Avoid destructive commands
/ralph-reset Clear state and start fresh
- Each
/ralphinvocation does ONE unit of work, then stops - State is persisted in
.ralph-state.jsonin your project - In
--automode, the plugin detects when Ralph finishes and re-invokes with fresh context - Loop continues until status is DONE or BLOCKED
| File | Purpose |
|---|---|
plugin/ralph-auto-loop.ts |
Plugin that handles auto-loop and session management |
command/ralph.md |
Main Ralph command with all the prompting |
command/ralph-reset.md |
Helper to clear Ralph state |
package.json |
Dependencies (@opencode-ai/plugin) |
- Ctrl+C during an iteration
- Edit
.ralph-state.jsonand set"auto": false - Run
/ralph-resetto clear all state