mkdir -p "${CLAUDE_PROJECT_DIR:-.}/.claude/coral/tmp" && touch "${CLAUDE_PROJECT_DIR:-.}/.claude/coral/tmp/kb-active"
Persistent Execution via Codex
Claude controls the loop. Codex executes each round. Claude verifies after each round.
Announce at start: "Using codex-ralph to execute this task via Codex with Claude-controlled verification loop."
Execution
- •Load protocol: Read
agents/codex-proxy.mdfor the prompt template and system instructions. Use the ralph role's prompt template (### Role: ralphsection). You call Codex directly - do NOT spawn a codex-proxy agent. - •Gather context: Collect task description, acceptance criteria, file paths, constraints from conversation
Execution Loop
- •Call Codex: Use
codex({ op: "exec", ... })(first round) orcodex({ op: "exec", session: <thread_id>, ... })with saved thread_id (subsequent rounds). Follow the protocol's prompt template. Passworking_directoryandreasoning_effort: "high". - •Save thread_id from the response for session continuity
- •Verify the changes yourself:
- •Read changed files
- •Compare against acceptance criteria
- •Use LSP/type-check only. NEVER run build or test during the execution loop.
- •Loop decision:
- •All criteria pass → exit loop, go to Post-Completion Review
- •Not complete → go to step 1 with thread_id + updated progress context
- •Max 5 rounds → ask user whether to continue or finalize
Post-Completion Review
Tests passing does not mean the work is correct. Codex may produce code that passes tests but diverges from the plan - especially for untestable content (docs, prompts, config).
After the loop exits:
- •
Read every changed file that Codex modified across all rounds
- •
Compare against the plan/requirements - does each file match what was specified?
- •
Flag untestable content - documentation, markdown, config: verify these match the plan
- •
Fix discrepancies yourself - do not send back to Codex; fix them directly
- •
Report to the user what was done correctly and what you corrected
- •
Post-implementation sequence (strict order, fail-fast by cost): Scope gate: Steps a-d apply only when source-affecting files are modified (
src/,scripts/,package.json,tsconfig.json). Non-source changes (agents/,skills/,docs/,hooks/,.claude/) skip directly to completion.--redadversarial testing: If--redis present in the task argument, spawncoral:red-attackervia Task tool in background (run_in_background: true) immediately before step a. Include in the prompt:- •
implementer: codex(Claude generates tests directly - no Codex delegation) - •Changed files list or scope description
- •
plan_context: <plan summary>(if a plan was used for this task)
a. Lint: Run linter if available. Cheapest check first. b. Parallel validation: Spawn
coral:architectfor architecture review. Additionally, if project instructions define workflow rules (e.g., review-orchestrator), execute them as parallel subagents alongside architect. Both must pass before proceeding to build. c. Build: Run the project's build command. d. Red-attacker gate (if--red): Wait for background red-attacker to complete. Read its output for the list of generated test files. e. Test: Run the test suite after build succeeds. If--red, this now includes adversarial tests. f. Red fix loop (if--redand adversarial test failures): Fix failures → re-run test. Cap at 3 iterations - if still failing, report remaining failures and escalate rather than looping indefinitely. g. Red triage (if--redand tests pass): Review each red test before merging. Red-attacker runs without full context - it may generate tests that target the wrong module, duplicate existing coverage, or test unreachable scenarios.- •For each
red-<target>.<ext>file, read the test and verify:- •Tests target code that was actually changed in this task (not unrelated modules)
- •Test scenarios are reachable (not testing impossible states or mocked-away paths)
- •No substantial overlap with existing tests in the main test file
- •Merge tests that pass triage: move
describeblocks into the main test file (append at end, preserve imports), delete thered-file - •Discard tests that fail triage: delete the
red-file, note the reason briefly - •Re-run tests to verify merge correctness
- •Record the adversarial test provenance in the commit message, not in file naming
- •
Sandbox bypass
Pass bypass: true only when the user explicitly requests bypass mode. Otherwise, omit the field.
Error Policy
If agents/codex-proxy.md cannot be read, report the error to the user. Do not fall back to inline execution - the agent protocol is a required dependency.