An autonomous development loop that drives itself from a task checklist — with context-aware doc routing, security audits, and self-directed planning.
The Ralph Loop is an agentic coding pattern where an AI agent:
- Picks the next pending task from
TASKS.md - Reads only the relevant documentation sections for that task (not all docs)
- Implements the task
- Verifies via build/test commands
- Marks the task done and loops
- When tasks run out → runs a security audit (reviews the plan for risks)
- Then enters planning mode (reads PRD + git history, generates new tasks)
- Continues until planning finds nothing more to do
The key innovation is doc routing — a DOC-INDEX.md maps each task ID to specific doc file+section pairs, reducing per-iteration context by ~95%.
| File | Purpose |
|---|---|
ralph.py |
Main loop script — runs autonomously |
setup.py |
Scaffolding script — bootstraps a new project |
templates/ |
Ready-to-use file templates |
SKILL.md |
Claude Code slash command (/ralphloop-implementation) |
In any project, run:
/ralphloop-implementation
This activates a Claude Code skill that audits your project and creates all the Ralph Loop files automatically.
# Download both scripts to your project root
curl -O https://raw.githubusercontent.com/vansearch/ralphloop-implementation/main/ralph.py
curl -O https://raw.githubusercontent.com/vansearch/ralphloop-implementation/main/setup.py
# Run the scaffolder (interactive)
python setup.py
# Or pass args directly
python setup.py --name "My Project" --lang swift
# Start the loop
python ralph.py --dry-run # preview first task
python ralph.py --status # show progress
python ralph.py # run autonomously- Copy
ralph.pyto your project root - Create
TASKS.md(seetemplates/TASKS.md) - Create
docs/DOC-INDEX.md(seetemplates/docs/DOC-INDEX.md) - Create
.ralph/directory withguardrails.mdandprogress.md - Add
.gitignoreentries (seetemplates/.gitignore)
python ralph.py # run the loop (parallel + planning)
python ralph.py --dry-run # preview next task/batch and prompt
python ralph.py --status # show progress summary
python ralph.py --task E2-T3 # run a specific task only (sequential)
python ralph.py --reset # clear .ralph/ state and start fresh
python ralph.py --no-plan # disable planning mode (finite, tasks only)
python ralph.py --no-parallel # force sequential mode (disable parallel)
python ralph.py --max-parallel 8 # allow up to 8 concurrent workers
Add [parallel] to an epic header to run its tasks concurrently:
## Epic 2 — Scanners [parallel]
- [ ] **E2-T1** Implement AppCacheScanner
- [ ] **E2-T2** Implement SystemCacheScanner
- [ ] **E2-T3** Implement LogsScannerThe orchestrator:
- Creates a git worktree per task (
.ralph/worktrees/E2-T1/, etc.) - Runs all workers simultaneously with prefixed output (
[E2-T1] ...,[E2-T2] ...) - Merges successful branches sequentially into the main tree
- Runs
VERIFY_STEPSonce on the merged state - Marks all passing tasks done; reverts and re-queues failed ones
Tasks in different epics are always sequential. Only tasks within the same [parallel] epic run concurrently. Use [parallel] for independent tasks that don't modify the same files.
After running setup.py or the skill:
your-project/
├── ralph.py ← the loop
├── setup.py ← scaffolder (optional, remove after setup)
├── TASKS.md ← task checklist
├── docs/
│ ├── DOC-INDEX.md ← routing table (task → doc sections)
│ ├── PRD.md ← product requirements
│ └── ARCHITECTURE.md ← architecture notes
└── .ralph/
├── guardrails.md ← learned failure patterns (commit this)
├── progress.md ← run history (.gitignore)
├── activity.log ← debug log (.gitignore)
└── security-report.md ← audit output (.gitignore)
# Project Name — Task List (Ralph Loop)
## Epic 1 — Foundation
- [ ] **E1-T1** Create the package structure
- [ ] **E1-T2** Add core dependencies
- [x] **E1-T3** Write initial unit test scaffold ← done
## Epic 2 — Scanners [parallel]
<!-- Tasks run concurrently — each gets its own git worktree -->
- [ ] **E2-T1** Implement AppCacheScanner
- [ ] **E2-T2** Implement SystemCacheScanner
- [ ] **E2-T3** Implement LogsScanner## Routing Table
E1-T1 | ARCHITECTURE.md:Package Structure | PRD.md:Goals E1-T2 | ARCHITECTURE.md:Dependencies
E2-T1 | ARCHITECTURE.md:Core Components | DATA-MODELS.md:UserEntity
In ralph.py, set VERIFY_STEPS for your tech stack:
# Swift
VERIFY_STEPS = [
("swift build", ["swift", "build", "-c", "debug"]),
("swift test", ["swift", "test"]),
]
# TypeScript / Bun
VERIFY_STEPS = [
("bun build", ["bun", "run", "build"]),
("bun test", ["bun", "test"]),
]
# Python / uv
VERIFY_STEPS = [
("pytest", ["uv", "run", "pytest"]),
]
# Rust
VERIFY_STEPS = [
("cargo build", ["cargo", "build"]),
("cargo test", ["cargo", "test"]),
]After the first plan's tasks complete, the loop automatically reviews the completed task descriptions for security risks. It:
- Loads content from
SECURITY_SKILL_PATHS(existing security skills/scripts) - Sends the completed task plan to Claude acting as a security auditor
- Saves the report to
.ralph/security-report.md - Generates
SEC-Txfix tasks for CRITICAL/HIGH risks - Executes fixes before entering planning mode
Disable with --no-security. Run standalone with --security-only.
The loop includes 6 security hardening measures to prevent prompt injection and other attacks:
sanitize_for_prompt()— strips shell metacharacters from task descriptions- Path traversal guard — blocks
../escape fromdocs/in doc routing - Guardrails sanitization — strips markdown headings from
.ralph/guardrails.mdreads - Data block wrapping — wraps
git logand file tree output in fenced blocks - Output cap — limits planning output to 500KB to prevent disk exhaustion
sanitize_guardrail()— sanitizes failure summaries before writing to guardrails
| Tag | Description |
|---|---|
| v1.2.0 | Parallel orchestrator: git worktrees, ThreadPoolExecutor, [parallel] tag |
| v1.1.0 | Full restore: ralph.py, setup.py, templates, README |
| v1.0.0 | Initial stable release (SKILL.md only) |
# Clone the skill into your Claude skills directory
git clone https://github.com/vansearch/ralphloop-implementation \
~/.claude/skills/ralphloop-implementation
# Then in any project:
/ralphloop-implementation