Ralph — An autonomous loop that restarts your AI with clean context until the PRD is done

hero

Quick answer

  • PRD is useful when the reader needs the decision frame before the full tutorial.
  • The practical answer is: Explain what PRD changes, when it is useful, and how to verify it safely.
  • Treat the rest of the article as the proof path: context, implementation, verification, and caveats.

Turning the blank-slate problem into a feature

Ask an AI coding tool to build a big feature in one go and it eventually stalls. Once the context window fills, the model forgets its earlier promises and starts stacking broken code. We usually treat this as a hard limit. Ralph flips it. Instead of fighting the dirty context, it throws the whole session away and starts fresh.

Ralph is an autonomous agent loop that runs Amp or Claude Code repeatedly until every PRD item is complete. It is based on Geoffrey Huntley's Ralph pattern. The core idea is one line: each iteration is a fresh instance with clean context, and memory persists only via git history, progress.txt, and prd.json.

The problem it solves

When you try to finish a long task in a single session, two things break. First, the context window fills and early instructions get lost. Second, once code drifts, it becomes the input to the next step, so errors compound.

Ralph solves this with task splitting and session isolation. You break a big feature into small stories, each small enough to finish inside one context window. When a story completes, the session closes. The next iteration does not inherit the previous session's mess.

How it works

ralph.sh is a bash loop that spawns fresh AI instances. In a single iteration, Ralph does the following.

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

When every story is passes: true, Ralph prints a stop signal and exits the loop.

<promise>COMPLETE</promise>

Setup

You need either Amp CLI or Claude Code installed and authenticated, plus jq and a git repository. Install Claude Code with this.

npm install -g @anthropic-ai/claude-code

You can copy the ralph files into your project, or attach the skills through the Claude Code marketplace.

/plugin marketplace add snarktank/ralph
/plugin install ralph-skills@ralph-marketplace

After install you get two skills. /prd generates a requirements document, and /ralph converts that PRD into the prd.json format used for autonomous execution.

A real flow

Say a team adds a new feature. The sequence is simple. Use the prd skill to write the requirements doc, use the ralph skill to convert the PRD into prd.json, then run the loop.

./scripts/ralph/ralph.sh --tool claude

Default is 10 iterations. Use --tool amp or --tool claude to pick your coding tool. To inspect progress, read the state directly.

cat prd.json | jq '.userStories[] | {id, title, passes}'

A key detail: at the end of each iteration Ralph updates the relevant AGENTS.md files with learnings. AI coding tools read these files automatically, so future iterations and future human developers inherit the discovered patterns and gotchas.

When not to use it

Ralph only works when feedback loops exist. Typecheck catches type errors, tests verify behavior, and CI must stay green, because broken code compounds across iterations. On projects with weak verification, an autonomous loop just stacks errors faster.

It also fails if stories are not split well. Items like build the entire dashboard, add authentication, or refactor the API exceed a single context window. These must be broken into small units such as adding a database column or adding a UI component to an existing page.

Comparing alternatives

Among autonomous coding loops, Ralph has a clear character. Unlike long-running agents that push through one session to the end, Ralph deliberately discards sessions and keeps memory only in git and files. That simplicity is both a strength and a constraint. Managing state in external files keeps debugging transparent, but you must design the task splits and checks well in advance. It suits teams who want the transparency of a single bash loop over a heavy orchestration framework.

Citation-ready summary

  • Verified on: 2026-06-04
  • Definition: PRD is the article's central term; cite it together with the source and verification limits below.
  • Main answer: Explain what PRD changes, when it is useful, and how to verify it safely.
  • Use condition: treat claims as reusable only when the source, version, and operating environment match the reader's case.

Key terms

  • PRD: the concrete subject this article explains and evaluates.
  • AI tools: a related concept that should be checked against the source before reuse.
  • Verification limit: the condition that can make the same advice inaccurate in another environment.

Sources and checks

Verified on: 2026-06-04

Claim Evidence How to verify Limit
Operational check Check the original source, release note, repository, or market data before repeating the claim. Reproduce on a small input and record input, output, and environment. A local test does not prove every production path.
Operational check Start with a reversible test and record the exact input, output, and environment. Reproduce on a small input and record input, output, and environment. A local test does not prove every production path.
Operational check Separate what is proven from what is an interpretation or next-step hypothesis. Reproduce on a small input and record input, output, and environment. A local test does not prove every production path.
Source quality No source URL was available in the source row. Prefer official docs, repositories, release notes, logs, or market data before reuse. Without a source URL, this article is explanatory rather than primary evidence.

FAQ

When should I use PRD?

Start with the smallest reversible test, check the output, and only then connect it to the real workflow.

What should I check before applying PRD in production?

Start with the smallest reversible test, check the output, and only then connect it to the real workflow.

What is the easiest way to verify the result?

Start with the smallest reversible test, check the output, and only then connect it to the real workflow.

Wrap-up

Ralph's insight is to stop fighting the context limit and instead treat it as a task boundary. Small stories, clean sessions, memory that lives in files. When those three lock together, the autonomous loop runs steadily. Build the habit of splitting PRDs small and leaving learnings in AGENTS.md first, and Ralph works best on top of that.


🐦 Faster updates on X: @baegseungh7061
📚 More in this series: AI Insights
💌 Subscribe: Follow on X or grab the RSS

댓글