Set up autonomous Claude Code loops (Ralph Wiggum pattern). Use when the user wants to run Claude continuously on a task until complete...
Set up autonomous Claude Code loops based on the Ralph Wiggum pattern - running Claude repeatedly with no memory between sessions until all tasks are complete.
┌─────────────────────────────────────────────────────────────┐
│ Claudius Loop │
├─────────────────────────────────────────────────────────────┤
│ │
│ Iteration N: │
│ ├─ Claude starts fresh (no memory) │
│ ├─ Reads PRD.md (requirements + tasks) │
│ ├─ Reads progress.txt (what's done) │
│ ├─ Picks next incomplete task │
│ ├─ Implements task │
│ ├─ Runs verification (tests, lint, etc) │
│ ├─ Updates progress.txt │
│ ├─ Commits + Pushes │
│ ├─ Outputs: <iteration_complete> │
│ └─ Runner kills process │
│ ↓ │
│ Iteration N+1: (fresh session) │
│ └─ Repeat until <workflow_complete> │
│ │
└─────────────────────────────────────────────────────────────┘
Key insight: Each iteration runs in a fresh Claude session. Progress is tracked externally in files. This eliminates context rot - Claude operates at peak intelligence every time.
When this skill is invoked, your goal is to fully automate setting up a Claudius loop in the user's project. This involves:
CRITICAL: Never be conservative with questions. Missing details leads to bad PRDs.
Before interviewing the user, scan the project to understand context:
Look for existing agent guidance:
CLAUDE.md, GEMINI.md, AGENTS.md, AGENT.md, README.md
.claude/settings.json
docs/*.md, .docs/*.md
Extract: code standards, testing requirements, commit conventions, tech stack.
Scan for existing sub-agents (these work in CLI via --agents flag):
.claude/agents/*.md
~/.claude/agents/*.md
For each agent found, extract from its YAML frontmatter:
name - agent identifierdescription - what it doestools - allowed tools listmodel - which model to useScan for skills the agent could use:
.claude/skills/*/SKILL.md
NOTE: Skills may or may not be fully available in headless mode. As a backup, create a "skill shim" in the PRD that lists skills by name + path. Skills use progressive disclosure - don't bulk read, start with SKILL.md.
List each skill found with:
Look for:
package.json (scripts section)
Makefile, Taskfile.yml
pyproject.toml, setup.py
Identify: test command, lint command, typecheck command, build command.
Check if there's already a PRD:
PRD.md, prd.md, PLAN.md, TODO.md
ALWAYS use AskUserQuestion tool. Do NOT ask questions in plain text.
Ask questions in logical groups. Never skip a category.
These are critical. Ask explicitly:
Present discovered skills:
Sub-agents can be passed to Claude via the --agents CLI flag.
Present discovered agents:
Explain that selected agents will be converted to JSON and passed via --agents flag.
After gathering all information, generate these files in the project directory:
Use the template from templates/PRD_TEMPLATE.md. Include:
[ ] checkboxes)Create an empty progress file:
# Progress Log
Convert selected sub-agents to JSON for the --agents CLI flag:
From agent .md file:
---
name: code-reviewer
description: Reviews code for quality
tools: Read, Glob, Grep
model: sonnet
---
You are a code reviewer. Analyze code and provide feedback.
To JSON:
{
"code-reviewer": {
"description": "Reviews code for quality",
"prompt": "You are a code reviewer. Analyze code and provide feedback.",
"tools": ["Read", "Glob", "Grep"],
"model": "sonnet"
}
}
CRITICAL: Do NOT generate this file from scratch. Output capture and signal handling are complex and fragile on different OSs (especially Windows).
scripts/claudius_runner.py in this skill folder to the user's project root.cp (Linux/Mac) or copy (Windows) or read_file + write_to_file.SYSTEM_PROMPT constant in the copied file to include:Before the user runs the loop:
Confirm the PRD - Present a summary of what will be done
Verify git state - Is the repo clean? Is the branch created?
Explain the command:
python claudius_runner.py <max_iterations>
Set expectations - Loops can take hours for complex work
Since user skills are NOT available in headless mode, include this in the PRD:
## Available Skills (Read When Needed)
> Skills use **progressive disclosure**. Don't bulk-read all files.
> Start with SKILL.md and branch out as needed.
| Skill Name | When to Use | Path |
|------------|-------------|------|
| my-skill | When doing X | `.claude/skills/my-skill/SKILL.md` |
The loop agent can then manually read skill files with the Read tool when relevant.
The runner script monitors Claude's output for these signals:
| Signal | Meaning | Runner Action |
|---|---|---|
<iteration_complete> |
Single task done, more tasks remain | Kill process, start next iteration |
<workflow_complete> |
All tasks done, PRD complete | Kill process, exit loop successfully |
The agent MUST output exactly one of these after each task.
| File | Purpose |
|---|---|
scripts/claudius_runner.py |
Main runner script |
templates/PRD_TEMPLATE.md |
Template for generating PRD |
templates/SYSTEM_PROMPT.md |
Template for system prompt |
references/cli-reference.md |
Claude CLI flags reference |
references/getting-started-with-ralph.md |
Original Ralph documentation |
references/tips-for-ai-coding-with-ralph-wiggum.md |
Advanced Ralph patterns |
claude -p "prompt" --dangerously-skip-permissions --no-session-persistence
| Flag | Purpose |
|---|---|
-p |
Print mode - non-interactive output |
--dangerously-skip-permissions |
Auto-approve ALL actions |
--no-session-persistence |
Don't save session to disk |
--max-turns N |
Optional: limit agentic turns per iteration |
| Type | Use Case | Key Prompt Element |
|---|---|---|
| Feature PRD | Build features from requirements | Task checklist in PRD |
| Test Coverage | Increase coverage to target | Coverage report + threshold |
| Linting | Clean up code quality | npm run lint as feedback |
| Refactoring | Extract, restructure code | Specific refactor goals |
| Entropy | Find and fix code smells | "Scan for X, fix one per iteration" |