ralph-loop

ralph-loop is a command for Claude Code from kumaran-is/claude-code-onboarding. It costs 49 tokens per session (1,583 once invoked), scanned B, original, MIT.

An autonomous task loop that gives the same instruction back to the coding agent after each attempt, so it can keep working until it finishes or reaches a limit.

In plain words
What is it for?
It is for overnight jobs, repeated implementation attempts, and tasks that need several rounds of coding and checking.
Why use it?
It removes the need to restart long or multi-step tasks manually. You can also provide a completion check or verification command to decide whether the work is done.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter. Also seen: positional $N argument.

Good fit It is for overnight jobs, repeated implementation attempts, and tasks that need several rounds of coding and checking.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/kumaran-is/claude-code-onboarding/ralph-loop
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/kumaran-is/claude-code-onboarding

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ralph-loop

README.md
[![agentmods](https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/ralph-loop.svg)](https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/ralph-loop)
Your own site
<a href="https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/ralph-loop"><img src="https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/ralph-loop.svg" alt="Measured on agentmods" height="20"></a>
Per session 49 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,583 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00049 $0.01583
Opus 5 $0.00024 $0.00792
Sonnet 5 $0.00010 $0.00317
Haiku 4.5 $0.00005 $0.00158

Measured 4d ago against content hash 1d420093ff05, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade B, and why

ralph-loop scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

cat > "$CLAUDE_PROJECT_DIR/.claude/ralph-loop.local.md" <<EOF
.claude/commands/ralph-loop.md · 133 lines

How it starts

The opening of the file, as written. The whole thing — 133 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Ralph Loop

Start an autonomous iteration loop for the given task.

Setup

# Parse arguments and create state file
ARGS="$ARGUMENTS"
PROMPT_PARTS=()
MAX_ITERATIONS=10
COMPLETION_PROMISE="null"
VERIFY_CMD="null"

while [[ $# -gt 0 ]]; do
  case "$1" in
    --max-iterations)
      MAX_ITERATIONS="$2"; shift 2 ;;
    --completion-promise)
      COMPLETION_PROMISE="$2"; shift 2 ;;
    --verify-cmd)
      VERIFY_CMD="$2"; shift 2 ;;
    *)
      PROMPT_PARTS+=("$1"); shift ;;
  esac
done
PROMPT="${PROMPT_PARTS[*]}"

if [[ -z "$PROMPT" ]]; then
  echo "❌ No prompt provided. Usage: /ralph-loop \"Your task\" --max-iterations 10"
  exit 1
fi

mkdir -p "$CLAUDE_PROJECT_DIR/.claude"

if [[ "$COMPLETION_PROMISE" != "null" ]]; then
  CP_YAML="\"$COMPLETION_PROMISE\""
else
  CP_YAML="null"
fi

if [[ "$VERIFY_CMD" != "null" ]]; then
  VC_YAML="\"$VERIFY_CMD\""
else
  VC_YAML="null"
fi

cat > "$CLAUDE_PROJECT_DIR/.claude/ralph-loop.local.md" <<EOF
---
active: true
iteration: 1
max_iterations: $MAX_ITERATIONS
completion_promise: $CP_YAML
verify_cmd: $VC_YAML
started_at: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
---

$PROMPT
EOF

# Progress state file (separate from the hook-managed loop file — survives loop end).
# If one already exists, KEEP it: a re-run after a crash/cancel resumes from prior progress.
RALPH_STATE="$CLAUDE_PROJECT_DIR/.claude/ralph-state.local.md"
if [[ -f "$RALPH_STATE" ]]; then
  echo "📄 Existing ralph-state.local.md found — resuming with prior progress/escalations."
  echo "   (Starting an unrelated task? Delete it first: rm .claude/ralph-state.local.md)"
else
  cat > "$RALPH_STATE" <<EOF
# Ralph loop state

## Last run
$(date -u +%Y-%m-%dT%H:%M:%SZ) · iteration 1 · loop started

## In progress
- (nothing yet)

## Completed
- (nothing yet)

## Escalated to humans (do NOT retry)
- (none)

## Lessons learned (durable discoveries — write here, not in chat)
- (none)

## Attempt counts
- (sub-task: N failed attempts)
EOF
fi

echo ""
echo "🔄 Ralph loop activated!"
echo "   Iteration:   1 of $(if [[ $MAX_ITERATIONS -gt 0 ]]; then echo $MAX_ITERATIONS; else echo '∞ (unlimited)'; fi)"
if [[ "$COMPLETION_PROMISE" != "null" ]]; then
  echo "   Promise:     $COMPLETION_PROMISE"
  if [[ "$VERIFY_CMD" != "null" ]]; then
    echo "   Verifier:    $VERIFY_CMD  (must exit 0 — the promise alone will NOT end the loop)"
  fi
  echo ""
  echo "═══════════════════════════════════════════════"
  echo "  To exit: output <promise>$COMPLETION_PROMISE</promise>"
  echo "  ONLY when the statement is GENUINELY TRUE."
  if [[ "$VERIFY_CMD" != "null" ]]; then
    echo "  The loop then runs:  $VERIFY_CMD"
    echo "  Exit happens ONLY if that command returns exit 0."
  fi
  echo "  Do NOT output a false promise to escape."
  echo "═══════════════════════════════════════════════"
fi
echo ""
echo "  Monitor:  head -5 .claude/ralph-loop.local.md"
echo "  Cancel:   /cancel-ralph"
echo ""

Read the full file on GitHub · 133 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 133 lines · 49 tokens per session scan B 1d420093ff05

Subscribe to this mod's changes

ralph-loop is a command published in the GitHub repository kumaran-is/claude-code-onboarding (35 stars, last pushed 2mo ago), licensed MIT. It adds 49 tokens to every session and 1,583 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.