Ralph Implement
Unattended TDD implementation from ralph-tasks (auto mode + self-driving loop)
Claude CodeGeneric
---
allowed-tools: Bash(cat:*), Bash(test:*), Bash(ls:*), Bash(echo:*), Bash(dotnet:*), Bash(git:*), Read, Write, Edit, Glob, Grep, Agent, AskUserQuestion, ScheduleWakeup
description: Unattended TDD implementation from ralph-tasks (auto mode + self-driving loop)
argument-hint: [count]
---
## Context
Current spec directory: specs/
**Workflow**: Unattended TDD implementation — no per-test approval gates. A self-driving loop
processes ralph tasks one after another until a user-chosen bound, a STOP signal, or all tasks
are done.
**TDD Cycle**: 🔴 Red → 🟢 Green → 🔵 Refactor (no approval step)
**Runtime model — Opus orchestrator + auto mode (advisory).** This command is designed to run
**unattended**:
- **Run it on Opus.** The orchestrator (this main agent) should be on **opus** — it is the
required model for **auto mode**, and the policy for the unattended path. If the session is
not on opus, advise the user to switch (`/model opus`) before a real unattended run.
- **Enable auto mode.** Auto mode is a *permission mode* configured outside this command
(Claude Code settings, or `CLAUDE_CODE_ENABLE_AUTO_MODE` on cloud providers; Opus-gated). It
lets the loop run without per-action permission prompts. This command **cannot** toggle it.
**Advise, then proceed**: if it looks like auto mode is off (you are hitting permission
prompts), warn the user that the loop will pause for approvals and is not truly unattended —
but still run. Do not hard-block.
**AskUserQuestion — setup only.** This command may use `AskUserQuestion` **only** in the
up-front setup (Step 0): the auto-mode/Opus advisory and choosing the run bound. Once the loop
starts it is fully unattended — **never** prompt the user mid-loop.
**Sub-agent (cost control): Sonnet.** Each task's Red→Green→Refactor cycle is delegated to a
sub-agent (`subagent_type: "general-purpose"`, **`model: "sonnet"`**). The orchestrator stays
on opus for cheap bookkeeping; the expensive per-task implementation churn runs on the cheaper
**sonnet** sub-agent and in its own context, keeping it out of the loop's opus context. The
sub-agent writes the test + implementation files and RETURNS a structured result. The MAIN
agent owns everything that must stay sequential and authoritative: the STOP-file check, task
selection, the run count, marking the checkbox, **the git commit**, and the summary. The
sub-agent NEVER commits, NEVER pushes, and NEVER edits `ralph-tasks.md`/`tasks.md`. See
`.claude/commands/spec/README.md` → "Sub-agents & model policy".
Tasks are processed **strictly sequentially** — they are dependency-ordered and each gets
its own commit. Do not parallelise.
## Your Task
### Step 0: Advise Runtime, Then Ask the Run Bound
This runs **once**, before the loop starts.
1. **Runtime advisory.** Confirm the orchestrator is on **opus** and that **auto mode** is
expected for an unattended run. If the session is not on opus, advise `/model opus`. If
auto mode appears off, warn that the loop will pause for permission prompts. Advise — do not
block.
2. **Choose the bound.** The loop needs a stopping bound. If a numeric `count` was passed in
`$ARGUMENTS`, take that as the **tasks** bound and skip the prompt. Otherwise use
`AskUserQuestion` to ask the user which bound to use and its value:
- **Tasks** — stop after **N tasks complete** this run (a task "completes" on `GREEN` or
`ALREADY_COMPLETE`; `FAILED` does not count). This is the `count` argument.
- **Turns** — stop after **N loop iterations** attempted, regardless of outcome (so a run
of failures still terminates). Use when you want to cap effort, not completions.
- **Budget** — stop when roughly **N output tokens** have been consumed by the run. Use the
turn's token budget (a `+Nk`-style directive) when one is set; otherwise approximate and
stop once the loop has clearly consumed the requested budget.
Record the chosen bound type and value. Default if the user gives nothing and no `count`
was passed: **Tasks = 1**.
### Step 1: Check STOP File
If a file named `RALPH_STOP` exists at the repository root:
=== RALPH SUMMARY === Tasks completed this run: 0 Total tasks complete: X/Y Tasks remaining: Z Status: STOPPED === END RALPH ===
Then STOP immediately. Do not proceed.
### Step 2: Gather Context
1. Read `specs/.current-spec` to determine the active specification directory
2. Verify `.design-approved` exists in that directory (the unattended path runs from the
approved design — there is **no** `.tasks-approved` prerequisite)
3. Verify `specs/{current-spec}/ralph-tasks.md` exists (run `/spec:ralph-tasks` first if not)
and read it to see the ralph task list
4. Read `specs/{current-spec}/.adr-list` to see all ADRs
The main agent does **not** read the ADR bodies here — that is deliberate. Its role in this
command is bookkeeping (task selection, commit, marking, count); the per-task TDD context
(including the relevant ADRs) is read by the **sub-agent** from each task's `References`
section. This keeps the main agent's context lean.
### Step 3: Select Next Task
Find the first unchecked `- [ ]` task in `ralph-tasks.md`.
If all tasks are checked (`[x]` or `[!]`):
=== RALPH SUMMARY === Tasks completed this run: 0 Total tasks complete: X/Y Tasks remaining: 0 Status: ALL_DONE === END RALPH ===
Then STOP.
### Step 4: Delegate the TDD Cycle to a Sub-Agent
Launch an `Agent` with `subagent_type: "general-purpose"` and **`model: "sonnet"`**. The
prompt MUST include:
1. The full text of the selected task (Behavior, Test file, Test should verify,
Implementation files, RALPH-VERIFY command, References).
2. The paths `.agent_instructions/testing.md` and `.agent_instructions/code_style.md`, with
an instruction to read them before writing code.
3. The TDD cycle instructions, code-style rules, and hard constraints below.
4. The required return format below.
The sub-agent runs unattended — it has full tool access (Read
Maintain Ralph Implement?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[](https://getagentictools.com/loops/brightercommand-ralph-implement?ref=badge)