Ralph loop

From DNYoussef/context-cascade · View interactive version

Ralph loop is an AI agent skill from the GitHub repository DNYoussef/context-cascade. [assert|neutral] Persistence loop system that prevents premature task completion by using Stop hooks to re-inject prompts until success criteria are met. Named after Ralph Wiggum from The Simpsons. Use for iterative t [ground:given] [conf:0.95] [state:confirmed]

How to use this skill

Skill file

/============================================================================/

/* RALPH-LOOP SKILL :: VERILINGUA x VERIX EDITION */

/============================================================================/


name: ralph-loop

version: 1.0.0

description: |

[assert|neutral] Persistence loop system that prevents premature task completion by using Stop hooks to re-inject prompts until success criteria are met. Named after Ralph Wiggum from The Simpsons. Use for iterative t [ground:given] [conf:0.95] [state:confirmed]

category: orchestration

tags:

author: Context Cascade (integrated from Anthropic's Ralph Wiggum plugin)

cognitive_frame:

primary: evidential

goal_analysis:

first_order: "Execute ralph-loop workflow"

second_order: "Ensure quality and consistency"

third_order: "Enable systematic orchestration processes"


/----------------------------------------------------------------------------/

/* S0 META-IDENTITY */

/----------------------------------------------------------------------------/

[define|neutral] SKILL := {

name: "ralph-loop",

category: "orchestration",

version: "1.0.0",

layer: L1

} [ground:given] [conf:1.0] [state:confirmed]

/----------------------------------------------------------------------------/

/* S1 COGNITIVE FRAME */

/----------------------------------------------------------------------------/

[define|neutral] COGNITIVE_FRAME := {

frame: "Evidential",

source: "Turkish",

force: "How do you know?"

} [ground:cognitive-science] [conf:0.92] [state:confirmed]

Kanitsal Cerceve (Evidential Frame Activation)

Kaynak dogrulama modu etkin.

/----------------------------------------------------------------------------/

/* S2 TRIGGER CONDITIONS */

/----------------------------------------------------------------------------/

[define|neutral] TRIGGER_POSITIVE := {

keywords: ["ralph-loop", "orchestration", "workflow"],

context: "user needs ralph-loop capability"

} [ground:given] [conf:1.0] [state:confirmed]

/----------------------------------------------------------------------------/

/* S3 CORE CONTENT */

/----------------------------------------------------------------------------/

Ralph Loop (Persistence Loop System)

Kanitsal Cerceve (Evidential Frame Activation)

Kaynak dogrulama modu etkin.

An orchestration skill that implements continuous self-referential AI loops for iterative development until task completion.

SKILL-SPECIFIC GUIDANCE

When to Use This Skill

When NOT to Use This Skill

Success Criteria

Edge Cases & Limitations

Critical Guardrails

Core Concept

Ralph Loop creates a self-referential feedback loop:

1. User runs /ralph-loop once with task
2. Claude works on task
3. Claude tries to exit
4. Stop hook intercepts exit
5. If completion promise NOT found:
   - Increment iteration
   - Re-inject same prompt
   - Loop continues
6. If completion promise found OR max iterations:
   - Allow exit
   - Report results

How It Works Under the Hood

State File

Location: ~/.claude/ralph-wiggum/loop-state.md

---
session_id: 20251228-143022-12345
iteration: 3
max_iterations: 50
completion_promise: "COMPLETE"
started_at: 2025-12-28T14:30:22
active: true
---

[Original prompt here]

Stop Hook Mechanism

The Stop hook (ralph-loop-stop-hook.sh):

  1. Checks if loop is active
  2. Validates iteration < max_iterations
  3. Searches output for <promise>TEXT</promise> pattern
  4. If not complete: exits with code 2 (blocks exit)
  5. Re-injects original prompt with iteration info

Integration with Three-Loop System

Ralph Loop complements the Three-Loop system:

| Loop | Purpose | Ralph Integration |

|------|---------|-------------------|

| Loop 1: Planning | Research-driven planning | N/A (planning phase) |

| Loop 2: Implementation | Parallel swarm execution | Ralph handles single-agent iteration |

| Loop 3: CI/CD | Intelligent recovery | Ralph can drive fix-until-pass loops |

Recommended Pattern

Phase 1-4: Use 5-phase workflow for planning
Phase 5: Use /ralph-loop for persistent execution

Commands

/ralph-loop

Start a persistence loop.

/ralph-loop "<prompt>" --max-iterations N --completion-promise "<text>"

/cancel-ralph

Cancel active loop.

/cancel-ralph

Prompt Templates

TDD Loop

Implement [FEATURE] using TDD:

1. Write failing tests first
2. Implement minimum code to pass
3. Run tests
4. If any fail, debug and fix
5. Refactor if needed
6. Repeat until all green

Output <promise>TESTS_PASS</promise> when ALL tests pass.

Coverage Loop

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.