Get the FREE Ultimate OpenClaw Setup Guide →

Ralph Iterate

npx machina-cli add skill stavarengo/ralph-wiggum-loop/ralph-iterate --openclaw
Files (1)
SKILL.md
7.2 KB

ralph-iterate

Run a single iteration manually for debugging or careful stepping.

What This Skill Does

This skill executes exactly ONE iteration of Ralph's work cycle. It spawns a single ralph-worker subagent, waits for it to complete, displays the result, and then stops. This is useful for:

  • Debugging Ralph's behavior step-by-step
  • Carefully controlling when iterations happen
  • Testing changes to PROMPT.md or fix_plan.md
  • Working through complex tasks with manual oversight

Prerequisites

Before running /ralph:iterate, you must have:

  1. Initialized Ralph: Run /ralph:init first
  2. PROMPT.md exists: File must exist at docs/ai/ralph/PROMPT.md
  3. fix_plan.md exists: File must exist at docs/ai/ralph/fix_plan.md
  4. status.json exists: File must exist at docs/ai/ralph/status.json

Implementation

When this skill is invoked:

1. Validate Prerequisites

Check that all required files exist:

# Check that Ralph has been initialized
if [[ ! -f docs/ai/ralph/PROMPT.md ]]; then
  echo "Error: docs/ai/ralph/PROMPT.md not found. Run /ralph:init first."
  exit 1
fi

if [[ ! -f docs/ai/ralph/fix_plan.md ]]; then
  echo "Error: docs/ai/ralph/fix_plan.md not found. Run /ralph:init first."
  exit 1
fi

if [[ ! -f docs/ai/ralph/status.json ]]; then
  echo "Error: docs/ai/ralph/status.json not found. Run /ralph:init first."
  exit 1
fi

2. Record Base Commit (if not already set)

If no base_commit exists in status.json yet (e.g., first iteration, or user is using /ralph:iterate without /ralph:start), record the current HEAD as the squash anchor:

EXISTING_BC=$(jq -r '.base_commit // empty' docs/ai/ralph/status.json)
if [[ -z "$EXISTING_BC" ]]; then
  jq --arg bc "$(git rev-parse HEAD)" \
     '.base_commit = $bc' \
     docs/ai/ralph/status.json > /tmp/status.json.tmp
  mv /tmp/status.json.tmp docs/ai/ralph/status.json
  echo "Base commit recorded: $(git rev-parse --short HEAD)"
fi

3. Get Current Iteration Count

Read the current iteration count from status.json:

CURRENT_ITERATION=$(jq -r '.iteration_count' docs/ai/ralph/status.json)
NEXT_ITERATION=$((CURRENT_ITERATION + 1))

4. Spawn ONE Ralph Worker

Use the Task tool to spawn exactly one ralph-worker subagent:

Task tool parameters:
- subagent_type: "ralph-worker"
- instructions: "Execute iteration ${NEXT_ITERATION}. Read docs/ai/ralph/PROMPT.md, fix_plan.md, AGENTS.md, and status.json. Follow the 9-step process. Return a concise summary when done."

The ralph-worker will:

  • Read all context files (PROMPT.md, fix_plan.md, AGENTS.md, status.json)
  • Pick the highest priority task from fix_plan.md
  • Implement, test, document, commit, and update tracking
  • Return a concise summary

5. Update Iteration Count

After the worker completes, increment the iteration count in status.json:

# Atomic update using jq
jq --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
   '.iteration_count = (.iteration_count + 1) | .last_updated = $timestamp | .status = "running"' \
   docs/ai/ralph/status.json > /tmp/status.json.tmp && \
   mv /tmp/status.json.tmp docs/ai/ralph/status.json

6. Display Result

Show the worker's summary to the user in the chat. Include:

  • What iteration just completed
  • Summary of work done
  • Files changed
  • Test status
  • What's next (or if complete/blocked)

7. Check for Completion

After the worker returns, check fix_plan.md for completion signals:

if grep -q "^RALPH_COMPLETE" docs/ai/ralph/fix_plan.md 2>/dev/null; then
  echo ""
  echo "RALPH_COMPLETE signal detected. All tasks complete!"

  FINAL_ITERATION=$(jq -r '.iteration_count' docs/ai/ralph/status.json)

  # --- Squash all Ralph commits into one ---
  BASE_COMMIT=$(jq -r '.base_commit // empty' docs/ai/ralph/status.json)

  if [[ -z "$BASE_COMMIT" ]]; then
    echo ""
    echo "WARNING: No base_commit found in status.json. Cannot squash automatically."
    # Use AskUserQuestion to ask:
    #   "No base commit was recorded. Provide a commit hash to squash from, or choose 'Skip squash'."
    # If user provides a hash, use it as BASE_COMMIT.
    # If user chooses "Skip squash", skip the squash step.
  else
    echo "Squashing commits from base $BASE_COMMIT to HEAD..."

    # Derive a commit message from the first heading in fix_plan.md
    PLAN_TITLE=$(head -5 docs/ai/ralph/fix_plan.md | grep "^#" | head -1 | sed 's/^#\+ *//')
    if [[ -z "$PLAN_TITLE" ]]; then
      PLAN_TITLE="Ralph autonomous implementation"
    fi

    git reset --soft "$BASE_COMMIT"
    git add .
    git commit -m "feat: ${PLAN_TITLE}

