ralph-loop

A command that keeps an agent working in a loop until it reports a defined completion promise or reaches its iteration limit. It follows TDD, or test-driven development: write a failing test, make it pass, then improve the code.

In plain words
What is it for?
Use it for longer coding tasks that need repeated test-and-fix cycles, especially when running the workflow manually outside an orchestrated process.
Why use it?
It prevents the agent from stopping after one incomplete attempt. The required test stages leave evidence that the change worked before and after cleanup.

Command

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.

agentmods
npx agentmods add commands/aegntic/compound-engineering/ralph-loop
Clone the repo
git clone --depth 1 https://github.com/aegntic/compound-engineering
Per session 19 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 319 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00019 $0.00319
Opus 5 $0.00010 $0.00160
Sonnet 5 $0.00004 $0.00064
Haiku 4.5 $0.00002 $0.00032

Measured 2d ago against content hash 9e5b33bdd622, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ralph-loop scanned grade A with 0 findings 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 2d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/ralph-loop.md · 37 lines

What it actually says

Ralph Loop

Start a self-referential loop using the stop hook mechanism.

Ralph is the canonical red-green-refactor engine behind /workflows:work when the resolved TDD contract selects Ralph-driven execution. Use this command directly only when you need manual control outside the orchestrated work path; it is not a detached alternative workflow.

Setup

Run the setup script via Bash tool:

bash "${CLAUDE_PLUGIN_ROOT}/scripts/setup-ralph-loop.sh" $ARGUMENTS

After setup, proceed with the prompt specified in the arguments. The stop hook will prevent exit and feed the prompt back until the completion promise is output or max iterations are reached.

Any Ralph-driven run should preserve this contract:

  1. RED first -- run failing tests before implementation
  2. GREEN second -- add the minimal implementation needed to pass
  3. REFACTOR third -- clean up behavior-preserving code
  4. POST-REFACTOR RERUN -- rerun the required tests and capture stable report evidence for:
    • Red
    • Green
    • Post-Refactor Green

To signal completion, output: <promise>YOUR_PROMISE_TEXT</promise>

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. 2d ago First seen · 37 lines · 19 tokens per session scan A 9e5b33bdd622

Subscribe to this mod's changes

ralph-loop is a command published in the GitHub repository aegntic/compound-engineering (2 stars, last pushed 2mo ago), licensed MIT. It adds 19 tokens to every session and 319 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.