| name | ralph-loop-setup |
| description | Sets up autonomous TDD loops at project level. Use when installing Ralph loops in projects, updating hooks based on latest practices, or troubleshooting loop behavior. Based on Ryan Carson's Ralph Wiggum technique. |
| allowed-tools | Bash, Read, Glob, Write, Edit |
Ralph Loop Setup Skill
Set up and maintain autonomous TDD loops for iterative development with verification feedback.
When This Activates
- User asks to "set up Ralph" or "add autonomous loop" to a project
- User wants to update Ralph hooks based on latest practices
- Troubleshooting loop behavior (not iterating, verification failing)
- Setting up a new project for autonomous development
What is Ralph?
The Ralph Wiggum technique is an autonomous TDD workflow where Claude iteratively works on tasks until a verification command passes and a completion promise is detected.
Key components:
- Start Command - Initializes loop with task and options
- Loop Mechanism - Either stop hook (same-session) or external script (fresh-context)
- State File - Tracks iteration count, completion promise
- Context Files -
progress.md for cross-session memory, prd.json for tasks, guardrails.md for learned constraints
Two Architectural Modes
Ralph supports two fundamentally different loop architectures. Fresh-context is the default for multi-task mode because it follows the true Ralph pattern: deliberate rotation, not accidental compaction.
Fresh-Context (Default for --next)
Uses an external bash script that spawns new Claude sessions each iteration.
/ralph-loop --next
./scripts/ralph/ralph.sh --max-iterations 100
Pros: Each iteration starts clean, no context pollution, failures evaporate, true re-anchoring.
Cons: More complex setup, loses conversation context.
Best for: Multi-task backlogs, long runs (20+ iterations).
Same-Session (Opt-In)
Uses Claude Code's stop hook to block exit and re-prompt within the same session.
/ralph-loop "Fix all TypeScript errors"
/ralph-loop --next --same-session
Pros: Simpler setup, works within Claude Code's native system, preserves conversation context.
Cons: Context accumulates, failed attempts stay in transcript.
Best for: Bounded single tasks, short runs (under 20 iterations).
This follows Geoffrey Huntley's original vision, Gordon Mickel's flow-next, and Agrim Singh's "ralph for idiots" insight that Anthropic's same-session pattern is "anti-ralph" because it accumulates context until it rots.
Installation
To add Ralph loops to a project:
/ralph-loop-setup
This creates:
.claude/commands/ralph-loop.md - Start command (supports both modes)
.claude/commands/ralph-cancel.md - Cancel/stop command (both modes)
.claude/commands/ralph-planner.md - Plan tasks from GitHub issues
.claude/hooks/stop-hook.sh - Same-session verification hook
.claude/settings.json - Hook registration (or updates existing)
scripts/ralph/ralph.sh - Fresh-context external loop
scripts/ralph/ralph-stop.sh - Stop script (kills processes, cleans state)
scripts/ralph/ralph-status.sh - Status dashboard script
scripts/ralph/ralph-tail.sh - Log tail helper
plans/progress.md - Cross-session context
plans/guardrails.md - Learned constraints ("signs") that prevent repeated failures
plans/prd.json - Task tracking
Usage
Once installed:
/ralph-loop "Fix all TypeScript errors" --max-iterations 20
/ralph-loop --next
/ralph-loop --next --max-iterations 100
/ralph-loop --next --verbose
/ralph-loop --next --monitor
/ralph-loop --next --verbose --monitor
/ralph-loop --next --same-session
/ralph-loop --next --screenshots
/ralph-loop --next --branch ralph/backlog
/ralph-loop --next --dry-run
/ralph-cancel
/ralph-cancel --force
./scripts/ralph/ralph.sh --max-iterations 100 --branch ralph/backlog --verbose --monitor
Monitoring
Ralph provides several tools to monitor loop progress in real-time.
Verbose Mode (--verbose)
Adds detailed output during iterations:
- Timing for Claude sessions and verification runs
- Last 10 lines of output after each iteration
- File path logging
./scripts/ralph/ralph.sh --verbose
/ralph-loop --next --verbose
Auto-Monitor (--monitor)
Automatically opens a status dashboard in a new terminal window (macOS only).
./scripts/ralph/ralph.sh --monitor
/ralph-loop --next --monitor
Terminal detection: Prefers iTerm2 if installed/running, falls back to Terminal.app.
Status Dashboard
View loop status, task progress, and recent output:
./scripts/ralph/ralph-status.sh
./scripts/ralph/ralph-status.sh --watch
Shows:
- Loop status with colored indicators (RUNNING, VERIFYING, COMPLETE)
- Progress bar and iteration count
- Current task being worked on
- Task checklist with completion status
- Recent runs history
- Last 8 lines of current output
Log Tailing
Follow iteration output in real-time:
./scripts/ralph/ralph-tail.sh
./scripts/ralph/ralph-tail.sh --all
./scripts/ralph/ralph-tail.sh 20260113-120000
Status JSON File
Machine-readable status at .claude/ralph-status.local.json:
{
"run_id": "20260113-120000",
"iteration": 3,
"max_iterations": 50,
"status": "running",
"current_task": {"id": "T-001", "title": "..."},
"remaining_tasks": 2,
"started_at": "2026-01-13T12:00:00-08:00",
"updated_at": "2026-01-13T12:05:30-08:00",
"branch": "main",
"log_file": "scripts/ralph/runs/20260113-120000/iteration-3.txt"
}
Branch Handling Options
Ralph supports two ways to manage branches:
Option 1: CLI Flag (per-run)
Specify branch when starting the loop:
/ralph-loop --next --branch ralph/backlog-cleanup
/ralph-loop "Fix bugs" --branch feature/bugfix
Best for: Ad-hoc runs, different branches per task batch.
Option 2: prd.json branchName (per-batch)
Set branchName in prd.json for all tasks in that batch:
{
"branchName": "feature/my-feature",
"features": [...]
}
Then just run:
/ralph-loop --next
Ralph will automatically checkout/create the branch from prd.json.
Best for: Consistent branch for a set of related tasks.
Priority
If both are specified, --branch flag takes precedence over prd.json branchName.
Skipping Tasks
Some tasks cannot be automated (e.g., creating accounts, configuring API keys in dashboards). Use the skip field to exclude these from the loop while keeping them in prd.json for tracking.
prd.json Schema
{
"id": "T-003",
"title": "Configure API credentials",
"github_issue": 83,
"passes": false,
"skip": true,
"skipReason": "Requires manual account creation and API key setup",
"notes": "Human needs to complete this manually"
}
Behavior
- Tasks with
skip: true are excluded from task selection
- Loop can complete successfully even with skipped tasks remaining
- Status dashboard shows skipped tasks with
⊘ indicator
- Skipped tasks still count toward total but not toward "remaining"
When to Skip
- Account/credential setup requiring human login
- Dashboard configuration in external services
- Tasks requiring physical access or approval workflows
- Anything with "manual" in the acceptance criteria
Ralph Planner
Use /ralph-planner to generate prd.json entries from GitHub issues:
/ralph-planner
/ralph-planner --labels bug,P1
/ralph-planner --milestone v2.0
/ralph-planner --limit 10
Features
- Fetches open issues from GitHub via
gh issue list
- Analyzes issues for automatable scope
- Detects manual tasks and suggests
skip: true
- Extracts acceptance criteria from issue body
- Sets priority from labels (P0→high, P1→high, P2→medium, etc.)
- Avoids duplicates (skips issues already in prd.json)
Output
Adds new entries to plans/prd.json with proper structure. Run /ralph-loop --next --dry-run after planning to preview.
Guardrails (Signs)
Guardrails are learned constraints that prevent repeated failures. They persist in plans/guardrails.md and are read at the start of each iteration.
Philosophy: Progress should persist. Failures should evaporate.
Seed Guardrails
The template includes seed signs that prevent common pitfalls:
- SIGN-001: Verify Before Complete - Run verification before outputting completion promise
- SIGN-002: Check All Tasks Before Complete - Re-read prd.json to confirm ALL tasks pass
- SIGN-003: Document Learnings - Update progress.md with patterns discovered
- SIGN-004: Small Focused Changes - Keep changes incremental
- SIGN-005: Use Skip for Manual Tasks - Set
skip: true for tasks requiring human intervention
- SIGN-006: Reference GitHub Issues in Commits - Include
Fixes #N in commit messages
Adding New Signs
When Ralph makes a repeated mistake, add a sign to prevent it:
### SIGN-XXX: [Descriptive Name]
**Trigger:** [When this applies]
**Instruction:** [What to do instead]
**Reason:** [Why this matters]
**Added after:** [Iteration N / date when learned]
Signs are append-only. Mistakes evaporate, lessons accumulate.
Visual Screenshots (UI Regression Review)
The --screenshots flag instructs Claude to capture visual screenshots via Playwright MCP. This helps catch UI/UX regressions that tests don't catch.
Note: In Playwright terminology, a "snapshot" is an accessibility/DOM tree capture, while a "screenshot" is a visual PNG/JPEG image. This feature uses browser_take_screenshot for visual captures.
How It Works
- Fresh-context mode: The
--screenshot flag is passed to ralph.sh, which adds Playwright instructions to the prompt
- Same-session mode: The state file includes
screenshots: true, prompting Claude to use Playwright MCP
- Output: Screenshots saved to
scripts/ralph/runs/{run-id}/screenshots/
Usage
/ralph-loop --next --screenshots
./scripts/ralph/ralph.sh --screenshot
Playwright MCP Tools Used
When --screenshots is enabled, Claude uses:
browser_navigate - Navigate to key pages
browser_take_screenshot - Capture visual PNG screenshots
Output Location
Screenshots are saved in the run directory:
scripts/ralph/runs/20260113-120000/
└── screenshots/
├── iteration-1-dashboard.png
├── iteration-1-settings.png
└── iteration-3-final.png
Important: Screenshots are advisory, non-blocking. Tests passing is the gate; visual review is recommended but doesn't block completion.
Project Requirements
Ralph loops work best with projects that have:
-
Verification command - A single command that validates code quality
- Node/Next.js:
pnpm verify (test + tsc + lint)
- Python:
make check or pytest && mypy && ruff
- Go:
go test ./... && go vet ./...
-
Clear acceptance criteria - Tasks with measurable completion
-
Test coverage - Automated tests for feedback
Customization
Verification Command
Edit .claude/hooks/stop-hook.sh:
VERIFY_OUTPUT=$(pnpm verify 2>&1) || true
Context Files Location
Default location is plans/. Edit the start command to change:
# In .claude/commands/ralph-loop.md
1. **Read plans/progress.md** → Change to your path
2. **Check plans/prd.json** → Change to your path
Templates
See the templates directory for:
Troubleshooting
Loop not iterating
- Check if
.claude/settings.json has correct hook registration
- Verify hook format is v2.1:
{"type": "command", "command": "..."}
- Check if state file
.claude/ralph-loop.local.md exists
Verification not running
- Ensure hook is executable:
chmod +x .claude/hooks/stop-hook.sh
- Check if verification command works standalone
- Look for
jq dependency (required for JSON output)
Premature completion
- Verify completion promise format:
<promise>COMPLETE</promise>
- Check transcript for promise detection
- Increase max iterations if needed
Branch not switching
- Check
--branch flag syntax: --branch branch-name (no =)
- Verify prd.json has
branchName at top level (not inside tasks)
- Ensure no uncommitted changes blocking checkout
Reference
Maintenance
See maintenance.md for on-demand cleanup tasks:
- Progress log cleanup - Archive and truncate
progress.md when it gets long
- PRD cleanup - Archive completed tasks from
prd.json
- Run logs cleanup - Remove old fresh-context run directories
Related Skills
- managing-context - Handoffs for manual session continuity
- frontmatter-scanner - Scanning files for context