Skip to content
Agentmart
Submit a tool

ralph-loop

Use when task scope exceeds one context window and decomposes into independent pass/fail stories with clean iteration boundaries

Skill by thesyntaxninja

IndexedMIT★ 2
Write a review

Chalk Labs

Need help deploying ralph-loop?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/thesyntaxninja-ralph-loop

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when task scope exceeds one context window and decomposes into independent pass/fail stories with clean iteration boundaries

Use cases: productivity

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/ralph-loop

What's inside

Skill name
ralph-loop
Description
Use when task scope exceeds one context window and decomposes into independent pass/fail stories with clean iteration boundaries
License
MIT
Instructions
186 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Ralph Loop (Training Loop)

## Quick Reference

For tasks too large for one context window: decompose into stories, generate prd.json, activate the Stop hook loop, and iterate inside the current session until all stories pass.

## When to Use

ALL of these must be true:
- Scope exceeds one context window
- Work decomposes into independent, verifiable stories
- Each story has pass/fail acceptance criteria
- Clean iteration boundaries exist (one story per iteration)

## When NOT to Use

- Task fits in one session (use `executing-plans`)
- Work can't be decomposed into independent stories
- Stories don't have objective pass/fail criteria
- User prefers manual step-by-step execution

## How It Works

The ralph loop uses Claude Code's Stop hook to keep the session alive:

1. Claude writes `.claude/ralph-loop.local.md` (state file with loop prompt)
2. Claude works on the first story in prd.json
3. When the session tries to end, the Stop hook fires
4. The hook reads prd.json — if all stories pass, it allows exit
5. Otherwise, it re-injects the prompt and Claude continues with the next story
6. No external scripts, no subprocess — the same interactive session continues

This is fully automatic. The planning chain activates it when scope demands it.

## Core Process

### Step 1: Detection

During `writing-plans`, assess whether the task triggers ralph-loop conditions:

| Signal | Threshold |
|--------|-----------|
| Estimated stories | 4+ independent stories |
| Estimated changes | 500+ lines across 10+ files |
| Context window fit | Plan + implementation won't fit in one session |
| Story independence | Each story is verifiable in isolation |

If ALL signals fire, propose the training loop to the user.

### Step 2: Prepare Artifacts

Chain to `story-decomposition` then `prd-generator`. This generates in `.claude/plugin/ralph/`:

- **`prd.json`** — stories with `passes: false` initially
- **`progress.txt`** — human-readable progress log
- **`notes/`** — per-story implementation notes (written during iterations)

### Step 3: Propose to User

Present the decomposition and ask for approval before activating:

```
This task would benefit from a ralph loop.

**Stories**: N stories, max 20 iterations
**Mechanism**: Stop hook — runs inside this session, fully interactive
**Completion**: Automatic when all prd.json stories pass

Stories:
1. [Title] — [one-line goal]
2. [Title] — [one-line goal]
...

Ready to start? I'll activate the loop now.
```

**Do not activate without user approval.**

### Step 4: Activate the Loop

After approval, write the state file `.claude/ralph-loop.local.md`:

```markdown
---
active: true
iteration: 1
session_id: <CLAUDE_CODE_SESSION_ID>
max_iterations: 20
prd_path: .claude/plugin/ralph/prd.json
started_at: "<current ISO 8601 timestamp>"
---

Read .claude/plugin/ralph/prd.json. Find the first story where passes is false.
Check its dependencies are met (all dependency story IDs must have passes: true).
Implement the story following its acceptance criteria. Run the verification
command. If it passes, update prd.json (set passes: true, increment
completedStories) and progress.txt (mark [x]). Write implementation notes to
.claude/plugin/ralph/notes/story-<id>.md. One story per iteration.

If you are stuck on a story after 3 attempts, or blocked on something requiring
human input, delete .claude/ralph-loop.local.md and explain what happened.
```

Write this file using the Write tool. The `session_id` should be read from the `CLAUDE_CODE_SESSION_ID` environment variable via Bash. The `max_iterations` defaults to 20 but can be adjusted based on story count or user preference.

Then immediately begin working on the first story.

### Step 5: Per-Iteration Behavior

Each iteration (after the Stop hook re-injects the prompt):

1. **Read prd.json** — find the first story where `passes` is `false`
2. **Check dependencies** — if a dependency story has `passes: false`, skip to the next eligible story
3. **Implement** — follow the story's acceptance criteria
4. **Verify** — run the story's verification command
5. **Update on success**:
   - Set `passes: true` in prd.json for this story
   - Increment `completedStories` in prd.json
   - Mark `[x]` in progress.txt

From thesyntaxninja/syntaxninja-dojo, MIT.

More from thesyntaxninja/syntaxninja-dojo

Signals

Stars
2
Forks
0
Open issues
0
Last commit (this folder)
Mar 4, 2026 (8 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from thesyntaxninja

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get ralph-loop running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying ralph-loop?

CallGet help
Cite this page

ralph-loop skill. Agent Mart. https://agentmart.dev/skills/thesyntaxninja-ralph-loop (last updated 2026-10-24)