Skip to content
/

Ralph (snarktank)

ralph-snarktank · snarktank/ralph · ★ 20k · last commit 2026-02-02

Run an AI coding tool in a fresh-context loop, one user story at a time, until all stories in prd.json pass.

Best whenContext freshness per iteration is more valuable than context continuity — new process every time.
Skip ifStories larger than one context window, Tasks described in more than 2-3 sentences
vs seeds
claude-flow's SQLite/vector store. It is the reference implementation of the Geoffrey Huntley Ralph pattern.
Primitive shape 2 total
Skills 2
00

Summary

Ralph (snarktank) — Summary

Ralph by snarktank is the canonical reference implementation of the "Ralph pattern" — an autonomous AI agent loop that spawns a fresh AI coding tool (Amp or Claude Code) per iteration, each time picking the highest-priority incomplete story from prd.json, implementing it, running quality checks, and committing if checks pass. Memory across iterations persists only through git history, progress.txt (append-only learnings), and prd.json (task completion state). The framework ships two SKILL.md files (a PRD generator and a JSON converter), a bash loop script (ralph.sh), and a .claude-plugin manifest for Claude Code marketplace discovery. At 19,612 stars it is the most widely forked Ralph variant in the ecosystem. Compared to seeds, Ralph most closely resembles spec-driver's sequential execution model but is philosophically a pure execution loop rather than a specification framework: spec-driver manages the spec lifecycle, while Ralph assumes a prd.json already exists and focuses entirely on the iterate-commit-repeat loop with fresh-context isolation as its core mechanism.

01

Overview

Ralph (snarktank) — Overview

Origin

Ralph was created by snarktank (Ryan Carson, as referenced in the README: "Read my in-depth article on how I use Ralph"). The implementation credits "Geoffrey Huntley's Ralph pattern" (ghuntley.com/ralph/) and the character Ralph Wiggum from The Simpsons. The repository has 19,612 stars and 4 contributors. Last pushed 2026-02-02.

Philosophy

From the README:

"Ralph is an autonomous AI agent loop that runs AI coding tools (Amp or Claude Code) repeatedly until all PRD items are complete. Each iteration is a fresh instance with clean context. Memory persists via git history, progress.txt, and prd.json."

Critical Concepts (verbatim from README)

Each Iteration = Fresh Context:

"Each iteration spawns a new AI instance (Amp or Claude Code) with clean context. The only memory between iterations is: Git history (commits from previous iterations), progress.txt (learnings and context), prd.json (which stories are done)."

Small Tasks:

"Each PRD item should be small enough to complete in one context window. If a task is too big, the LLM runs out of context before finishing and produces poor code."

AGENTS.md Updates Are Critical:

"After each iteration, Ralph updates the relevant AGENTS.md files with learnings. This is key because AI coding tools automatically read these files, so future iterations (and future human developers) benefit from discovered patterns, gotchas, and conventions."

Feedback Loops:

"Ralph only works if there are feedback loops: Typecheck catches type errors, Tests verify behavior, CI must stay green."

Design Opinions

  • Context freshness is more valuable than context continuity for implementation tasks
  • Task granularity is the primary success factor: stories too large produce poor code
  • Git history is the right persistence mechanism for implementation work
  • Learnings should be written to AGENTS.md files (not just progress.txt) so future AI tool invocations benefit automatically
02

Architecture

Ralph (snarktank) — Architecture

Distribution & Install

  • Distribution type: bash-script-bundle + skill-pack (Claude Code marketplace)
  • Primary install: Copy ralph.sh to scripts/ralph/ in project
  • Skill install: cp -r skills/ ~/.config/amp/skills/ or ~/.claude/skills/
  • Marketplace install: /plugin marketplace add snarktank/ralph then /plugin install ralph-skills@ralph-marketplace
  • License: MIT
  • Required runtime: bash, jq, Amp CLI or Claude Code CLI

Directory Tree (repo)

ralph/
├── ralph.sh              # Main bash loop script
├── prompt.md             # Prompt template for Amp
├── CLAUDE.md             # Prompt template for Claude Code
├── prd.json.example      # Example PRD format
├── progress.txt          # (generated) Append-only learnings
├── skills/
│   ├── prd/
│   │   └── SKILL.md      # PRD generator skill
│   └── ralph/
│       └── SKILL.md      # PRD→JSON converter skill
├── .claude-plugin/       # Plugin manifest for Claude Code marketplace
├── flowchart/            # Interactive visualization (npm/React)
└── AGENTS.md             # Agent instructions

Loop Mechanics