Squashed from ${FINAL_ITERATION} Ralph iterations.

Co-Authored-By: Ralph Wiggum <ralph@claude-code>"

    echo "All commits squashed into one: $(git rev-parse --short HEAD)"
  fi

  # Update status to complete
  jq '.status = "complete" | .last_updated = now | .completed_at = now' \
    docs/ai/ralph/status.json > /tmp/status.json.tmp
  mv /tmp/status.json.tmp docs/ai/ralph/status.json

  echo ""
  echo "Ralph completed successfully!"
  echo "- Total iterations: $FINAL_ITERATION"
  echo "- All commits squashed into a single commit."

elif grep -q "^RALPH_BLOCKED" docs/ai/ralph/fix_plan.md 2>/dev/null; then
  BLOCKER=$(grep "^RALPH_BLOCKED" docs/ai/ralph/fix_plan.md | head -1)

  jq '.status = "blocked" | .last_updated = now | .blocked_at = now' \
    docs/ai/ralph/status.json > /tmp/status.json.tmp
  mv /tmp/status.json.tmp docs/ai/ralph/status.json

  echo ""
  echo "Ralph blocked: $BLOCKER"
  echo "Review fix_plan.md to resolve the blocker, then run /ralph:iterate or /ralph:start again."
fi

8. Exit (No Loop)

IMPORTANT: This skill does NOT loop. It executes exactly one iteration and then stops. To run another iteration, the user must:

  • Run /ralph:iterate again (manual stepping)
  • Run /ralph:start to begin autonomous looping

Example Output

After running /ralph:iterate, you might see:

Iteration 3 complete.

Summary from ralph-worker:
- Implemented user authentication endpoint
- Files changed: src/auth.rs, tests/auth_test.rs
- Tests: PASS (all 15 tests passing)
- Next: Implement password reset flow

To continue:
- Run /ralph:iterate again for the next iteration
- Run /ralph:start to begin autonomous looping
- Run /ralph:stop if you're done

Difference from /ralph:start

Feature/ralph:iterate/ralph:start
IterationsONEContinuous loop until complete/stopped
ControlManualAutonomous
Use caseDebugging, careful steppingProduction autonomous development
Stops after1 iterationAll tasks complete or /ralph:stop
Squash on completeYesYes
Records base_commitYes (if not already set)Yes (always at start)

Notes

  • Each iteration is fully independent with fresh context
  • The worker reads all context files at the start of each iteration
  • status.json tracks the iteration count, status, and base_commit
  • On RALPH_COMPLETE, commits are squashed back to base_commit — same behavior as /ralph:start
  • If using /ralph:iterate repeatedly (without /ralph:start), the base_commit is recorded on the first invocation and preserved across subsequent calls
  • Use this skill when you want fine-grained control over Ralph's execution

Source

git clone https://github.com/stavarengo/ralph-wiggum-loop/blob/main/skills/ralph-iterate/SKILL.mdView on GitHub

Overview

ralph-iterate runs exactly one iteration of Ralph's work cycle. It spawns a single ralph-worker subagent, waits for it to finish, displays the result, and then stops. This is valuable for step-by-step debugging, precise timing, and validating small changes to prompts and plans.

How This Skill Works

When invoked, it validates prerequisites (PROMPT.md, fix_plan.md, status.json) and records a base commit if needed. It then spawns one ralph-worker with instructions to read the context files (PROMPT.md, fix_plan.md, AGENTS.md, and status.json), executes the next prioritized task, and after completion updates status.json and shows a concise summary.

When to Use It

  • You want to debug Ralph's behavior step-by-step.
  • You need precise control over when iterations occur.
  • You want to test changes to PROMPT.md or fix_plan.md.
  • You are working through complex tasks with manual oversight.
  • You want to validate status tracking and base commit handling before full runs.

Quick Start

  1. Step 1: Ensure Ralph is initialized and PROMPT.md, fix_plan.md, status.json exist.
  2. Step 2: Run /ralph:iterate to spawn one ralph-worker and wait for it to finish.
  3. Step 3: Review the worker's summary, then proceed to the next action (or complete).

Best Practices

  • Ensure PROMPT.md, fix_plan.md, and status.json exist before running.
  • Run in a controlled environment to avoid side effects.
  • Review the worker's concise summary and any files changed.
  • Keep PROMPT.md and fix_plan.md updated between iterations.
  • Monitor status.json for iteration_count and last_updated after each run.

Example Use Cases

  • Debugging a failing step in a multi-part task.
  • Stepping through a task to verify prompt behavior.
  • Testing a fix_plan.md change and ensuring it's picked up.
  • Incremental iteration to validate status.json updates.
  • Manual oversight while integrating change proposals (AGENTS.md).

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers