npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@th0rgal/ralph-wiggum

v1.0.9

Published

Ralph Wiggum technique for OpenCode - iterative AI development loops with self-correcting agents

Readme


What is Ralph?

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."
done

The 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.

Why Ralph?

| 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 |

Installation

Prerequisites: Bun and OpenCode

npm (recommended)

npm install -g @th0rgal/ralph-wiggum

Bun

bun add -g @th0rgal/ralph-wiggum

From source

git clone https://github.com/Th0rgal/ralph-wiggum
cd opencode-ralph-wiggum
./install.sh
git clone https://github.com/Th0rgal/ralph-wiggum
cd opencode-ralph-wiggum
.\install.ps1

This installs:

  • ralph CLI command (global)

Quick Start

# 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 20

Commands

Running a Loop

ralph "<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

Monitoring & Control

# 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-context

Status Dashboard

The --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"

Mid-Loop Context Injection

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.

Troubleshooting

"ralph-wiggum" plugin errors

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-plugins

"bun: command not found"

Install Bun: https://bun.sh

Writing Good Prompts

Include Clear Success Criteria

❌ 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.

Use Verifiable Conditions

❌ 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.

Always Set Max Iterations

# Safety net for runaway loops
ralph "Your task" --max-iterations 20

When to Use Ralph

Good 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

How It Works

┌─────────────────────────────────────────────────────────────┐
│                                                             │
│   ┌──────────┐    same prompt    ┌──────────┐              │
│   │          │ ───────────────▶  │          │              │
│   │  ralph   │                   │ OpenCode │              │
│   │   CLI    │ ◀─────────────── │          │              │
│   │          │   output + files  │          │              │
│   └──────────┘                   └──────────┘              │
│        │                              │                     │
│        │ check for                    │ modify              │
│        │ <promise>                    │ files               │
│        ▼                              ▼                     │
│   ┌──────────┐                   ┌──────────┐              │
│   │ Complete │                   │   Git    │              │
│   │   or     │                   │  Repo    │              │
│   │  Retry   │                   │ (state)  │              │
│   └──────────┘                   └──────────┘              │
│                                                             │
└─────────────────────────────────────────────────────────────┘
  1. Ralph sends your prompt to OpenCode
  2. OpenCode works on the task, modifies files
  3. Ralph checks output for completion promise
  4. If not found, repeat with same prompt
  5. AI sees previous work in files
  6. Loop until success or max iterations

Project Structure

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

State Files (in .opencode/)

During operation, Ralph stores state in .opencode/:

  • ralph-loop.state.json - Active loop state
  • ralph-history.json - Iteration history and metrics
  • ralph-context.md - Pending context for next iteration

Uninstall

npm uninstall -g @th0rgal/ralph-wiggum
npm uninstall -g @th0rgal/ralph-wiggum

Learn More

See Also

Check out OpenAgent - a dashboard for orchestrating AI agents with workspace management, real-time monitoring, and multi-agent workflows.

License

MIT