ralph.sh [max_iterations]
  # Default: 10 iterations
  # --tool amp|claude  (AI tool selection)
  # Steps per iteration:
  # 1. Create/check out feature branch from PRD branchName
  # 2. Pick highest priority story where passes=false
  # 3. Spawn fresh AI instance with CLAUDE.md or prompt.md
  # 4. AI implements story
  # 5. Run quality checks (typecheck, lint, test)
  # 6. If checks pass: commit all changes
  # 7. Update prd.json: set passes=true for completed story
  # 8. Append learnings to progress.txt
  # 9. Repeat until all passes=true or max_iterations

PRD Format (prd.json)

{
  "project": "Project Name",
  "branchName": "ralph/feature-name",
  "description": "Feature description",
  "userStories": [
    {
      "id": "US-001",
      "title": "Story title",
      "description": "As a [user], I want [feature] so that [benefit]",
      "acceptanceCriteria": ["Criterion 1", "Typecheck passes"],
      "priority": 1,
      "passes": false,
      "notes": ""
    }
  ]
}

Target AI Tools

  • Amp (default, via ampcode.com)
  • Claude Code (via --tool claude)
  • Amp autoHandoff is recommended for large stories (context fill management)

Claude Code Marketplace

.claude-plugin/ contains the marketplace manifest. Available skills after installation:

  • /prd — Generate PRDs
  • /ralph — Convert PRDs to prd.json format
03

Components

Ralph (snarktank) — Components

Scripts

Script Purpose
ralph.sh Main bash loop — spawns AI instances iteratively

Skills (SKILL.md format)

Skill Trigger phrases Purpose
skills/prd/SKILL.md "create a prd", "write prd for", "plan this feature", "requirements for", "spec out" Interactively generates a structured PRD with clarifying questions; saves to tasks/prd-[feature].md
skills/ralph/SKILL.md "convert this prd", "turn into ralph format", "create prd.json from this", "ralph json" Converts a markdown PRD to prd.json format following story size and dependency rules

Prompt Templates

File Purpose
prompt.md Prompt template for Amp — agent instructions for each iteration
CLAUDE.md Prompt template for Claude Code — same content adapted for Claude Code

Runtime Files (generated per project)

File Purpose
prd.json User stories with passes/fails status
progress.txt Append-only learnings log
AGENTS.md (per-dir) Patterns and gotchas for future AI tool invocations

Claude Code Plugin

.claude-plugin/ — marketplace manifest for snarktank/ralph

Flowchart

flowchart/ — React/npm interactive visualization hosted at snarktank.github.io/ralph/

No Hooks, No Commands, No MCP

Ralph is a bash script that invokes AI tools as external processes. It does not use Claude Code hook events, slash commands, or MCP servers.

05

Prompts

Ralph (snarktank) — Prompts

Verbatim Excerpt 1 — prompt.md (Amp template, full)

# Ralph Agent Instructions

You are an autonomous coding agent working on a software project.

## Your Task

1. Read the PRD at `prd.json` (in the same directory as this file)
2. Read the progress log at `progress.txt` (check Codebase Patterns section first)
3. Check you're on the correct branch from PRD `branchName`. If not, check it out or create from main.
4. Pick the **highest priority** user story where `passes: false`
5. Implement that single user story
6. Run quality checks (e.g., typecheck, lint, test - use whatever your project requires)
7. Update AGENTS.md files if you discover reusable patterns (see below)
8. If checks pass, commit ALL changes with message: `feat: [Story ID] - [Story Title]`
9. Update the PRD to set `passes: true` for the completed story
10. Append your progress to `progress.txt`

...

## Stop Condition

After completing a user story, check if ALL stories have `passes: true`.

If ALL stories are complete and passing, reply with:
<promise>COMPLETE</promise>

If there are still stories with `passes: false`, end your response normally (another iteration will pick up the next story).

## Important

- Work on ONE story per iteration
- Commit frequently
- Keep CI green
- Read the Codebase Patterns section in progress.txt before starting

Technique: Numbered step list with explicit stop condition (<promise>COMPLETE</promise>). The agent is told to read learnings from progress.txt before starting, creating a lightweight memory-injection mechanism. AGENTS.md update instructions create a durable pattern library for future iterations.

Verbatim Excerpt 2 — skills/prd/SKILL.md (key section on story size)

## Story Size: The Number One Rule

**Each story must be completable in ONE Ralph iteration (one context window).**

Right-sized stories:
- Add a database column and migration
- Add a UI component to an existing page
- Update a server action with new logic
- Add a filter dropdown to a list

Too big (split these):
- "Build the entire dashboard" - Split into: schema, queries, UI components, filters
- "Add authentication" - Split into: schema, middleware, login UI, session handling
- "Refactor the API" - Split into one story per endpoint or pattern

