articleJanuary 6, 2026

Ralph: Step-by-Step Setup Guide

Ralph ships code while you sleep—a bash loop that pipes prompts into your AI agent, picks tasks from a JSON backlog, runs tests, commits passing code, and repeats until done.

Summary

Ryan Carson shares his practical experience with Ralph, the autonomous AI coding loop created by Geoffrey Huntley. The core insight: Ralph isn't sophisticated orchestration—it's a bash loop that feeds prompts to your agent, picks the next task, implements it, runs verification, commits if passing, and repeats.

How Ralph Works

A bash loop that:

  1. Pipes a prompt into your AI agent (Amp, Claude Code, etc.)
  2. Agent picks the next story from prd.json
  3. Agent implements it
  4. Agent runs typecheck + tests
  5. Agent commits if passing
  6. Agent marks story done and logs learnings
  7. Loop repeats until all stories pass

Memory persists only through git commits, progress.txt (learnings), and prd.json (task status). No server-side memory—the files are the memory.

File Structure

scripts/ralph/
├── ralph.sh      # The loop script
├── prompt.md     # Instructions for each iteration
├── prd.json      # Task list with priorities and status
└── progress.txt  # Accumulated learnings across sessions

Code Snippets

The Loop Script (ralph.sh)

#!/bin/bash
set -e

MAX_ITERATIONS=${1:-10}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

echo "Starting Ralph"

for i in $(seq 1 $MAX_ITERATIONS); do
  echo "═══ Iteration $i ═══"

  OUTPUT=$(cat "$SCRIPT_DIR/prompt.md" \
    | amp --dangerously-allow-all 2>&1 \
    | tee /dev/stderr) || true

  if echo "$OUTPUT" | grep -q "<promise>COMPLETE</promise>"; then
    echo "Done!"
    exit 0
  fi

  sleep 2
done

echo "Max iterations reached"
exit 1

For Claude Code, replace the amp line with:

claude --dangerously-skip-permissions

Task List (prd.json)

{
  "branchName": "ralph/feature",
  "userStories": [
    {
      "id": "US-001",
      "title": "Add login form",
      "acceptanceCriteria": [
        "Email/password fields",
        "Validates email format",
        "typecheck passes"
      ],
      "priority": 1,
      "passes": false,
      "notes": ""
    }
  ]
}

Progress Log (progress.txt)

Start with codebase patterns at the top:

# Ralph Progress Log
Started: 2026-01-06

## Codebase Patterns
- Migrations: IF NOT EXISTS
- Types: Export from actions.ts

## Key Files
- db/schema.ts
- app/auth/actions.ts
---

Ralph appends after each story. Patterns accumulate across iterations.

Critical Success Factors

FactorWhy It Matters
Small storiesMust fit in one context window. "Add login form" not "Build auth system"
Fast feedbacknpm run typecheck and npm test give Ralph signals about what's broken
Explicit criteria"Email/password fields, validates email format, typecheck passes" not "Users can log in"
Learnings compoundBy story 10, Ralph knows patterns from stories 1-9 via progress.txt
AGENTS.md updatesDocument gotchas for future sessions and human developers

When NOT to Use

  • Exploratory work without clear outcomes
  • Major refactors without explicit criteria
  • Security-critical code requiring human review
  • Anything needing judgment calls

Connections

Linked References (1)

Connections (22)