Skip to content
Back to search

hamel-review

MarketplaceWorks with Claude CodeGitHub

Claude Code plugin: automated code review loop with Codex

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/hamelsmu-claude-review-loop/badge.svg)](/listings/hamelsmu-claude-review-loop)

HTML

<a href="/listings/hamelsmu-claude-review-loop"><img src="/api/listings/hamelsmu-claude-review-loop/badge.svg" alt="findsafeskills safety rating" /></a>

Install

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

From the CLI:

claude plugin marketplace add hamelsmu/claude-review-loop
claude plugin install review-loop@hamel-review

Or from within a Claude Code session:

/plugin marketplace add hamelsmu/claude-review-loop
/plugin install review-loop@hamel-review

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/marketplace.json · Manifest · 22 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "hamel-review",
  3. "owner": {
  4. "name": "Hamel Husain"
  5. },
  6. "metadata": {
  7. "description": "Automated code review loop plugin for Claude Code"
  8. },
  9. "plugins": [
  10. {
  11. "name": "review-loop",
  12. "source": "./plugins/review-loop",
  13. "description": "Automated code review loop: Claude implements, Codex reviews independently, Claude addresses feedback",
  14. "author": {
  15. "name": "Hamel Husain"
  16. },
  17. "repository": "https://github.com/hamelsmu/claude-review-loop",
  18. "license": "MIT",
  19. "keywords": ["code-review", "codex", "quality", "automation"]
  20. }
  21. ]
  22. }
