.claude/skills/ralph-loop/SKILL.md
Autonomous iteration loop with dual-mode support. Standalone mode uses Stop hooks (RALPH_ACTIVE=1). Multi-agent mode uses router-managed iteration. Never traps the host/router session.
npx skillsauth add oimiragieo/agent-studio ralph-loopInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Autonomous iteration loop for Claude Code with dual-mode support. Named after the Ralph Wiggum technique popularized in the Claude Code community (Dec 2025 - Feb 2026).
Enable Claude Code to work autonomously on well-defined tasks until genuine completion, without manual re-prompting. The skill provides:
RALPH_ACTIVE=1 is set, preventing host/router trappingFor single-session use. The Stop hook keeps the session alive until completion. Requires RALPH_ACTIVE=1 env var (set by the launcher scripts).
User runs ralph-audit.sh/bat (sets RALPH_ACTIVE=1)
|
v
Claude works on task (reads PROMPT.md)
|
v
Claude attempts to exit
|
v
Stop hook intercepts (ralph-stop-hook.cjs)
|
+-- RALPH_ACTIVE != '1'? --> YES --> exit(0) immediately (no-op)
|
+-- Completion signal found? --> YES --> Clear state, exit(0)
|
+-- Max iterations reached? --> YES --> Clear state, exit(0)
|
+-- NO --> Increment iteration, save state, re-inject prompt, block exit
This is the primary mode within agent-studio. The router manages iteration by spawning and re-spawning QA agents via Task(). No Stop hook is involved -- the router itself controls the loop lifecycle. The state file at .claude/context/runtime/ralph-state.json within agent-studio tracks iteration progress.
Router receives /ralph-loop command
|
v
Router spawns QA agent with audit prompt via Task()
|
v
QA agent completes, reports findings via TaskUpdate()
|
v
Router checks audit state file (.claude/context/runtime/ralph-state.json)
|
+-- RALPH_AUDIT_COMPLETE_NO_FINDINGS? --> Done
|
+-- RALPH_ITERATION_COMPLETE? --> Spawn another QA agent
|
+-- Max iterations? --> Report and stop
Why two modes: Stop hooks fire on the host session, not on subagents. In multi-agent setups (like agent-studio), the Stop hook would trap the router. The RALPH_ACTIVE guard ensures the hook is a no-op unless explicitly activated by a standalone launcher. In agent-studio, Mode 2 is used exclusively -- the router orchestrates iteration without any Stop hook registration.
| File | Relative Path | Purpose |
| ----------------------- | -------------------------------------- | ----------------------------------------------- |
| Main script | scripts/main.cjs | CLI for status/reset/config of ralph loop state |
| Pre-execute hook | hooks/pre-execute.cjs | Input validation before skill execution |
| Post-execute hook | hooks/post-execute.cjs | Output validation after skill execution |
| Input schema | schemas/input.schema.json | Input validation schema |
| Output schema | schemas/output.schema.json | Output contract schema |
| Implementation template | templates/implementation-template.md | PROMPT.md and launcher templates |
| Skill rule | rules/ralph-loop.md | Skill-specific rules |
These files are NOT part of the skill bundle. They live in the hosting project's .claude/ directory and must be created/configured by the user or via the implementation template.
| File | Project Path | Purpose |
| --------------- | ------------------------------------------ | ---------------------------------------------------------- |
| Stop hook | .claude/hooks/ralph-stop-hook.cjs | Loop controller (stdin -> transcript check -> re-inject) |
| Prompt | .claude/ralph/PROMPT.md | Audit/task instructions re-injected each iteration |
| State | .claude/context/runtime/ralph-state.json | Iteration count, timestamps, findings count (auto-created) |
| Guardrails | .claude/ralph/guardrails.md | Learned lessons from past failures |
| Launcher (bash) | .claude/ralph/ralph-audit.sh | Unix/macOS launcher script (sets RALPH_ACTIVE=1) |
| Launcher (bat) | .claude/ralph/ralph-audit.bat | Windows launcher script (sets RALPH_ACTIVE=1) |
| Settings | .claude/settings.json | Stop hook registration (Mode 1 only) |
# From your project's workspace root — sets RALPH_ACTIVE=1 automatically
.claude/ralph/ralph-audit.sh # Unix/macOS
.claude\ralph\ralph-audit.bat # Windows
# Must set RALPH_ACTIVE=1 yourself for the Stop hook to activate
export RALPH_ACTIVE=1
claude --print-output-format text < .claude/ralph/PROMPT.md
Use the /ralph-loop command within agent-studio, or have the router spawn QA agents with the audit prompt. The router manages iteration; no Stop hook is involved.
Create a custom PROMPT.md with:
| Signal | Meaning |
| --------------------------------------------- | ---------------------------------------- |
| RALPH_AUDIT_COMPLETE_NO_FINDINGS | All validations pass, zero open findings |
| RALPH_ITERATION_COMPLETE: N findings remain | Progress made, N findings still open |
The stop hook (ralph-stop-hook.cjs) follows this protocol:
RALPH_ACTIVE env var — if not '1', exit 0 immediately (no stdin read, no file checks, no-op). This is the critical protection that prevents the hook from trapping the host/router session.stop_hook_active guard (prevent infinite re-triggering)ralph-state.json exists (no state = no active loop)RALPH_AUDIT_COMPLETE_NO_FINDINGS
ralph-state.json, increment iterationRALPH_ITERATION_COMPLETE)PROMPT.md and write to stdout as JSON { decision: 'block', reason: <prompt> }| Code | Meaning | | ---- | ----------------------------------------------- | | 0 | Allow exit (complete, max iterations, or error) | | 2 | Block exit, stdout fed back as next prompt |
| Variable | Default | Description |
| --------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------- |
| RALPH_ACTIVE | (unset) | Must be 1 to activate the Stop hook. Set by launcher scripts. Without this, the hook is a no-op. |
| RALPH_MAX_ITERATIONS | 25 | Maximum loop iterations |
| RALPH_COMPLETION_SIGNAL | RALPH_AUDIT_COMPLETE_NO_FINDINGS | String that signals completion |
| RALPH_CIRCUIT_BREAKER_THRESHOLD | 3 | Consecutive iterations with unchanged findings count before circuit breaker trips |
{
"iteration": 3,
"startedAt": "2026-02-28T10:00:00Z",
"lastRunAt": "2026-02-28T10:15:00Z",
"lastFindingsCount": 5
}
When using ralph-loop for TDD workflows, use a separate TDD-specific state file at .claude/context/runtime/tdd-state.json. This schema tracks per-scenario RED/GREEN evidence across session interruptions:
{
"scenarios": [
{
"id": "sc-001",
"description": "routing-guard blocks Write on creator paths",
"status": "pending|red|green|refactored"
}
],
"completedScenarios": [
{
"id": "sc-001",
"evidenceCommand": "node --test tests/hooks/routing-guard.test.cjs",
"redEvidence": "AssertionError: expected exit code 2, got 0",
"greenEvidence": "✓ routing-guard blocks Write (4ms)",
"passedAt": "2026-03-12T10:00:00Z"
}
],
"currentScenario": "sc-002",
"evidenceLog": [
{
"scenarioId": "sc-001",
"phase": "red|green|refactored",
"output": "<verbatim test runner output>",
"timestamp": "2026-03-12T09:58:00Z"
}
]
}
TDD Session Resumption: On each loop iteration, before picking a scenario:
const tddState = JSON.parse(
fs.readFileSync('.claude/context/runtime/tdd-state.json', 'utf-8') || '{}'
);
const completedIds = (tddState.completedScenarios || []).map(s => s.id);
const remaining = (tddState.scenarios || []).filter(s => !completedIds.includes(s.id));
if (remaining.length === 0) {
// All scenarios complete — emit RALPH_AUDIT_COMPLETE_NO_FINDINGS
console.log('RALPH_AUDIT_COMPLETE_NO_FINDINGS');
process.exit(0);
}
const nextScenario = remaining[0];
Critical rule: Never re-execute scenarios already in completedScenarios. The evidenceLog is append-only — each phase (red/green/refactored) adds a new entry. Circuit breaker trips if currentScenario is unchanged for 3+ iterations.
Integration with TDP: When spawning the developer agent for a TDD loop iteration, extract the red evidence from evidenceLog and inject verbatim into the spawn prompt (see tdd skill — Test-Driven Prompting pattern).
# Mission
One-line directive.
## Before Doing Anything
Step 1: Read previous findings (if exists)
Step 2: Load context/skills
## Scope
Numbered list of areas to audit/fix.
## Validation Commands
Commands that must pass for completion.
## Findings Log
Where to write findings (path + format).
## Completion Condition
Exact signal strings and when to use each.
The guardrails.md file accumulates "Signs" — lessons learned from failures:
### Sign: [Name]
- **Trigger**: When this applies
- **Instruction**: What to do
- **Added after**: What failure taught this
Agents should read guardrails.md at the start of each iteration and add new Signs when they encounter novel failure modes.
Input validated against schemas/input.schema.json before execution.
Output contract defined in schemas/output.schema.json.
| Anti-Pattern | Why It Fails | Correct Approach |
| ------------------------------------ | ----------------------------------------------- | ----------------------------------------------- |
| No max iterations | Infinite loop burns tokens | Always set maxIterations (default 25) |
| Vague completion criteria | Agent claims "done" prematurely | Use binary pass/fail validation commands |
| No state persistence | Progress lost on context reset | Write findings to file, read at iteration start |
| Stop hook without RALPH_ACTIVE guard | Traps host/router session in multi-agent setups | Check RALPH_ACTIVE=1 before any other logic |
| Running standalone mode from router | Router gets trapped by Stop hook | Use router-managed iteration (Mode 2) instead |
| No guardrails | Same mistakes repeated each iteration | Maintain guardrails.md with learned Signs |
RALPH_ACTIVE=1 env var before reading stdin, checking files, or any other logic. This is the primary protection against trapping the host/router.Before starting:
Read .claude/context/memory/learnings.md using the Read tool.
Check for:
After completing:
learnings.md.claude/ralph/guardrails.mddecisions.mdASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
tools
Comprehensive biosignal processing toolkit for analyzing physiological data including ECG, EEG, EDA, RSP, PPG, EMG, and EOG signals. Use this skill when processing cardiovascular signals, brain activity, electrodermal responses, respiratory patterns, muscle activity, or eye movements. Applicable for heart rate variability analysis, event-related potentials, complexity measures, autonomic nervous system assessment, psychophysiology research, and multi-modal physiological signal integration.
tools
Comprehensive toolkit for creating, analyzing, and visualizing complex networks and graphs in Python. Use when working with network/graph data structures, analyzing relationships between entities, computing graph algorithms (shortest paths, centrality, clustering), detecting communities, generating synthetic networks, or visualizing network topologies. Applicable to social networks, biological networks, transportation systems, citation networks, and any domain involving pairwise relationships.
data-ai
Molecular featurization for ML (100+ featurizers). ECFP, MACCS, descriptors, pretrained models (ChemBERTa), convert SMILES to features, for QSAR and molecular ML.
development
Run Python code in the cloud with serverless containers, GPUs, and autoscaling. Use when deploying ML models, running batch processing jobs, scheduling compute-intensive tasks, or serving APIs that require GPU acceleration or dynamic scaling.