Edit the prompts in your project's ralph/ directory:
# Edit planning prompt
vim ralph/PROMPT_plan.md
# Edit building prompt
vim ralph/PROMPT_build.mdChanges only affect your project and are tracked in git.
Available variables in prompts:
| Variable | Description | Set By |
|---|---|---|
${RALPH_GOAL} |
Custom goal for planning | ralph.config |
${WORK_SCOPE} |
Scoped planning target | CLI argument |
Create new prompt files for specialized workflows:
# ralph/PROMPT_refactor.md
cat > ralph/PROMPT_refactor.md << 'EOF'
# Ralph Refactoring Mode
Focus on code quality improvements without changing behavior.
1. Study the codebase for code smells
2. Identify refactoring opportunities
3. Make changes with comprehensive tests
4. Validate behavior is unchanged
RULES:
- No new features
- No API changes
- Tests must pass before and after
EOFUse with a custom mode (requires extending loop.sh).
Skip ralph plan entirely when you already have a plan:
# Initialize without running plan
ralph init
# Replace with your existing plan (JSON format)
cat > ralph/prd.json << 'EOF'
{
"meta": {
"goal": "Build user authentication system",
"created_at": "2025-01-23T15:00:00Z",
"updated_at": "2025-01-23T15:00:00Z",
"iteration": 0
},
"tasks": [
{"id": "task-001", "description": "Set up database schema for users table", "status": "pending", "priority": 1, "depends_on": [], "spec": "auth.md"},
{"id": "task-002", "description": "Implement user registration endpoint", "status": "pending", "priority": 2, "depends_on": ["task-001"], "spec": "auth.md"},
{"id": "task-003", "description": "Add JWT authentication middleware", "status": "pending", "priority": 3, "depends_on": ["task-002"], "spec": "auth.md"},
{"id": "task-004", "description": "Create login/logout endpoints", "status": "pending", "priority": 4, "depends_on": ["task-003"], "spec": "auth.md"},
{"id": "task-005", "description": "Add password reset flow", "status": "pending", "priority": 5, "depends_on": ["task-004"], "spec": "auth.md"}
],
"issues": []
}
EOF
# Go straight to building
ralph 20If you have a PRD or design doc, you can either:
- Manual conversion: Create
prd.jsonwith tasks from your PRD - AI-assisted conversion: Use Claude/GPT to convert the PRD to Ralph JSON format
- Hybrid approach: Put the PRD in
ralph/specs/and runralph planonce to generate the initial tasks, then editprd.json
Example conversion prompt:
Convert this PRD into a Ralph prd.json format.
Use this JSON schema:
{
"meta": {"goal": "string", "iteration": 0},
"tasks": [{"id": "task-NNN", "description": "string", "status": "pending", "priority": N, "depends_on": [], "spec": "filename.md"}],
"issues": []
}
Order tasks by priority (1 = highest). Set depends_on for task dependencies.
You can edit prd.json while Ralph is running:
- Wait for current iteration to complete (watch for "END ITERATION" message)
- Edit
ralph/prd.json(add tasks, change priorities, etc.) - Ralph reads fresh state at start of next iteration
This is useful for:
- Reprioritizing mid-run
- Adding urgent tasks
- Removing tasks that are no longer needed
- Fixing incorrect task descriptions
Use ralph status to view current state in a readable format.
Pull plans from external sources and convert to JSON:
# From GitHub Issues (creates JSON tasks)
gh issue list --json number,title --jq '[.[] | {id: "task-\(.number)", description: .title, status: "pending", priority: .number, depends_on: [], spec: null}]' | \
jq '{meta: {goal: "From GitHub Issues", iteration: 0}, tasks: ., issues: []}' > ralph/prd.json
# From Linear (example with custom script)
./scripts/sync-from-linear.sh > ralph/prd.json
# Merge with existing prd.json
jq -s '.[0].tasks += .[1].tasks | .[0]' ralph/prd.json new-tasks.json > ralph/prd.json.tmp && mv ralph/prd.json.tmp ralph/prd.jsonRun multiple Ralphs on different branches:
# Terminal 1: Auth feature
git checkout -b feature/auth
ralph plan-work "user authentication"
ralph --docker
# Terminal 2: API feature
git checkout -b feature/api
ralph plan-work "REST API endpoints"
ralph --dockerSeparate planning from execution:
# Human-guided planning
ralph plan # Review the output
vim ralph/prd.json # Adjust priorities
# Autonomous building
ralph --docker 50 # Let it runRun different validation levels:
# Quick iterations (unit tests only)
RALPH_QUICK_VALIDATE=true ralph 10
# Full validation at checkpoints
ralph 5 # Full tests every 5 iterations# .github/workflows/ralph.yml
name: Ralph Build Loop
on:
workflow_dispatch:
inputs:
iterations:
description: 'Max iterations'
default: '20'
mode:
description: 'Mode (plan/build)'
default: 'build'
jobs:
ralph:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Ralph
run: |
git clone https://github.com/yourorg/ralph-wiggum.git ~/.ralph-wiggum
echo "alias ralph='~/.ralph-wiggum/ralph.sh'" >> ~/.bashrc
- name: Run Ralph
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
source ~/.bashrc
if [ "${{ inputs.mode }}" = "plan" ]; then
ralph plan ${{ inputs.iterations }}
else
ralph ${{ inputs.iterations }}
fi
- name: Create PR
uses: peter-evans/create-pull-request@v5
with:
title: "Ralph: Automated changes"
body: "Changes made by Ralph autonomous loop"Validate Ralph output before committing:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-implementation-plan
name: Validate Implementation Plan
entry: bash -c 'test -f ralph/prd.json'
language: system
pass_filenames: falseAdd timestamps and metrics to loop output:
# In lib/loop.sh, add to the loop:
echo "[$(date -Iseconds)] Iteration $iteration started" >> ralph.log
time run_agent "$prompt_file" "$mode"
echo "[$(date -Iseconds)] Iteration $iteration completed" >> ralph.logTrack API usage per session:
# Before running
export RALPH_SESSION_ID=$(date +%s)
# In CLI adapter, log requests
echo "$RALPH_SESSION_ID,$(date -Iseconds),request" >> ~/.ralph-costs.csvNotify on completion:
# Add to loop.sh after completion
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"Ralph completed '$iteration' iterations"}' \
$SLACK_WEBHOOK_URLIncrease subagent count for large codebases:
# In PROMPT_plan.md
0a. Study `specs/*` with up to 1000 parallel subagents...For large projects, scope the context:
# In PROMPT_build.md
Focus only on files in `src/features/auth/` for this iteration.Mount a persistent cache volume:
# docker-compose.yml
volumes:
- ralph-cache:/home/ralph/.cache
volumes:
ralph-cache:If Ralph keeps implementing the same thing:
- Check prd.json for duplicate tasks
- Verify the agent is marking tasks complete
- Check validation commands actually catch the issue
If iterations take too long:
- Reduce spec scope
- Break large tasks into smaller ones
- Increase resource limits in Docker
If validation keeps failing:
- Run validation commands manually to understand failures
- Check AGENTS.md has correct commands
- Verify the agent understands the error messages
If the plan doesn't match reality:
- Run
ralph planto regenerate - Manually review and prune completed items
- Check for conflicting specs
Add support for new CLIs:
# lib/cli-adapters/myagent.sh
#!/bin/bash
run_agent() {
local prompt_file="$1"
local mode="$2"
cat "$prompt_file" | myagent-cli \
--autonomous \
${RALPH_MYAGENT_FLAGS:-}
}Add custom validation:
# In lib/loop.sh, after run_agent:
if [[ -f "ralph/validate.sh" ]]; then
source ralph/validate.sh
custom_validate || exit 1
fiAdd lifecycle hooks:
# ralph/hooks/pre-iteration.sh
# ralph/hooks/post-commit.sh
# ralph/hooks/on-error.sh