README.md · README · 138 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # review-loop
  2. A Claude Code plugin that adds an automated code review loop to your workflow.
  3. ## What it does
  4. When you use `/review-loop`, the plugin creates a two-phase lifecycle:
  5. 1. **Task phase**: You describe a task, Claude implements it
  6. 2. **Review phase**: When Claude finishes, the stop hook prepares a [Codex](https://github.com/openai/codex) runner script and blocks exit. Claude then runs Codex directly (with output streaming to the user) and addresses the review feedback.
  7. The result: every task gets an independent second opinion before you accept the changes, and you can watch the review happen in real time.
  8. <img width="2284" height="1959" alt="memelord_meme_2026-02-22 (3)" src="https://github.com/user-attachments/assets/75af1351-47e6-4b70-a50a-9b3311773be7" />
  9. ## Review coverage
  10. The plugin spawns up to 4 parallel Codex sub-agents, depending on project type:
  11. | Agent | Always runs? | Focus |
  12. |-------|-------------|-------|
  13. | **Diff Review** | Yes | `git diff` — code quality, test coverage, security (OWASP top 10) |
  14. | **Holistic Review** | Yes | Project structure, documentation, AGENTS.md, agent harness, architecture |
  15. | **Next.js Review** | If `next.config.*` or `"next"` in `package.json` | App Router, Server Components, caching, Server Actions, React performance |
  16. | **UX Review** | If `app/`, `pages/`, `public/`, or `index.html` exists | Browser E2E via [agent-browser](https://agent-browser.dev/), accessibility, responsive design |
  17. After all agents finish, Codex deduplicates findings and writes a single consolidated review to `reviews/review-<id>.md`.
  18. ## Requirements
  19. - [Claude Code](https://claude.ai/code) (CLI)
  20. - `jq` — `brew install jq` (macOS) / `apt install jq` (Linux)
  21. - [Codex CLI](https://github.com/openai/codex) — `npm install -g @openai/codex`
  22. ### Codex multi-agent
  23. This plugin uses Codex [multi-agent](https://developers.openai.com/codex/multi-agent/) to run parallel review agents. The `/review-loop` command automatically enables it in `~/.codex/config.toml` on first use.
  24. To set it up manually instead:
  25. ```toml
  26. # ~/.codex/config.toml
  27. [features]
  28. multi_agent = true
  29. ```
  30. ## Installation
  31. From the CLI:
  32. ```bash
  33. claude plugin marketplace add hamelsmu/claude-review-loop
  34. claude plugin install review-loop@hamel-review
  35. ```
  36. Or from within a Claude Code session:
  37. ```
  38. /plugin marketplace add hamelsmu/claude-review-loop
  39. /plugin install review-loop@hamel-review
  40. ```
  41. ## Updating
  42. ```bash
  43. claude plugin marketplace update hamel-review
  44. claude plugin update review-loop@hamel-review
  45. ```
  46. ## Usage
  47. ### Start a review loop
  48. ```
  49. /review-loop Add user authentication with JWT tokens and test coverage
  50. ```
  51. Claude will implement the task. When it finishes, the stop hook:
  52. 1. Prepares a Codex runner script and prompt file
  53. 2. Blocks Claude's exit with instructions to run the review
  54. 3. Claude runs `bash .claude/review-loop-run-codex.sh` — Codex output streams to the user
  55. 4. Codex writes findings to `reviews/review-<id>.md`
  56. 5. Claude reads the review, addresses items it agrees with, then stops
  57. ### Cancel a review loop
  58. ```
  59. /cancel-review
  60. ```
  61. ## How it works
  62. The plugin uses a **Stop hook** — Claude Code's mechanism for intercepting agent exit. When Claude tries to stop:
  63. 1. The hook reads the state file (`.claude/review-loop.local.md`)
  64. 2. If in `task` phase: writes a runner script and prompt file, transitions to `addressing`, blocks exit with instructions for Claude to run Codex
  65. 3. If in `addressing` phase: allows exit and cleans up
  66. State is tracked in `.claude/review-loop.local.md` (add to `.gitignore`). Reviews are written to `reviews/review-<id>.md`.
  67. ## File structure
  68. ```
  69. claude-review-loop/
  70. ├── .claude-plugin/
  71. │ └── plugin.json # Plugin manifest
  72. ├── commands/
  73. │ ├── review-loop.md # /review-loop slash command
  74. │ └── cancel-review.md # /cancel-review slash command
  75. ├── hooks/
  76. │ ├── hooks.json # Stop hook registration (30s timeout)
  77. │ └── stop-hook.sh # Core lifecycle engine
  78. ├── scripts/
  79. │ └── setup-review-loop.sh # Argument parsing, state file creation
  80. ├── AGENTS.md # Agent operating guidelines
  81. ├── CLAUDE.md # Symlink to AGENTS.md
  82. └── README.md
  83. ```
  84. ## Configuration
  85. The stop hook timeout is set to 30 seconds in `hooks/hooks.json`. The hook itself is fast (it only writes files and returns a block decision); Codex runs separately via Claude's Bash tool.
  86. ### Environment variables
  87. | Variable | Default | Description |
  88. |----------|---------|-------------|
  89. | `REVIEW_LOOP_CODEX_FLAGS` | `--dangerously-bypass-approvals-and-sandbox` | Flags passed to `codex`. Set to `--sandbox workspace-write` for safer sandboxed reviews. |
  90. ### Telemetry
  91. Execution logs are written to `.claude/review-loop.log` with timestamps, codex exit codes, and elapsed times. This file is gitignored.
  92. ## Credits
  93. Inspired by the [Ralph Wiggum plugin](https://github.com/anthropics/claude-code/tree/main/plugins/ralph-wiggum) and [Ryan Carson's compound engineering loop](https://x.com/ryancarson/article/2016520542723924279).
plugins/review-loop/hooks/stop-hook.sh · Bundled script · 444 lines · 1 finding marked
  1. #!/usr/bin/env bash
  2. # Review Loop — Stop Hook
  3. #
  4. # Two-phase lifecycle:
  5. # Phase 1 (task): Claude finishes work → hook prepares Codex runner script → blocks exit
  6. # Phase 2 (addressing): Claude runs Codex, addresses review → hook verifies review exists → allows exit
  7. #
  8. # On any error, default to allowing exit (never trap the user in a broken loop).
  9. #
  10. # Environment variables:
  11. # REVIEW_LOOP_CODEX_FLAGS Override codex flags (default: --dangerously-bypass-approvals-and-sandbox)
  12. LOG_FILE=".claude/review-loop.log"
  13. log() {
  14. mkdir -p "$(dirname "$LOG_FILE")"
  15. echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] $*" >> "$LOG_FILE"
  16. }
  17. trap 'log "ERROR: hook exited via ERR trap (line $LINENO)"; rm -f .claude/review-loop.lock .claude/review-loop-run-codex.sh .claude/review-loop-codex-prompt.txt .claude/review-loop-retries; printf "{\"decision\":\"approve\"}\n"; exit 0' ERR
  18. # Consume stdin (hook input JSON) — must read to avoid broken pipe
  19. HOOK_INPUT=$(cat)
  20. STATE_FILE=".claude/review-loop.local.md"
  21. # No active loop → allow exit
  22. if [ ! -f "$STATE_FILE" ]; then
  23. printf '{"decision":"approve"}\n'
  24. exit 0
  25. fi
  26. # Parse a field from the YAML frontmatter
  27. parse_field() {
  28. sed -n "s/^${1}: *//p" "$STATE_FILE" | head -1
  29. }
  30. ACTIVE=$(parse_field "active")
  31. PHASE=$(parse_field "phase")
  32. REVIEW_ID=$(parse_field "review_id")
  33. # Not active → clean up and exit
  34. if [ "$ACTIVE" != "true" ]; then
  35. rm -f "$STATE_FILE"
  36. printf '{"decision":"approve"}\n'
  37. exit 0
  38. fi
  39. # Validate review_id format to prevent path traversal
  40. if ! echo "$REVIEW_ID" | grep -qE '^[0-9]{8}-[0-9]{6}-[0-9a-f]{6}$'; then
  41. log "ERROR: invalid review_id format: $REVIEW_ID"
  42. rm -f "$STATE_FILE"
  43. printf '{"decision":"approve"}\n'
  44. exit 0
  45. fi
  46. # ── Project type detection ────────────────────────────────────────────────
  47. detect_nextjs() {
  48. [ -f "next.config.js" ] || [ -f "next.config.mjs" ] || [ -f "next.config.ts" ] || \
  49. ([ -f "package.json" ] && grep -q '"next"' package.json 2>/dev/null)
  50. }
  51. detect_browser_ui() {
  52. # Has HTML/JSX/TSX files in app/ or pages/ or src/ directories, or has a public/ dir
  53. [ -d "app" ] || [ -d "pages" ] || [ -d "src/app" ] || [ -d "src/pages" ] || \
  54. [ -d "public" ] || [ -f "index.html" ]
  55. }
  56. # ── Build the multi-agent review prompt ───────────────────────────────────
  57. build_review_prompt() {
  58. local REVIEW_FILE="$1"
  59. local IS_NEXTJS=false
  60. local HAS_UI=false
  61. detect_nextjs && IS_NEXTJS=true
  62. detect_browser_ui && HAS_UI=true
  63. log "Project detection: nextjs=$IS_NEXTJS, browser_ui=$HAS_UI"
  64. # ── Preamble ──
  65. cat << PREAMBLE_EOF
  66. You are orchestrating a thorough, independent code review of recent changes in this repository.
  67. Use multi-agent to run the following review agents IN PARALLEL. Each agent should return its findings as structured text (not write to files). After ALL agents complete, consolidate their findings into a single deduplicated review file.
  68. IMPORTANT: Spawn one agent per review path below. Wait for all agents to finish. Then deduplicate overlapping findings and write the consolidated review to: ${REVIEW_FILE}
  69. PREAMBLE_EOF
  70. # ── Agent 1: Diff Review ──
  71. cat << 'DIFF_EOF'
  72. ---
  73. AGENT 1: Diff Review (focus on uncommitted and recently committed changes ONLY)
  74. Run `git diff` and `git diff --cached` to see all uncommitted changes. Also run `git log --oneline -5` and `git diff HEAD~5` for recently committed work. Focus your review EXCLUSIVELY on this changed code.
  75. Review criteria for changed code:
  76. Code Quality:
  77. - Is the changed code well-organized, modular, and readable?
  78. - Does it follow DRY principles — no copy-pasted blocks that should be abstracted?
  79. - Are names (variables, functions, files) clear and consistent with the codebase?
  80. - Are abstractions at the right level — not over-engineered, not under-abstracted?
  81. - Is there unnecessary complexity that could be simplified?
  82. Test Coverage:
  83. - Does every new function/endpoint/component have corresponding tests?
  84. - Are edge cases covered: empty inputs, nulls, boundary values, error paths?
  85. - Are tests isolated, deterministic, and fast?
  86. - Do tests verify behavior (not implementation details)?
  87. - For bug fixes: is there a regression test that would have caught the original bug?
  88. Security:
  89. - Input validation: are all user inputs validated and sanitized before use?
  90. - Authentication/authorization: are auth checks present on all protected routes/actions?
  91. - Injection: any risk of SQL injection, XSS, command injection, path traversal?
  92. - Secrets: are any credentials, API keys, or tokens hardcoded or logged?
  93. - OWASP Top 10: check for broken access control, cryptographic failures, insecure design, security misconfiguration, vulnerable dependencies, SSRF
  94. - Are error messages safe (no stack traces or internal details leaked to users)?
  95. For each issue: return file path, line number, severity (critical/high/medium/low), category, description, and suggested fix.
  96. DIFF_EOF
  97. # ── Agent 2: Holistic Review ──
  98. cat << 'HOLISTIC_EOF'
  99. ---
  100. AGENT 2: Holistic Review (evaluate overall project structure and agent readiness)
  101. Read the full project directory structure, key config files, README, and any AGENTS.md / CLAUDE.md files. This is NOT about individual line changes — it's about whether the project is well-structured for maintainability and agent-driven development.
  102. Review criteria for the whole project:
  103. Code Organization & Modularity:
  104. - Is the project structure logical and navigable? Can a new developer (or agent) find things?
  105. - Are concerns properly separated (data access, business logic, presentation, config)?
  106. - Are there god files/functions that do too much and should be split?
  107. - Is shared code properly extracted into reusable modules?
  108. - Are import paths clean (absolute imports, no deep relative paths)?
  109. Documentation & Agent Harness:
  110. - Does every major directory have an AGENTS.md with operating guidelines for agents?
  111. - Is there a CLAUDE.md symlinked to each AGENTS.md for Claude Code compatibility?
  112. - Do AGENTS.md files document: conventions, file purposes, testing patterns, common pitfalls?
  113. - Is there telemetry/observability instrumentation (logging, metrics, tracing)?
  114. - Is there a type system in use (TypeScript, Python type hints, etc.) with proper coverage?
  115. - Are there proper constraints and guardrails so agents working on the code are set up for success?
  116. - Are environment variables documented and validated at startup?
  117. - Are there clear boundaries between server-only and client-safe code?
  118. Architecture:
  119. - Is the dependency graph clean (no circular dependencies)?
  120. - Are external integrations properly abstracted behind interfaces?
  121. - Is configuration centralized rather than scattered?
  122. - Is error handling consistent across the codebase?
  123. For each issue: return file path (or directory), severity (critical/high/medium/low), category, description, and suggested fix.
  124. HOLISTIC_EOF
  125. # ── Agent 3: Next.js Best Practices (conditional) ──
  126. if [ "$IS_NEXTJS" = "true" ]; then
  127. cat << 'NEXTJS_EOF'
  128. ---
  129. AGENT 3: Next.js & React Best Practices Review
  130. This is a Next.js project. Review the codebase against these specific patterns:
  131. App Router & Server Components:
  132. - Are Server Components used by default? Is 'use client' only added when interactivity is needed?
  133. - Is data fetched in Server Components, not Client Components?
  134. - Are Suspense boundaries used for streaming slow data sources?
  135. - Are file conventions correct: layout.tsx, page.tsx, loading.tsx, error.tsx, not-found.tsx?
  136. - Are searchParams and params handled as Promises (await searchParams / await params)?
  137. - Is generateStaticParams() used to pre-render known dynamic routes?
  138. - Is generateMetadata() used for SEO-critical pages?
  139. - Is notFound() called for missing resources instead of returning null?
  140. Data Fetching & Caching:
  141. - Are parallel data fetches used (Promise.all) instead of sequential waterfalls?
  142. - Is cache strategy appropriate: no-store for fresh data, force-cache for static, revalidate for ISR?
  143. - Are cache tags used for fine-grained invalidation after mutations?
  144. - Is React.cache() used to deduplicate queries within a single request?
  145. Server Actions & Mutations:
  146. - Are Server Actions validated and auth-checked as if they were public API endpoints?
  147. - Is revalidateTag/revalidatePath called after mutations to invalidate cache?
  148. - Is after() used for non-blocking post-response work (logging, analytics)?
  149. Performance & Bundle Size:
  150. - No barrel file imports — import directly from source paths?
  151. - Is next/dynamic with { ssr: false } used for heavy client-only components?
  152. - Are non-critical libraries (analytics, error tracking) deferred until after hydration?
  153. - Are heavy bundles preloaded on user intent (hover/focus)?
  154. - Is data minimized across the RSC boundary (only pass fields client needs)?
  155. React Performance:
  156. - Is derived state calculated during render, not in effects?
  157. - Are expensive computations memoized appropriately?
  158. - Is useTransition used for non-urgent updates?
  159. - No unnecessary useEffect for things that belong in event handlers?
  160. - Are stable callback references used (functional setState, refs) to avoid re-render churn?
  161. - Is content-visibility: auto used for long lists?
  162. - Are inline scripts used to set client data before hydration (prevent FOUC)?
  163. For each issue: return file path, line number, severity (critical/high/medium/low), category, description, and suggested fix.
  164. NEXTJS_EOF
  165. fi
  166. # ── Agent 4: UX & Browser Testing (conditional) ──
  167. if [ "$HAS_UI" = "true" ]; then
  168. cat << 'UX_EOF'
  169. ---
  170. AGENT (UX): Browser-Based UX Review (SKIP if you cannot access a running dev server)
  171. If the project has a running dev server, use agent-browser to test the UI.
  172. Install agent-browser if needed: npm install -g agent-browser (or: brew install agent-browser)
  173. Testing checklist:
  174. - Navigate to all major routes/pages
  175. - Test key user workflows end-to-end (signup, login, CRUD operations, etc.)
  176. - Take screenshots at desktop (1280x720) and mobile (375x812) viewports
  177. - Check for: broken layouts, missing error states, loading states, empty states
  178. - Verify accessibility: keyboard navigation, focus indicators, color contrast
  179. - Check responsive design at multiple breakpoints
  180. - Verify forms have proper validation feedback
  181. - Check that error messages are user-friendly
  182. If the dev server is not running or you cannot access it, skip this agent and note that UX testing was not performed.
  183. For each issue: return screenshot description, severity, category, description, and suggested fix.
  184. UX_EOF
  185. fi
  186. # ── Consolidation instructions ──
  187. cat << CONSOLIDATION_EOF
  188. ---
  189. CONSOLIDATION INSTRUCTIONS (after all agents complete):
  190. 1. Collect all findings from all agents
  191. 2. Deduplicate: if multiple agents flagged the same issue, keep the most detailed version
  192. 3. Organize all findings by severity (critical first, then high, medium, low)
  193. 4. For each finding, include:
  194. - File path and line number (or directory for structural issues)
  195. - Severity: critical / high / medium / low
  196. - Category: which review path found it (Diff, Holistic, Next.js, UX)
  197. - Description: clear explanation
  198. - Suggested fix: concrete, actionable recommendation
  199. 5. End with a summary: total issues, breakdown by severity, agents that ran, overall assessment
  200. 6. Write the COMPLETE consolidated review to: ${REVIEW_FILE}
  201. IMPORTANT: You MUST create the file ${REVIEW_FILE} with the full review.
  202. CONSOLIDATION_EOF
  203. }
  204. # ── Rewrite state file to update phase (atomic, no fragile sed regex) ──────
  205. transition_phase() {
  206. local new_phase="$1"
  207. local TEMP_FILE="${STATE_FILE}.tmp.$$"
  208. # Rewrite: replace 'phase: <anything>' with 'phase: <new_phase>'
  209. # Use awk for robustness — handles whitespace variants, no anchoring issues
  210. awk -v np="$new_phase" '{
  211. if ($0 ~ /^phase:/) { print "phase: " np }
  212. else { print }
  213. }' "$STATE_FILE" > "$TEMP_FILE"
  214. mv "$TEMP_FILE" "$STATE_FILE"
  215. # Verify the transition succeeded
  216. local CHECK
  217. CHECK=$(parse_field "phase")
  218. if [ "$CHECK" != "$new_phase" ]; then
  219. log "ERROR: phase transition failed (expected=$new_phase, got=$CHECK)"
  220. return 1
  221. fi
  222. log "Phase transitioned to: $new_phase"
  223. return 0
  224. }
  225. case "$PHASE" in
  226. task)
  227. # ── Phase 1 → 2: Prepare Codex review for Claude to run directly ────
  228. # Instead of running Codex inside this hook (which blocks Claude and
  229. # hides all output), we write the prompt and a runner script, then tell
  230. # Claude to execute it via Bash so Codex output streams to the user.
  231. REVIEW_FILE="reviews/review-${REVIEW_ID}.md"
  232. mkdir -p reviews
  233. CODEX_PROMPT=$(build_review_prompt "$REVIEW_FILE")
  234. CODEX_FLAGS="${REVIEW_LOOP_CODEX_FLAGS:---dangerously-bypass-approvals-and-sandbox}"
  235. if ! command -v codex &> /dev/null; then
  236. log "ERROR: codex not found on PATH"
  237. rm -f "$STATE_FILE"
  238. REASON="ERROR: Codex CLI is not installed. The review loop requires Codex for independent code review.
  239. Install it: npm install -g @openai/codex
  240. Then run /review-loop again. Multi-agent will be auto-configured."
  241. jq -n --arg r "$REASON" '{decision:"block", reason:$r}' 2>/dev/null \
  242. || printf '{"decision":"block","reason":"Codex CLI is not installed. Install it: npm install -g @openai/codex"}\n'
  243. exit 0
  244. fi
  245. # Validate multi-agent is enabled (should have been set up by /review-loop command)
  246. CODEX_CONFIG="${HOME}/.codex/config.toml"
  247. if [ ! -f "$CODEX_CONFIG" ] || ! grep -qE '^\s*multi_agent\s*=\s*true' "$CODEX_CONFIG"; then
  248. log "ERROR: multi_agent not enabled in $CODEX_CONFIG"
  249. rm -f "$STATE_FILE"
  250. REASON="ERROR: Codex multi-agent is not enabled in ~/.codex/config.toml. This should have been configured by /review-loop but may have been changed.
  251. Add to ~/.codex/config.toml:
  252. [features]
  253. multi_agent = true
  254. Then run /review-loop again."
  255. jq -n --arg r "$REASON" '{decision:"block", reason:$r}' 2>/dev/null \
  256. || printf '{"decision":"block","reason":"Codex multi-agent is not enabled in ~/.codex/config.toml"}\n'
  257. exit 0
  258. fi
  259. # Write prompt to file for the runner script to read
  260. PROMPT_FILE=".claude/review-loop-codex-prompt.txt"
  261. printf '%s' "$CODEX_PROMPT" > "$PROMPT_FILE"
  262. # Generate runner script that Claude will execute via Bash tool.
  263. # ${CODEX_FLAGS} expands at write time to bake in the flags value.
  264. # All other $ are escaped so they stay literal in the generated script.
  265. RUNNER_SCRIPT=".claude/review-loop-run-codex.sh"
  266. cat > "$RUNNER_SCRIPT" << RUNNER_EOF
  267. #!/usr/bin/env bash
  268. LOG_FILE=".claude/review-loop.log"
  269. log() { echo "[\$(date -u +"%Y-%m-%dT%H:%M:%SZ")] \$*" >> "\$LOG_FILE"; }
  270. PROMPT_FILE=".claude/review-loop-codex-prompt.txt"
  271. if [ ! -f "\$PROMPT_FILE" ]; then
  272. echo "ERROR: prompt file missing: \$PROMPT_FILE" >&2
  273. exit 1
  274. fi
  275. log "Starting Codex multi-agent review"
  276. START_TIME=\$(date +%s)
  277. # shellcheck disable=SC2086
  278. codex ${CODEX_FLAGS} exec "\$(cat "\$PROMPT_FILE")" || CODEX_EXIT=\$?
  279. CODEX_EXIT=\${CODEX_EXIT:-0}
  280. ELAPSED=\$(( \$(date +%s) - START_TIME ))
  281. log "Codex finished (exit=\$CODEX_EXIT, elapsed=\${ELAPSED}s)"
  282. exit \$CODEX_EXIT
  283. RUNNER_EOF
  284. chmod +x "$RUNNER_SCRIPT"
  285. # Transition to addressing phase — fail-open if this breaks, otherwise
  286. # a failed transition leaves phase=task and the next stop re-runs everything.
  287. if ! transition_phase "addressing"; then
  288. log "ERROR: phase transition failed, cleaning up"
  289. rm -f "$STATE_FILE" "$RUNNER_SCRIPT" "$PROMPT_FILE"
  290. printf '{"decision":"approve"}\n'
  291. exit 0
  292. fi
  293. log "Prepared Codex review for Claude to execute (review_id=$REVIEW_ID)"
  294. REASON="Phase 1 complete. Now run the Codex multi-agent review so you can see its progress.
  295. Execute this command (use a 600000ms timeout since reviews can take several minutes):
  296. \`\`\`
  297. bash .claude/review-loop-run-codex.sh
  298. \`\`\`
  299. After the review completes, read ${REVIEW_FILE} and address the findings:
  300. 1. Read the review carefully
  301. 2. For each item, independently decide if you agree
  302. 3. For items you AGREE with: implement the fix
  303. 4. For items you DISAGREE with: briefly note why you are skipping them
  304. 5. Focus on critical and high severity items first
  305. 6. When done addressing all relevant items, you may stop
  306. Use your own judgment. Do not blindly accept every suggestion."
  307. SYS_MSG="Review Loop [${REVIEW_ID}] — Phase 2/2: Run Codex review and address feedback"
  308. jq -n --arg r "$REASON" --arg s "$SYS_MSG" \
  309. '{decision:"block", reason:$r, systemMessage:$s}' 2>/dev/null \
  310. || printf '{"decision":"block","reason":"Phase 1 complete. Run: bash .claude/review-loop-run-codex.sh then address the review.","systemMessage":"%s"}\n' "$SYS_MSG"
  311. ;;
  312. addressing)
  313. # ── Phase 2: verify review was actually produced before allowing exit ──
  314. REVIEW_FILE="reviews/review-${REVIEW_ID}.md"
  315. if [ -f "$REVIEW_FILE" ]; then
  316. # Review exists — success
  317. log "Review loop complete (review_id=$REVIEW_ID)"
  318. rm -f "$STATE_FILE" .claude/review-loop.lock .claude/review-loop-run-codex.sh .claude/review-loop-codex-prompt.txt .claude/review-loop-retries
  319. printf '{"decision":"approve"}\n'
  320. elif [ -f ".claude/review-loop-run-codex.sh" ]; then
  321. # Runner script exists but review doesn't — check retry limit
  322. RETRY_FILE=".claude/review-loop-retries"
  323. RETRY_COUNT=0
  324. if [ -f "$RETRY_FILE" ]; then
  325. RETRY_COUNT=$(cat "$RETRY_FILE" 2>/dev/null || echo 0)
  326. fi
  327. RETRY_COUNT=$(( RETRY_COUNT + 1 ))
  328. if [ "$RETRY_COUNT" -ge 2 ]; then
  329. # Already told Claude to run the script once — Codex failed, don't retry
  330. log "ERROR: Codex failed to produce review, failing open (review_id=$REVIEW_ID)"
  331. rm -f "$STATE_FILE" .claude/review-loop.lock .claude/review-loop-run-codex.sh .claude/review-loop-codex-prompt.txt "$RETRY_FILE"
  332. printf '{"decision":"approve"}\n'
  333. else
  334. echo "$RETRY_COUNT" > "$RETRY_FILE"
  335. log "Review file not found ($REVIEW_FILE), prompting Claude to run Codex"
  336. REASON="The Codex review has not been completed yet. Please run the review script (use a 600000ms timeout since reviews can take several minutes):
  337. \`\`\`
  338. bash .claude/review-loop-run-codex.sh
  339. \`\`\`
  340. Then read ${REVIEW_FILE} and address the findings."
  341. SYS_MSG="Review Loop [${REVIEW_ID}] — Codex review not yet complete"
  342. jq -n --arg r "$REASON" --arg s "$SYS_MSG" \
  343. '{decision:"block", reason:$r, systemMessage:$s}' 2>/dev/null \
  344. || printf '{"decision":"block","reason":"Codex review not yet complete. Run: bash .claude/review-loop-run-codex.sh","systemMessage":"%s"}\n' "$SYS_MSG"
  345. fi
  346. else
  347. # Neither review nor runner script — orphaned state, fail-open
  348. log "ERROR: review file and runner script both missing, cleaning up (review_id=$REVIEW_ID)"
  349. rm -f "$STATE_FILE" .claude/review-loop.lock .claude/review-loop-codex-prompt.txt .claude/review-loop-retries
  350. printf '{"decision":"approve"}\n'
  351. fi
  352. ;;
  353. *)
  354. # Unknown phase — clean up and allow exit
  355. log "WARN: unknown phase '$PHASE', cleaning up"
  356. rm -f "$STATE_FILE" .claude/review-loop.lock .claude/review-loop-run-codex.sh .claude/review-loop-codex-prompt.txt
  357. printf '{"decision":"approve"}\n'
  358. ;;
  359. esac
plugins/review-loop/scripts/setup-review-loop.sh · Bundled script · 103 lines · 1 finding marked
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Review Loop — Setup Script
  4. # Creates state file and prepares the review loop lifecycle.
  5. ARGS=()
  6. while [[ $# -gt 0 ]]; do
  7. case $1 in
  8. --help|-h)
  9. cat << 'HELP'
  10. Usage: /review-loop <task description>
  11. Starts a review loop:
  12. 1. Claude implements your task
  13. 2. Codex performs an independent code review
  14. 3. Claude addresses the feedback
  15. Environment variables:
  16. REVIEW_LOOP_CODEX_FLAGS Override codex flags (default: --dangerously-bypass-approvals-and-sandbox)
  17. Example:
  18. /review-loop Add user authentication with JWT tokens and proper test coverage
  19. HELP
  20. exit 0
  21. ;;
  22. *)
  23. ARGS+=("$1")
  24. shift
  25. ;;
  26. esac
  27. done
  28. PROMPT="${ARGS[*]:-}"
  29. if [ -z "$PROMPT" ]; then
  30. echo "Error: No task description provided."
  31. echo "Usage: /review-loop <task description>"
  32. exit 1
  33. fi
  34. # Check dependencies
  35. if ! command -v codex &> /dev/null; then
  36. echo "Warning: 'codex' CLI not found. The review phase will fall back to self-review."
  37. echo "Install Codex CLI to enable independent code reviews."
  38. fi
  39. if ! command -v jq &> /dev/null; then
  40. echo "Error: 'jq' is required but not found."
  41. echo " macOS: brew install jq"
  42. echo " Linux: apt install jq / yum install jq"
  43. echo " Docs: https://jqlang.github.io/jq/download/"
  44. exit 1
  45. fi
  46. # Check for existing loop
  47. if [ -f ".claude/review-loop.local.md" ]; then
  48. echo "Error: A review loop is already active. Use /cancel-review to abort it first."
  49. exit 1
  50. fi
  51. # Generate unique ID: timestamp + random hex
  52. # Prefer openssl, fallback to /dev/urandom
  53. if command -v openssl &> /dev/null; then
  54. RAND_HEX=$(openssl rand -hex 3)
  55. else
  56. RAND_HEX=$(head -c 3 /dev/urandom | od -An -tx1 | tr -d ' \n')
  57. fi
  58. REVIEW_ID="$(date +%Y%m%d-%H%M%S)-${RAND_HEX}"
  59. # Clean up stale lock from previous runs
  60. rm -f .claude/review-loop.lock
  61. # Create state file
  62. mkdir -p .claude
  63. cat > .claude/review-loop.local.md << STATE_EOF
  64. ---
  65. active: true
  66. phase: task
  67. review_id: ${REVIEW_ID}
  68. started_at: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
  69. ---
  70. ${PROMPT}
  71. STATE_EOF
  72. # Ensure reviews directory exists
  73. mkdir -p reviews
  74. echo ""
  75. echo "Review Loop activated"
  76. echo " ID: ${REVIEW_ID}"
  77. echo " Phase: 1/2 — Task implementation"
  78. echo " Review: reviews/review-${REVIEW_ID}.md"
  79. echo ""
  80. echo " Lifecycle:"
  81. echo " 1. You implement the task"
  82. echo " 2. Stop hook runs Codex for independent review"
  83. echo " 3. You address the feedback"
  84. echo ""
  85. echo " Use /cancel-review to abort."
  86. echo ""

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.