Autonomous coding loop for Claude Code. PRD-based workflow with bash implementation.
If you are an AI agent (Claude Code, Codex, etc.) working on Ralph CLI tasks:
👉 Start here: ui/public/docs/agent-guide.html or http://localhost:3000/docs/agent-guide.html
The Agent Guide provides:
- ⚡ Quick-start summary with critical rules
- 🎯 Decision trees for command selection
- 📋 Common task patterns with examples
- 🚨 Critical warnings (--headless, merge policy)
- 📍 Task-based section pointers
This file (CLAUDE.md) is the comprehensive reference for:
- Installation & setup details
- Complete command documentation
- Configuration options
- Technical implementation details
- Troubleshooting procedures
Use this workflow:
- Check agent-guide.html for task patterns and critical rules
- Reference CLAUDE.md sections for detailed configuration/troubleshooting
- Use
ralph error RALPH-XXXfor error remediation
Context-specific guidance (NEW):
For context-aware agent guidance, check the local AGENTS.md file in your working directory:
- In root: AGENTS.md - Core Ralph agent rules and decision trees
- In
.agents/ralph/: .agents/ralph/AGENTS.md - Build loop guidance - In
skills/prd/: skills/prd/AGENTS.md - PRD generation rules (CRITICAL: --headless flag) - In
skills/commit/: skills/commit/AGENTS.md - Conventional commit format - In
skills/factory/: skills/factory/AGENT_GUIDE.md - Factory workflows - In
skills/ue-agent/: skills/ue-agent/AGENTS.md - UE multi-agent orchestration - In
ui/: ui/AGENTS.md - UI testing guidance - In
tests/: tests/AGENTS.md - Test writing rules
These files provide right-time context for the task at hand, reducing token usage and eliminating redundancy.
| Use Case | Command |
|---|---|
| Install (Mac/Linux) | curl -fsSL https://raw.githubusercontent.com/AskTinNguyen/ralph-cli/main/install.sh | bash |
| Install (Windows) | iwr -useb https://raw.githubusercontent.com/AskTinNguyen/ralph-cli/main/install.ps1 | iex |
| Install (manual) | git clone https://github.com/AskTinNguyen/ralph-cli.git && cd ralph-cli && npm i && npm link |
| Install to project | ralph install |
| Generate PRD | ralph prd |
| Create plan from PRD | ralph plan (uses latest PRD) |
| Plan specific PRD | ralph plan --prd=1 |
| Run build iterations | ralph build 5 |
| Build specific PRD | ralph build 5 --prd=1 |
| Dry run (no commit) | ralph build 1 --no-commit |
| Factory run | ralph factory run my-factory |
| Factory status | ralph factory status my-factory |
| Use Case | Command |
|---|---|
| List PRDs | ralph stream list |
| Show status | ralph stream status |
| Init worktree | ralph stream init 1 |
| Build in stream | ralph stream build 1 5 |
| Build (no worktree) | ralph stream build 1 5 --no-worktree |
| Build (force) | ralph stream build 1 5 --force |
| Run parallel | ralph stream build 1 & ralph stream build 2 & |
| Merge stream | ralph stream merge 1 |
Factory Mode enables declarative, multi-stage agent workflows with verification gates. Use it for complex pipelines, recursive workflows, and production-grade automation.
| Use Case | Command |
|---|---|
| Create factory | ralph factory init my-factory |
| Run factory | ralph factory run my-factory |
| Check status | ralph factory status my-factory |
| Resume failed | ralph factory resume my-factory |
| List factories | ralph factory list |
Key Features:
- Chained workflows: PRD → Plan → Build pipelines
- Conditional branching: Execute different paths based on results
- Recursive loops: Auto-retry failed stages with context
- Verification gates: Tamper-resistant checks (tests, git, builds)
Verification gates prevent gaming - agents cannot claim success by outputting "All tests pass!" - the verification system actually runs tests and checks results.
Documentation:
Text-to-speech for Claude Code responses using local Qwen LLM summarization.
| Use Case | Command |
|---|---|
| Setup (first time) | ralph install (shows auto-speak setup guidance) |
| Enable auto-speak | ralph speak --auto-on |
| Disable auto-speak | ralph speak --auto-off |
| Check status | ralph speak --auto-status |
| Speak text | ralph speak "Hello world" |
| Recap (medium) | ralph recap |
| Recap (detailed) | ralph recap --full |
| Recap (preview) | ralph recap --preview |
Auto-speak: Short ~20-word summaries spoken automatically after each response. Recap: On-demand longer summaries (~100-200 words) when you want more detail.
Auto-speak requires:
- Dependencies: Ollama + qwen2.5:1.5b model, jq, TTS provider (macOS say/VieNeu/Piper)
- Claude Code hooks: Add hooks to
~/.claude/settings.local.json - Voice config:
.ralph/voice-config.json(auto-created byralph install)
Automatic setup (recommended):
# Install Ralph to your project
ralph install
# Follow the auto-speak setup prompts to:
# - Check dependencies
# - Create voice config
# - Get hook configuration instructionsManual hook setup:
# Option A: Automated (uses jq to safely modify config)
.agents/ralph/setup/post-install.sh
# Option B: Manual (copy/paste to ~/.claude/settings.local.json)
# See hook snippet in setup guidance or docs/guides/voice/auto-speak-guide.mdInstall missing dependencies:
# macOS
brew install ollama jq
ollama pull qwen2.5:1.5b
# TTS: macOS has built-in 'say' command
# Linux
# Install Ollama: https://ollama.com/install
sudo apt install jq # or use your package manager
ollama pull qwen2.5:1.5b
# TTS: Install Piper or VieNeu-TTSVieNeu-TTS (Vietnamese voice cloning):
# During ralph init wizard
? Install VieNeu-TTS for Vietnamese voice support? Yes
# Or manually
.agents/ralph/setup/vieneu-setup.shVoice config location: .ralph/voice-config.json
Key settings:
ttsEngine: "macos" (say), "vieneu" (Vietnamese), "piper" (Linux)autoSpeak.enabled: true/false (toggle viaralph speak --auto-on/off)autoSpeak.maxWords: 20 (summary length)headlessAlwaysSpeak: true (enable in headless mode)initialDelaySeconds: 5 (first progress phrase delay)
Headless mode (Ralph build): Auto-speak works in headless mode with these defaults:
headlessAlwaysSpeak: true- Bypasses session-start detectioninitialDelaySeconds: 5- First progress phrase after 5 seconds- Force headless mode:
export RALPH_HEADLESS=true
| Issue | Solution |
|---|---|
| No voice output | Run ralph speak --auto-status to check configuration |
| Missing dependencies | Run ralph install again to see dependency status |
| Hooks not working | Verify hooks in ~/.claude/settings.local.json, restart Claude Code |
| "jq not found" | Install jq: brew install jq (macOS) or apt install jq (Linux) |
| "ollama not found" | Install Ollama: https://ollama.com/install |
| "qwen model not found" | Run ollama pull qwen2.5:1.5b |
Uninstall hooks:
.agents/ralph/setup/remove-hooks.shFull guide:
docs/guides/voice/VOICE.mdFeature history:docs/guides/voice/VOICE_CHANGELOG.md
Documentation:
- For AI Agents:
skills/factory/AGENT_GUIDE.md- Concise guide with patterns and decision trees- Full Reference:
skills/factory/SKILL.md- Complete YAML schema, verification types, examples- UI Guide: http://localhost:3000/docs/factory-guide.html (when UI server running)
Each ralph plan creates a new isolated folder (PRD-1, PRD-2, ...) to prevent plans from being overwritten:
- PRD → Define requirements:
ralph prd(creates.ralph/PRD-N/prd.md) - Plan → Break into stories:
ralph plan(uses latest PRD) orralph plan --prd=1(specific PRD) - Build → Execute stories:
ralph build Norralph build N --prd=1 - Merge → MANUAL STEP (worktree only): Review changes, then
ralph stream merge N
Merge Safety: Builds NEVER auto-merge. When using worktrees, you must explicitly run ralph stream merge N after reviewing changes. Direct-to-main builds don't require merging.
- Create multiple PRDs: Run
ralph prdmultiple times (creates PRD-1, PRD-2, ...) - Edit PRDs:
.ralph/PRD-N/prd.md - Init worktrees (optional):
ralph stream init N - Run in parallel:
ralph stream build 1 & ralph stream build 2 & - Wait for completion: Monitor build progress via
ralph stream status - Review changes:
git log main..ralph/PRD-N, run tests, validate output - Merge completed:
ralph stream merge N(requires human confirmation)
Merge Safety: Ralph NEVER auto-merges worktree branches. Each merge requires:
- Explicit human command:
ralph stream merge N - Interactive confirmation prompt (or
--yesflag for automation) - All merges are auditable and reversible
Each plan is stored in its own isolated folder to prevent conflicts:
project/
├── .agents/
│ └── ralph/ # Loop templates
│ ├── loop.sh # Main execution loop
│ ├── stream.sh # Multi-stream commands
│ └── config.sh # Agent configuration
└── .ralph/
├── PRD-1/ # First plan (isolated)
│ ├── prd.md # PRD document
│ ├── plan.md # Implementation plan (stories)
│ ├── progress.md # Progress log
│ └── runs/ # Run logs
├── PRD-2/ # Second plan (isolated)
│ ├── prd.md
│ ├── plan.md
│ ├── progress.md
│ └── runs/
├── guardrails.md # Shared lessons learned
├── locks/ # Stream locks (prevent concurrent runs)
├── worktrees/ # Git worktrees for parallel execution
│ ├── PRD-1/ # Isolated working directory
│ └── PRD-2/
└── factory/ # Factory mode (meta-orchestration)
├── my-factory.yaml # Factory definitions
├── learnings.json # Project-wide learnings
└── runs/ # Execution history
└── run-TIMESTAMP/
├── state.json # Checkpoint state
└── stages/ # Per-stage results
Key principle: Plans are NEVER stored in a centralized location. Each ralph plan auto-increments to the next available PRD-N folder.
# Product Requirements Document
## Overview
What we're building and why.
## User Stories
### [ ] US-001: Story title
**As a** user
**I want** feature
**So that** benefit
#### Acceptance Criteria
- [ ] Criterion 1
- [ ] Criterion 2Stories are marked [x] when complete.
Set in .agents/ralph/config.sh or via CLI flag:
# Use Claude (default - recommended)
ralph build 1 --agent=claude
# Use Codex (OpenAI - no Claude model routing)
ralph build 1 --agent=codex
# Use Droid (Factory.ai - no Claude model routing)
ralph build 1 --agent=droidAgent/Model Compatibility:
- Claude agent: Full support for model routing (haiku, sonnet, opus)
- Codex/Droid: Model routing auto-disabled; uses provider's default model
If you try to use a non-Claude agent with model routing enabled, Ralph will:
- Display a warning message
- Auto-disable model routing for that session
- Suggest using
--agent=claudeor disabling routing
Ralph can automatically select the optimal Claude model based on task complexity. Configure in .agents/ralph/config.sh or via ralph init.
| Tier | Score | Default Model | Use Case |
|---|---|---|---|
| Low | 1-3 | Haiku | Simple fixes, docs, typos |
| Medium | 4-7 | Sonnet | Features, refactoring |
| High | 8-10 | Opus | Architecture, complex changes |
# Enable/disable complexity-based model routing
RALPH_ROUTING_ENABLED=true
# Model for LOW complexity tasks (score 1-3)
RALPH_LOW_COMPLEXITY_MODEL=haiku
# Model for MEDIUM complexity tasks (score 4-7)
RALPH_MEDIUM_COMPLEXITY_MODEL=sonnet
# Model for HIGH complexity tasks (score 8-10)
RALPH_HIGH_COMPLEXITY_MODEL=opus
# Default model when routing is disabled
RALPH_DEFAULT_MODEL=sonnet
# Customize complexity thresholds (advanced)
RALPH_HAIKU_MAX_COMPLEXITY=3 # Scores 1-3 use LOW model
RALPH_SONNET_MAX_COMPLEXITY=7 # Scores 4-7 use MEDIUM model# Force a specific model for one build
ralph build 5 --model=opus
# Force model for stream build
ralph stream build 1 5 --model=haikuTo use Opus for all tasks regardless of complexity:
# Option 1: Disable routing, set default
RALPH_ROUTING_ENABLED=false
RALPH_DEFAULT_MODEL=opus
# Option 2: Set all tiers to Opus
RALPH_ROUTING_ENABLED=true
RALPH_LOW_COMPLEXITY_MODEL=opus
RALPH_MEDIUM_COMPLEXITY_MODEL=opus
RALPH_HIGH_COMPLEXITY_MODEL=opusRun ralph init to configure model routing interactively:
? Enable complexity-based model routing? Yes
? Model for LOW complexity tasks (1-3)? Haiku (recommended)
? Model for MEDIUM complexity tasks (4-7)? Sonnet (recommended)
? Model for HIGH complexity tasks (8-10)? Opus (recommended)
┌ Model Routing Configuration ─────────────────┐
│ Low (1-3) → haiku │
│ Medium (4-7) → sonnet │
│ High (8-10) → opus │
└──────────────────────────────────────────────┘
Note: Model routing configuration is only shown for Claude agent. Non-Claude agents (Codex, Droid) skip this step.
The ralph prd command supports two execution modes:
Usage: ralph prd "Feature description"
- Used when a human runs the command in a terminal
- Agent runs interactively with full terminal output
- Real-time progress and thinking visible to user
- Suitable for development and manual workflows
Example:
# Human running in terminal
ralph prd "Build a user authentication system"Usage: ralph prd "Feature description" --headless
- Required for server/UI/background execution
- Agent runs with piped stdin (no interactive prompts)
- Output captured programmatically for streaming
- Prevents TTY conflicts and hanging processes
When to use --headless:
- ✅ UI server triggering PRD generation
- ✅ CI/CD pipelines and automation scripts
- ✅ Background jobs and daemons
- ✅ When Claude Code agent executes
ralph prd(avoids nested interaction) - ✅ Any context where stdin is not an interactive terminal
Examples:
# UI server (always use --headless)
ralph prd "Feature description" --headless
# Claude Code agent calling ralph
ralph prd "Add dashboard feature" --headless
# CI/CD pipeline
ralph prd "Automated test suite" --headless
# Background process
nohup ralph prd "Long-running task" --headless > prd.log 2>&1 &Important: The Ralph UI server (ui/) automatically uses --headless mode (see ui/src/services/wizard-process-manager.ts:126) to prevent process hangs.
Ralph includes a simplified loop that delegates enforcement to Claude Code hooks instead of inline validation.
| Component | Lines | Purpose |
|---|---|---|
simplified-loop.sh |
~200 | Core iteration loop |
lib/minimal.sh |
~160 | Essential utilities |
hooks/pre-tool.sh |
~120 | PreToolUse validation |
hooks/post-tool.sh |
~150 | Test failure detection |
hooks/on-stop.sh |
~85 | Completion validation |
hooks/pre-prompt.sh |
~55 | Session management |
| Total | ~770 | vs 4,244 in loop.sh |
# Run simplified loop
.agents/ralph/simplified-loop.sh 5 # 5 iterations
.agents/ralph/simplified-loop.sh --prd=2 # Specific PRD
.agents/ralph/simplified-loop.sh --dry-run # Dry runPreToolUse (pre-tool.sh):
- Blocks Edit/Write without prior Read
- Blocks
git push,git merge,git --force - Blocks
ralph stream merge
PostToolUse (post-tool.sh):
- Detects test failures (Jest, Vitest, pytest, Go, Mocha, RSpec, Bats)
- Triggers automatic rollback to checkpoint
- Logs failure context for retry
Stop (on-stop.sh):
- Validates story completion
- Cleans up temporary files
- Logs incomplete sessions
- Hooks MUST exit 0 - Non-zero exit breaks Claude Code
- Validate JSON before parsing - Prevents injection attacks
- Use fixed-string grep - Security for path lookups
- Atomic file operations - Temp file + mv pattern
The post-tool hook detects failures from multiple frameworks:
| Framework | Detection Pattern |
|---|---|
| Jest | Tests: X failed, Test Suites: X failed |
| Vitest | Same as Jest |
| pytest | = FAILURES =, X failed, |
| Go test | --- FAIL:, FAIL\t |
| Mocha | X failing |
| RSpec | X examples, Y failures |
| Bats | not ok |
Add to ~/.claude/settings.local.json:
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash|Edit|Write",
"hooks": [{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.agents/ralph/hooks/pre-tool.sh"}]
}],
"PostToolUse": [{
"matcher": "Bash|Edit|Write",
"hooks": [{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.agents/ralph/hooks/post-tool.sh"}]
}],
"Stop": [{
"hooks": [{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.agents/ralph/hooks/on-stop.sh"}]
}],
"UserPromptSubmit": [{
"hooks": [{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.agents/ralph/hooks/pre-prompt.sh"}]
}]
}
}ralph-cli/
├── bin/ralph # Node.js CLI entry point
├── .agents/ralph/ # Bash loop implementation
│ ├── loop.sh # Main execution loop (4,244 lines)
│ ├── simplified-loop.sh # Simplified loop with hooks (~200 lines)
│ ├── PROMPT_build.md # Build iteration prompt
│ ├── PROMPT_plan.md # Planning prompt
│ ├── PROMPT_simplified.md # Simplified loop prompt
│ ├── hooks/ # Claude Code hooks
│ │ ├── pre-tool.sh # PreToolUse validation
│ │ ├── post-tool.sh # PostToolUse enforcement
│ │ ├── on-stop.sh # Stop cleanup
│ │ └── pre-prompt.sh # Session management
│ └── lib/
│ └── minimal.sh # Minimal utilities
├── skills/ # Optional agent skills
│ ├── commit/ # Git commit helper
│ └── prd/ # PRD generation
├── tests/ # Test files (IMPORTANT: ALL tests go here)
│ ├── *.mjs # Integration and E2E tests
│ ├── test-*.js # Unit tests
│ ├── simplified-loop.test.sh # Simplified loop tests
│ ├── fixtures/ # Test fixtures
│ │ └── hooks/ # Hook test fixtures
│ ├── helpers/ # Test utilities
│ └── mocks/ # Mock implementations
└── package.json
Testing Rules:
- ✅ All test files must be in
/testsdirectory - ✅ Integration/E2E tests use
.mjsextension - ✅ Unit tests use
test-*.jsnaming pattern - ❌ Never place test files in
/lib,/bin, or other source directories
Full testing guide: See
docs/guides/testing/TESTING.mdfor comprehensive documentation on test organization and best practices.
- PRD:
ralph prdgenerates requirements document in.ralph/PRD-N/prd.md - Plan:
ralph plancreatesplan.mdwith ordered stories in the same PRD-N folder - Build:
ralph build Nruns N iterations ofloop.shagainst the active PRD - Loop: Each iteration picks next unchecked story, executes, commits, marks done
Isolation guarantee: Each plan lives in its own PRD-N folder. Plans are never overwritten by subsequent ralph plan calls - a new PRD-N+1 folder is created instead.
The loop is stateless - each iteration reads files, does work, writes results.
IMPORTANT: Git commits are the ultimate source of truth for PRD status. Checkboxes are only progress markers.
How it works:
- Git is authoritative: Status checks git history for actual commits, not checkboxes
- Two completion workflows:
merged: Worktree workflow - branch merged to main via PR (.mergedmarker)completed: Direct-to-main workflow - commits directly on main (.completedmarker)
- Auto-correction: Missing
.completedmarkers auto-created when git shows commits - Checkboxes are hints: Used by agents during work, not for status determination
Status detection hierarchy:
running: Lock file exists with active PIDmerged: Branch merged to main (git merge-base check)completed: Commits found on main (progress.md hashes + git log search)in_progress: progress.md exists but no commits foundready: plan.md exists but no progress yet
Why this matters:
- Correctly identifies PRDs completed via direct-to-main workflow (no worktree)
- Checkboxes can't be trusted as proof of work - only git commits matter
- Prevents false status when checkboxes aren't updated
Manual verification:
# Check if PRD has commits on main
git log --oneline --grep="PRD-N"
# Verify specific commits from progress.md
grep "Commit:" .ralph/PRD-N/progress.md
# See all commits for a PRD
git log --all --oneline | grep -i "PRD-N\|US-00"New status commands:
# Mark PRD as completed (direct-to-main workflow)
ralph stream mark-completed N
# Remove completion marker
ralph stream unmark-completed N
# Auto-scan and fix all stale status markers
ralph stream verify-statusCommon issues:
- Checkbox marked but no commits: Status = "in_progress" (work not committed yet)
- Commits exist but shows "ready": Run
ralph stream verify-statusto auto-correct - Want to distinguish worktree vs direct builds: Check for
.mergedvs.completedmarker files - Direct-to-main PRD shows wrong status:
get_stream_status()will auto-create.completedmarker on first status check
Ralph agents have access to MCP (Model Context Protocol) servers for external integrations. Configuration is in .mcp.json.
| Server | Purpose | Status | Env Variable |
|---|---|---|---|
| Notion | Docs, databases, task tracking | Auto-start | NOTION_API_KEY |
| Slack | Team notifications, context search | Auto-start | SLACK_BOT_TOKEN, SLACK_TEAM_ID |
| GitHub | Issues, PRs, code search | Auto-start | GITHUB_TOKEN |
| Miro | Visual diagrams, boards | Auto-start | MIRO_API_TOKEN |
- Set required environment variables in your shell or
.env - MCP servers auto-start when Claude Code runs
- Tools are available as
mcp__<server>__<action>
If a Ralph build/plan process is interrupted or killed unexpectedly, the elapsed time indicator may continue running in the background. This has been fixed in the latest version (progress indicators now auto-terminate when the parent process dies), but you may still encounter orphaned processes from older runs.
Symptoms:
- Elapsed time messages (
⏱ Elapsed: Xm Ys) continue appearing after a Ralph process completes - Terminal shows: "Progress PID XXXXX reused by another process, skipping kill"
- Background
loop.shprocesses visible inps aux | grep ralph
Quick fix:
# Clean up all orphaned Ralph processes
.agents/ralph/cleanup-orphans.shManual cleanup:
# Find orphaned processes
ps aux | grep "ralph-cli/.agents/ralph/loop.sh" | grep -v grep
# Kill specific PIDs
kill -TERM <pid1> <pid2> ...
# Force kill if needed (use with caution)
kill -9 <pid>Prevention: The fix (as of v1.x) ensures background progress indicators automatically exit when their parent process dies, preventing orphans from forming in future runs.
# Search Notion for project docs
mcp__notion__search("Project requirements")
# Post build status to Slack
mcp__slack__send_message(channel="builds", text="Build completed")
# Create GitHub issue
mcp__github__create_issue(repo="org/repo", title="Bug found")
# Get Miro board
mcp__miro__get_boards()
See .agents/ralph/MCP_TOOLS.md for full documentation.
IMPORTANT: All UI-related testing uses browser automation with agent-browser.
Vercel's agent-browser - Fast Rust-based CLI for browser automation, optimized for AI agents.
Why agent-browser?
- Fast & reliable: Rust CLI with Node.js fallback
- AI-optimized: Snapshot + ref workflow (
@e1,@e2) for deterministic selection - No buggy MCP: Standalone CLI tool, no MCP server issues
- Persistent sessions: Isolated browser instances with cookies/storage
- JSON output: Machine-readable results for agents
Installation:
npm install -g agent-browser
agent-browser install # Downloads ChromiumUsage Examples:
# Start the UI server
cd ui && npm run dev
# Navigate and take snapshot
agent-browser open http://localhost:3000
agent-browser snapshot -i # Interactive elements only
# Click elements by reference
agent-browser click @e2
# Fill forms
agent-browser fill @e3 "test@example.com"
# Take screenshot
agent-browser screenshot --full
# Get element text
agent-browser get text @e1
# Run JavaScript
agent-browser eval "document.title"
# Find and click by role
agent-browser find role button click --name SubmitCommon Commands:
# Navigation
agent-browser open <url>
agent-browser back
agent-browser reload
# Interaction
agent-browser click <selector|@ref>
agent-browser type <selector|@ref> "text"
agent-browser fill <selector|@ref> "text"
agent-browser press Enter
# Verification
agent-browser snapshot [-i] [-c] # -i = interactive only, -c = compact
agent-browser screenshot [--full]
agent-browser get text <selector|@ref>
agent-browser is visible <selector|@ref>
# Debug
agent-browser console
agent-browser errors
agent-browser network requestsWhen testing UI features with agent-browser:
- ✅ Navigate to the page:
agent-browser open http://localhost:3000 - ✅ Take snapshot:
agent-browser snapshot -ito see interactive elements - ✅ Verify elements visible:
agent-browser is visible @e1 - ✅ Test interactions:
agent-browser click @e2,agent-browser fill @e3 "text" - ✅ Check console errors:
agent-browser consoleandagent-browser errors - ✅ Validate data loads:
agent-browser get text @e1oragent-browser eval "..." - ✅ Take screenshots:
agent-browser screenshot --full
Never test UI features with just curl or API calls alone - always verify the actual rendered page works correctly.
Full guide:
docs/guides/testing/TESTING.mdQuick reference:docs/guides/testing/TESTING_CHEATSHEET.md
For common testing scenarios, use the provided helper script:
# Quick snapshot of homepage
.agents/ralph/test-ui.sh snapshot
# Test PRD list page (automated)
.agents/ralph/test-ui.sh test-list
# Test logs page (automated)
.agents/ralph/test-ui.sh test-logs
# Interactive mode (opens headed browser)
.agents/ralph/test-ui.sh interactive
# Clean up browser session
.agents/ralph/test-ui.sh cleanupCustom UI URL:
UI_URL=http://localhost:8080 .agents/ralph/test-ui.sh snapshotThe Ralph UI server uses RALPH_ROOT environment variable to determine which .ralph directory to read from:
Production mode (default):
# Uses parent directory's .ralph/ (ralph-cli/.ralph)
cd ui && npm run dev
# or
npm startTest mode:
# Uses ui/.ralph/ for isolated testing
cd ui && npm run dev:test
# or
npm run start:testCustom RALPH_ROOT:
# Point to any .ralph directory
RALPH_ROOT=/path/to/.ralph npm run devDirectory structure:
ralph-cli/.ralph/- Production PRD directories (PRD-1 through PRD-N)ralph-cli/ui/.ralph/- Test/isolated PRD directories (used with:testscripts)
The server automatically uses ralph-cli/.ralph unless RALPH_ROOT is explicitly set. This prevents the UI from showing test PRDs in production while allowing isolated testing when needed.
See: ui/public/docs/agent-guide.html or http://localhost:3000/docs/agent-guide.html
Agent-optimized quick reference with task patterns, decision trees, and critical warnings. Details referenced in this file (CLAUDE.md) as needed.
Ralph CLI uses standardized error codes (RALPH-XXX) for consistent error handling and automated GitHub issue creation.
| Range | Category | Description |
|---|---|---|
| 001-099 | CONFIG | Configuration errors (missing files, invalid settings) |
| 100-199 | PRD | PRD/Plan errors (missing stories, malformed documents) |
| 200-299 | BUILD | Build failures (agent errors, rollback issues) |
| 300-399 | GIT | Git errors (conflicts, dirty state, diverged branches) |
| 400-499 | AGENT | Agent errors (fallback exhausted, timeouts) |
| 500-599 | STREAM | Stream errors (lock conflicts, worktree issues) |
| 900-999 | INTERNAL | Internal errors (unexpected failures) |
# Look up specific error
ralph error RALPH-401
# List all errors
ralph error --list
# Filter by category
ralph error --list --category=BUILD
# Show errors that auto-create GitHub issues
ralph error --list --auto-issueWhen build failures occur, agents should:
- Reference error codes when reporting failures
- Check remediation steps:
ralph error RALPH-XXX - Include error code in progress.md updates
- Follow remediation before retrying
Example in progress.md:
## Iteration 3 - Failed
- Error: [RALPH-401] Agent fallback chain exhausted
- Story: US-003
- See: `ralph error RALPH-401` for remediationRalph can auto-create GitHub issues for critical failures. Disabled by default - enable via config.
Enable auto-issue creation:
# In .agents/ralph/config.sh
export RALPH_AUTO_ISSUES=trueErrors that trigger auto-issue creation:
RALPH-201: Agent command failedRALPH-202: Rollback failed - manual intervention requiredRALPH-401: Agent fallback chain exhaustedRALPH-402: Story selection lock timeoutRALPH-506: PR creation failed
Issue format:
- Title:
[RALPH-XXX] Error message - Labels:
ralph-error, category-specific label - Body: Error details, context, remediation steps, logs
When working as an agent and encountering critical failures, create GitHub issues using MCP:
mcp__github__create_issue({
owner: "<repo-owner>",
repo: "<repo-name>",
title: "[RALPH-XXX] <short description>",
body: "<formatted error context>",
labels: ["ralph-error", "ralph-<category>"]
})Required context in issues:
- Error code and message
- PRD and story being worked on
- Agent chain tried (if applicable)
- Last 50 lines of run log
- Link to error documentation
Create issues for: RALPH-201, RALPH-202, RALPH-401, RALPH-402, RALPH-506
Do NOT create issues for:
- CONFIG errors (0XX range) - user configuration issues
- GIT errors (3XX range) - requires manual resolution
- Transient network errors - should retry
Add to .agents/ralph/config.sh:
# Enable/disable auto issue creation (default: false)
export RALPH_AUTO_ISSUES=false
# Override repo for issues (default: current project repo)
export RALPH_ISSUE_REPO=""
# Deduplication window in hours (default: 24)
export RALPH_ISSUE_DEDUP_HOURS=24