ralph README

The project's README from github.com/snarktank/ralph. As one markdown file: README.md.

Ralph

Ralph

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.

Based on Geoffrey Huntley's Ralph pattern.

Read my in-depth article on how I use Ralph

Prerequisites

Setup

Option 1: Copy to your project

Copy the ralph files into your project:

# From your project root
mkdir -p scripts/ralph
cp /path/to/ralph/ralph.sh scripts/ralph/

# Copy the prompt template for your AI tool of choice:
cp /path/to/ralph/prompt.md scripts/ralph/prompt.md    # For Amp
# OR
cp /path/to/ralph/CLAUDE.md scripts/ralph/CLAUDE.md    # For Claude Code

chmod +x scripts/ralph/ralph.sh

Option 2: Install skills globally (Amp)

Copy the skills to your Amp or Claude config for use across all projects:

For AMP

cp -r skills/prd ~/.config/amp/skills/
cp -r skills/ralph ~/.config/amp/skills/

For Claude Code (manual)

cp -r skills/prd ~/.claude/skills/
cp -r skills/ralph ~/.claude/skills/

Option 3: Use as Claude Code Marketplace

Add the Ralph marketplace to Claude Code:

/plugin marketplace add snarktank/ralph

Then install the skills:

/plugin install ralph-skills@ralph-marketplace

Available skills after installation:

Skills are automatically invoked when you ask Claude to:

Add to ~/.config/amp/settings.json:

{
  "amp.experimental.autoHandoff": { "context": 90 }
}

This enables automatic handoff when context fills up, allowing Ralph to handle large stories that exceed a single context window.

Workflow

1. Create a PRD

Use the PRD skill to generate a detailed requirements document:

Load the prd skill and create a PRD for [your feature description]

Answer the clarifying questions. The skill saves output to tasks/prd-[feature-name].md.

2. Convert PRD to Ralph format

Use the Ralph skill to convert the markdown PRD to JSON:

Load the ralph skill and convert tasks/prd-[feature-name].md to prd.json

This creates prd.json with user stories structured for autonomous execution.

3. Run Ralph

# Using Amp (default)
./scripts/ralph/ralph.sh [max_iterations]

# Using Claude Code
./scripts/ralph/ralph.sh --tool claude [max_iterations]

Default is 10 iterations. Use --tool amp or --tool claude to select your AI coding tool.

Ralph will:

  1. Create a feature branch (from PRD branchName)
  2. Pick the highest priority story where passes: false
  3. Implement that single story
  4. Run quality checks (typecheck, tests)
  5. Commit if checks pass
  6. Update prd.json to mark story as passes: true
  7. Append learnings to progress.txt
  8. Repeat until all stories pass or max iterations reached

Key Files

File Purpose
ralph.sh The bash loop that spawns fresh AI instances (supports --tool amp or --tool claude)
prompt.md Prompt template for Amp
CLAUDE.md Prompt template for Claude Code
prd.json User stories with passes status (the task list)
prd.json.example Example PRD format for reference
progress.txt Append-only learnings for future iterations
skills/prd/ Skill for generating PRDs (works with Amp and Claude Code)
skills/ralph/ Skill for converting PRDs to JSON (works with Amp and Claude Code)
.claude-plugin/ Plugin manifest for Claude Code marketplace discovery
flowchart/ Interactive visualization of how Ralph works

Flowchart

Ralph Flowchart

View Interactive Flowchart - Click through to see each step with animations.

The flowchart/ directory contains the source code. To run locally:

cd flowchart
npm install
npm run dev

Critical Concepts

Each Iteration = Fresh Context

Each iteration spawns a new AI instance (Amp or Claude Code) with clean context. The only memory between iterations is:

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.

Right-sized stories:

Too big (split these):

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.

Examples of what to add to AGENTS.md:

Feedback Loops

Ralph only works if there are feedback loops:

Browser Verification for UI Stories

Frontend stories must include "Verify in browser using dev-browser skill" in acceptance criteria. Ralph will use the dev-browser skill to navigate to the page, interact with the UI, and confirm changes work.

Stop Condition

When all stories have passes: true, Ralph outputs <promise>COMPLETE</promise> and the loop exits.

Debugging

Check current state:

# See which stories are done
cat prd.json | jq '.userStories[] | {id, title, passes}'

# See learnings from previous iterations
cat progress.txt

# Check git history
git log --oneline -10

Customizing the Prompt

After copying prompt.md (for Amp) or CLAUDE.md (for Claude Code) to your project, customize it for your project:

Archiving

Ralph automatically archives previous runs when you start a new feature (different branchName). Archives are saved to archive/YYYY-MM-DD-feature-name/.

References

ralph (snarktank/ralph)

Searching Database…

22K ·GitHub
这是什么?Ralph 是一个自主运行的 AI 代理循环,会一遍又一遍地运行 AI 编程工具(Amp 或 Claude Code),直到 PRD 里的每一项都完成为止。每次迭代都会以干净的上下文启动一个全新的实例。
这是要安装的应用,还是放在我项目里的东西?既不是应用也不是服务——它就是几个文件:一个 bash 循环脚本(ralph.sh)、提示词模板和一些技能。你可以把它们复制到项目里、全局安装,或者通过 Claude Code 市场添加。
在一个功能上实际怎么用它?先用 /prd 技能生成一份 PRD,再用 /ralph 技能把它转换成 prd.json,然后运行 Ralph——默认迭代 10 次,可以用 --tool amp 或 --tool claude 选择后端。
运行之前我需要准备什么?一个已登录认证的 Amp CLI(默认)或 Claude Code、装好 jq(macOS 上用 brew install jq),以及项目的 git 仓库。就这些。
我可以直接丢给它一个大功能吗?不行——每个 PRD 条目都必须小到能在一个上下文窗口内完成;像“添加身份验证”或“搭建整个仪表盘”这样的史诗任务太大了,应该先拆分。
它怎么处理前端故事?前端故事的验收标准里必须包含“Verify in browser using dev-browser skill”。Ralph 随后会使用 dev-browser 技能打开页面、操作界面,确认改动真的生效。
Amp 的自动交接设置是干什么的?在 ~/.config/amp/settings.json 里添加一个设置后,当上下文占满时会自动交接,这样 Ralph 就能继续处理超出单个上下文窗口的大型故事。
开始新功能时,我之前的那次运行会怎样?当你用不同的 branchName 开始一个功能时,Ralph 会自动归档之前的运行,保存在 archive/YYYY-MM-DD-feature-name/ 目录下。
这种做法是从哪来的?它基于 Geoffrey Huntley 的 Ralph 模式,仓库作者还写了一篇详细介绍自己如何在工作流中使用 Ralph 的文章。
Creator
snarktank
Size
4.6 MB
Stars
22K
Updated
CommitFeb 02
Age
9mo
Commits · 90 Days