codex-loop

An automated review loop that checks the changes on a feature branch against a base branch, fixes real problems, and repeats until two reviews find nothing.

In plain words
What is it for?
Use it to run repeated Codex code reviews, repair findings with regression tests, and stop after two consecutive clean reviews.
Why use it?
It reduces the chance that code issues remain after one review and keeps applying fixes without requiring the developer to supervise each round.

Command for Claude Code

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/runnithan/claudex-setup/codex-loop
Clone the repo
git clone --depth 1 https://github.com/runnithan/claudex-setup

Made for: Claude Code.

Per session 36 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,569 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.00036 $0.02569
Opus 5 $0.00018 $0.01285
Sonnet 5 $0.00007 $0.00514
Haiku 4.5 $0.00004 $0.00257

Measured yesterday against content hash d3de77076962, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

codex-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 yesterday.

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.

.claude/commands/codex-loop.md · 223 lines

How it starts

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

/codex-loop: review, fix, repeat until clean

Run codex review against a base branch, fix what it finds, and keep looping until two consecutive rounds return no findings. Run autonomously. Do not report back between rounds and do not ask permission to continue; the point is that the owner starts it and walks away.

--base is the COMPARISON point, not the branch under review. Run this from the feature branch you are working on; --base main then reviews everything that branch adds on top of main. Do not check out the base branch to run it. Default base is main.

There is no round cap by default. Run as many rounds as it takes. --max-rounds N sets an optional ceiling. The stop conditions in §6 are the real terminators, and they are what keep this from being an infinite loop.

Fixes run on Opus (pinned in this file's frontmatter). Triage is the hard part of this loop, and a cheaper model tends to apply findings literally, which is the exact failure §2 exists to prevent.

Requires the Codex CLI, authenticated, with codex review available (codex review --help).


0. Before the first round

  1. Start whatever services the test suite needs (database container, etc.). A suite whose dependency is missing often does not fail cleanly, it hangs, which reads like a slow suite rather than a missing dependency and can burn half an hour before you notice. Start dependencies first, and if a suite runs far longer than its usual time, suspect a missing service before suspecting the tests.
  2. Confirm the working tree is clean apart from the work you intend to review.
  3. Create or resume the state file .planning/codex-loop/STATE.md (or the project's equivalent scratch location). This loop runs long enough to be compacted mid-flight and everything that matters between rounds otherwise lives only in context. If the file exists with an unfinished run, RESUME from it rather than restarting the count.
# codex-loop state
base: main
started: <HEAD sha at round 1>
round: <n>
consecutive_clean: <0..2>
max_rounds: none

## Rounds
- R1: 4 findings -> 4 fixed (sha, sha, ...)
- R2: 3 findings -> 2 fixed, 1 rejected (reason)
- R4: 2 findings, all self-inflicted x2 -> fixed by Codex (escalation) (sha, sha)

## Rejected (do not re-litigate)
- <finding>, <evidence it is not real, or why the suggested fix is wrong>

## Flagged, deliberately not fixed
- <finding>, <why>

## Self-inflicted
- <finding>, caused by <sha> earlier in this loop

Read the full file on GitHub · 223 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. yesterday First seen · 223 lines · 36 tokens per session scan A d3de77076962

Subscribe to this mod's changes

codex-loop is a command published in the GitHub repository runnithan/claudex-setup (1 stars, last pushed 2d ago), licensed MIT. It adds 36 tokens to every session and 2,569 once invoked, about $0.0002 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.