**Rule of thumb:** If you cannot describe the change in 2-3 sentences, it is too big.

Technique: Prescriptive task-sizing instructions in the PRD-generation skill. This is not a runtime prompt — it is a meta-prompt that shapes the structure of the prd.json that Ralph will execute, preventing failure before the loop even starts.

09

Uniqueness

Ralph (snarktank) — Uniqueness & Positioning

Differs from Seeds

Ralph (snarktank) is closest to spec-driver in its sequential, story-by-story execution model — both drive an agent through a prioritized task list. However, Ralph's core mechanism is fresh-context isolation per iteration (a new AI process for every story), whereas spec-driver manages a persistent skill chain in a continuous session. Ralph has no spec lifecycle management — it assumes prd.json already exists and focuses entirely on the iterate-commit-repeat loop. Unlike any seed framework, Ralph explicitly supports two different AI tools (Amp and Claude Code) and is the only framework here designed primarily around Amp. The AGENTS.md update instruction — asking the agent to update per-directory pattern files after each commit so future AI tool invocations benefit — is a distinctive memory mechanism not present in any seed. Compared to claude-flow's elaborate SQLite/vector memory, Ralph's memory is deliberately minimal: three files, all human-readable, all in the git repo.

Positioning

Ralph (snarktank) is the reference implementation of the Geoffrey Huntley Ralph pattern and the most widely-starred variant. It is designed for simplicity and auditability: minimal dependencies (bash + jq), no installation, copy-paste deployment. The interactive flowchart visualization (snarktank.github.io/ralph/) is a distinctive community asset.

Observable Failure Modes

  • No retry on quality check failure: If a story fails checks, Ralph ends the iteration and starts a fresh one. If the same story repeatedly fails, it simply consumes iterations without progress.
  • max_iterations cap: Default 10 is very low for complex projects; users must increase it.
  • Single-tool per run: Cannot route different stories to different AI tools within one ralph.sh invocation.
  • No task decomposition: Stories that are too large silently produce poor code; the PRD skill's sizing guidance is advisory, not enforced.
  • Amp-first: Uses Amp by default; Claude Code is secondary. Users on Claude Max must remember --tool claude.

Explicit Antipatterns (from skill files)

  • Stories that span more than one context window
  • Tasks described in more than 2-3 sentences (too big to implement in one iteration)
  • Implementing features out of dependency order in prd.json
04

Workflow

Ralph (snarktank) — Workflow

Phases

Phase Description Artifact
PRD creation /prd skill generates PRD with clarifying Q&A tasks/prd-[feature].md
PRD conversion /ralph skill converts markdown PRD to JSON prd.json
Loop execution ralph.sh iterates until all stories pass Commits, progress.txt
Per-iteration: story selection Pick highest priority passes: false story
Per-iteration: implementation Fresh AI instance implements one story Code changes
Per-iteration: quality checks Run typecheck, lint, test Check results
Per-iteration: commit If checks pass, commit all changes Git commit
Per-iteration: PRD update Set passes: true for completed story Updated prd.json
Per-iteration: learnings Append to progress.txt, update AGENTS.md Updated context files

Phase-to-Artifact Map

Phase Artifact
PRD creation tasks/prd-[feature].md
PRD conversion prd.json
Per-iteration commit git commit with feat: [Story ID] - [Story Title]
Per-iteration learning progress.txt (appended), AGENTS.md (updated)

Approval Gates

None — Ralph is fully autonomous. The only human-defined gate is the PRD itself (story acceptance criteria) and the max_iterations limit. A failed quality check causes Ralph to retry in the next iteration rather than blocking for human input.

Stop Conditions

  • All stories have passes: true
  • max_iterations reached (default: 10)
  • AI tool returns <promise>COMPLETE</promise> (from CLAUDE.md / prompt.md)

Context Strategy

The prompt files explicitly instruct the agent:

  • Work on ONE story per iteration
  • Commit frequently
  • Keep CI green
  • Read the Codebase Patterns section in progress.txt before starting
06

Memory Context

Ralph (snarktank) — Memory & Context

State Storage

Three persistent files provide cross-iteration memory:

File Written By Read By Content
prd.json Agent (updates passes: true) Agent (reads at start) Story list + completion status
progress.txt Agent (appends per iteration) Agent (reads at start) Learnings, patterns, gotchas
AGENTS.md files (per directory) Agent (updates after commit) AI tools on next invocation Module-level reusable patterns

Memory Design

