Claude Code · Codex · Guide

Claude x Codex Loop: do AI agents, ek loop

4
steps per round
3
max iterations
1
SKILL.md file

Skip to the prompt for Claude Code ↓

Loop kaise chalta hai

The loop
Claude: PLAN  -->  Codex: EXECUTE  -->  Claude: CHECK  -->  Codex: IMPROVE
                                              |                    |
                                  sab pass? STOP  <----- nahi to wapas CHECK
RoleKaunKaam
PlannerClaudeTask ko chhote steps + "done" criteria mein todta hai
ExecutorCodexPlan ke mutabiq code likhta hai
CheckerClaudeDiff padhta hai, tests chalata hai, issues ki list banata hai
ImproverCodexSirf us list ke issues fix karta hai
  • Stop condition: checker kahe "sab criteria pass" (tests green + koi issue nahi).
  • Max iterations: 3 (cap zaroor lagao, warna loop chalta reh sakta hai aur usage jalta hai).
  • Roles ulta bhi kar sakte ho (Codex plan, Claude execute). Concept same hai: ek banata hai, doosra parakhta hai.

Ye cheezein ready rakho

  • Claude Code account: Pro, Max, Team, Enterprise ya Console. Free claude.ai plan mein Claude Code nahi hai (docs ke mutabiq).
  • Codex ke liye ChatGPT account se sign-in (ya API key). Kaunsa plan Codex deta hai aur kitni limit: check current limits OpenAI ke pricing page pe.
  • Node.js 22+ (npm install ke liye) aur Git.
  • Ek project folder jo git repo ho.

Claude Code install

Windows PowerShell
irm https://claude.ai/install.ps1 | iex
macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash

Naya terminal kholo, claude --version chalao, phir claude se login karo.

Codex CLI install

Terminal
npm install -g @openai/codex
codex --version
codex        # pehli baar: "Sign in with ChatGPT"

macOS/Linux pe OpenAI ka installer bhi hai: curl -fsSL https://chatgpt.com/codex/install.sh | sh.

Claude Codex ko kaise bulata hai

Claude Code Bash se koi bhi CLI chala sakta hai. Codex ka non-interactive mode codex exec hai:

Claude Code chalata hai
cat .loop/task.md | codex exec --sandbox workspace-write -
  • --sandbox workspace-write = Codex sirf project ki files edit kar sake. Default read-only hai.
  • - ka matlab prompt stdin se aaye (quotes ki jhanjhat nahi).
  • danger-full-access kabhi mat use karo.

Skill folder banao aur SKILL.md paste karo

Terminal
mkdir -p ~/.claude/skills/claude-codex-loop

(Windows: %USERPROFILE%\.claude\skills\claude-codex-loop.) Sirf ek project ke liye: .claude/skills/claude-codex-loop/ project ke andar. Phir usme SKILL.md banao:

SKILL.md
---
name: claude-codex-loop
description: Run a plan/execute/check/improve loop where Claude plans and checks and Codex executes and improves. Use when the user asks for the Claude x Codex loop.
disable-model-invocation: true
argument-hint: "[task description]"
allowed-tools: Bash(codex exec *) Bash(git *)
---

Task: $ARGUMENTS

Rules: max 3 iterations. Never touch .env or secrets. Codex runs only with --sandbox workspace-write.

1. PLAN (you, Claude): write .loop/plan.md with small steps and a "Done when" list
   of testable criteria (tests pass, lint clean, specific behavior works).
   Make sure we are on a new git branch first.
2. EXECUTE (Codex): run
   cat .loop/plan.md | codex exec --sandbox workspace-write -
   with the instruction "Implement this plan. Do not change anything outside it."
3. CHECK (you, Claude): read `git diff`, run the project's tests/lint, compare with
   "Done when". Write .loop/issues.md: PASS or a numbered list of concrete problems.
4. IMPROVE (Codex): if issues exist, run
   cat .loop/issues.md | codex exec --sandbox workspace-write -
   with "Fix only these issues." Then go back to step 3.
5. STOP when CHECK says PASS or after 3 iterations. Report: iterations used, what
   changed, anything still failing. Do not commit; leave the diff for the human.

Claude Code skills docs ke mutabiq disable-model-invocation: true ka matlab skill sirf tum manually chalate ho. allowed-tools sirf us ek turn ke liye pre-approve karta hai.

Chalao

Claude Code kholo (project folder mein) aur:

Claude Code
/claude-codex-loop add a /health endpoint with a test

Worked example

Task: "Express app mein /health endpoint + test."

  1. Plan: Claude .loop/plan.md banata hai: route add, Jest test, "Done when: npm test pass, GET /health = 200 {status:"ok"}".
  2. Execute: Codex route aur test likhta hai.
  3. Check: Claude tests chalata hai. Test fail: response JSON key galat. issues.md mein 1 issue.
  4. Improve: Codex sirf wo fix karta hai.
  5. Check (round 2): PASS. Loop stop. Tum git diff khud review karte ho.

(Ye illustration hai, koi guaranteed result nahi.)

Safety

  • Diff khud review karo commit se pehle. Checker bhi AI hai, galat ho sakta hai.
  • Prod secrets mat do: .env, API keys, production DB URL agents ke paas na hon. Alag dev keys use karo.
  • Iteration cap (3) aur chhota task: loop ka har round dono taraf usage khata hai.
  • Naye git branch pe chalao taake wapas ja sako.
  • danger-full-access ya "sab approve" mode avoid karo.

Common Mistakes

  1. Vague task: "app better banao". "Done when" measurable likho.
  2. Cap nahi lagaya: loop atak ke usage jala deta hai.
  3. Checker ke paas tests hi nahi: phir "PASS" ka matlab kuch nahi.
  4. Executor ko poora folder + secrets access de diya.
  5. Ek round mein bohot bada task. Chhote tasks mein todo.
  6. Codex login/install bhoole, codex: command not found: codex --version pehle check karo.
  7. Diff review kiye bina merge.

Checklist

  • Claude Code install + login (claude --version)
  • Codex CLI install + sign-in (codex --version)
  • Project git repo hai, naya branch bana
  • ~/.claude/skills/claude-codex-loop/SKILL.md paste kiya
  • .env/secrets agents se door
  • Max iterations = 3
  • Task chhota, "Done when" measurable
  • /claude-codex-loop <task> chalaya, diff review kiya

Using Claude Code or Codex?

Paste this. Let your agent set it up.

Prompt
Set up the Claude x Codex loop skill from https://theaikhan.com/guides/claude-codex-loop
1. Run `claude --version` and `codex --version`. If one is missing, stop and tell me how to install it.
2. Create ~/.claude/skills/claude-codex-loop/SKILL.md with the exact SKILL.md from the guide.
3. Never read or touch .env files or secrets.
4. When done, tell me to open my project on a new git branch and run:
   /claude-codex-loop <small task with a clear "done when">

Home