Ralph's memory model is git-native: the primary knowledge transfer between iterations is git history (committed code + messages). The three files above augment git history with:

  • Completion state (prd.json) — which stories are done
  • Accumulated learnings (progress.txt) — what the agent discovered about the codebase
  • Durable patterns (AGENTS.md) — conventions that apply broadly to a directory

Cross-Session Handoff

Yes — prd.json and progress.txt persist between ralph.sh invocations. If the loop is interrupted, re-running ralph.sh continues from the next incomplete story.

Context Compaction

Structural rather than mechanical: each iteration is a fresh AI instance with zero conversation history. The agent reads progress.txt and AGENTS.md at startup (lightweight text injection), then has the full context window available for implementation. The "Codebase Patterns" section at the top of progress.txt is explicitly structured for efficient consumption at iteration start.

Memory Persistence

Project-scoped. prd.json and progress.txt live in the project repository.

Amp AutoHandoff Integration

The README recommends configuring amp.experimental.autoHandoff: { "context": 90 } in ~/.config/amp/settings.json. At 90% context fill, Amp automatically hands off to a new instance — Ralph's fresh-context philosophy at the tool level.

07

Orchestration

Ralph (snarktank) — Orchestration

Multi-Agent Support

No — single agent per iteration. Ralph spawns one AI instance per loop, which works on one story to completion before the loop restarts with a new fresh instance.

Orchestration Pattern

Sequential — one story per iteration, in priority order from prd.json. No parallelism. No hierarchy.

Execution Mode

Continuous-ralph — the loop runs for up to max_iterations iterations (default: 10), each spawning a fresh AI process. The loop exits when all stories pass or the iteration limit is reached.

Isolation Mechanism

Process — each iteration spawns a new AI CLI process with clean context. No git worktrees; all work happens on the same branch. The isolation is context-level (fresh process) not filesystem-level.

Multi-Model Support

No. Ralph invokes whichever AI tool is configured (--tool amp or --tool claude). No role-based model routing.

Crash Recovery

Implicit — prd.json records which stories have passes: true. If ralph.sh is interrupted, re-running it automatically picks up from the next incomplete story.

Quality Gates (built-in)

Ralph explicitly requires feedback loops to function:

  • Quality checks must run per iteration (typecheck, lint, test)
  • Code is only committed if checks pass
  • If checks fail, the iteration ends without committing; the next iteration retries

Consensus / Coordination

None. Single sequential agent loop.

Prompt Chaining Pattern

Minimal — each iteration reads progress.txt (prior learnings) before starting. This is a lightweight chaining pattern: prior iteration output influences current iteration behavior via appended text.

08

Ui Cli Surface

Ralph (snarktank) — UI & CLI Surface

Dedicated CLI

ralph.sh is a bash script, not a compiled binary. It accepts:

  • [max_iterations] — integer argument (default: 10)
  • --tool amp|claude — AI tool selection

Not a dedicated CLI binary; it is a script copied into each project's scripts/ralph/ directory.

Local UI / Dashboard

None. Ralph has no dashboard or TUI.

Interactive Flowchart

flowchart/ contains a React application hosted at https://snarktank.github.io/ralph/ providing an interactive visualization of the Ralph loop steps. This is documentation infrastructure, not an operational interface.

IDE Integration

Claude Code marketplace integration: /plugin marketplace add snarktank/ralph installs the skills for use within Claude Code sessions.

Observability

  • progress.txt — append-only human-readable log of what each iteration did and learned
  • prd.json — stories with passes: true/false status; visible to humans and AI alike
  • Git log — full commit history per story

Target Tools

  • Amp (default) — ampcode.com, commercial AI coding tool
  • Claude Code — Anthropic's Claude Code CLI

Related frameworks

same archetype · same primary tool · same memory type

Claude-Flow / Ruflo ★ 55k

Eliminates single-agent context limits and sequential bottlenecks by orchestrating fault-tolerant swarms of specialized AI agents…

Hermes Agent (NousResearch) ★ 168k

Self-improving personal AI agent with closed learning loop, 7 terminal backends, and messaging gateway — not tied to any AI…

OpenCode ★ 165k

Terminal-first AI coding agent with multi-model routing, native desktop app, and a typed .opencode/ configuration system for…

OpenHands ★ 75k

Open-source AI software development platform (open-source Devin alternative) with Docker sandbox isolation, 77.6% SWE-bench…

DeerFlow ★ 70k

Long-horizon superagent that researches, codes, and creates by orchestrating parallel sub-agents with isolated contexts in Docker…

oh-my-openagent (omo) ★ 60k

Multi-provider AI agent orchestration for OpenCode: escape vendor lock-in by routing Sisyphus (Claude/Kimi/GLM) and Hephaestus…