Skip to content
◀ Blog

How to use Claude Code and Codex together

Install foreman so Claude Code can hand tasks to Codex in git worktrees, answer its questions mid-run, then review and commit. Setup and data from 58 runs

Riley Hilliard19 min readUpdated

agentsclaude-codecodexforeman

To use Claude Code and Codex together, install foreman, an open-source CLI that lets Claude Code hand a written task to Codex and supervise it. Claude plans the work and writes a contract for each task. foreman starts Codex on that contract in its own git worktree, holds any question Codex asks until Claude answers, and wakes Claude when the run ends. Claude then reviews the uncommitted diff, runs your checks and commits. foreman uses your Codex ChatGPT login, so there is no API key to set up. We build our open-source developer tools this way, with Claude Opus 5.5 as the orchestrator and gpt-6.1-sol as the coder.

Quick start. You need git, a repo with at least one commit, Node 26 or newer, Claude Code, and a ChatGPT plan that includes Codex. foreman supports macOS and Linux, not Windows. Install and check:

npm i -g @steamfield/foreman
foreman skill install
npm i -g @openai/[email protected]
codex login
foreman doctor

Then open Claude Code in the repo and say: Use the foreman skill to delegate "add a --json flag to the export command" to Codex, then review its work. Swap in your own task. Setup covers the one-time repo trust step.

How do you use Claude Code and Codex together?

You give Claude Code a task and tell it to use foreman. Claude does the rest through foreman commands while you watch or do something else:

  1. Claude reads the code and writes a contract: the goal, the files Codex may change, the checks it must run and what to report.
  2. foreman start creates a git worktree and branch for the run, then starts Codex on the contract.
  3. Codex works. If it hits a decision the contract doesn’t cover, it asks, and foreman holds the question until Claude answers.
  4. When the turn ends, Claude reads the hand-off and the diff, fixes what needs fixing and runs the full gate.
  5. Claude commits. foreman never commits for you.
Claude CodePlan one unitRead designSplit by subsystemContext boundaryContractforeman startCodex / own worktreeImplement → scoped checks↓ QA as a user↓ Fresh-processself-review → fixesQuestion → Claude answersStays here, typically:~200 commands4–17M input tokens readHand-off+ diffClaude CodeReview hand-off, then diffRefactor or resumeFull gate → commitCodex leaves no commitanswer · steer · follow up
Fig. 1 One unit crosses the context boundary as a contract and returns as a hand-off and diff for Claude to review, gate and commit. Questions travel back through foreman while the run is live; schematic. Source: Schematic of the foreman workflow, as Steamfield uses it

A local daemon owns each Codex session. A run keeps going after the command that started it returns, Claude can work on something else, and a question or a finished turn wakes Claude when it needs to act.

How do you set up foreman?

The quick start installs everything. foreman skill install puts the skill in ~/.claude/skills/foreman/, which is how Claude Code learns the workflow. Codex 0.169.0 is the version foreman’s protocol is checked against. foreman needs git, a repository with at least one commit and Node 26 or newer for the npm launcher, and ships native binaries for macOS and Linux on arm64 and x64. It signs in through the Codex CLI’s ChatGPT login, so it needs no OpenAI API key.

Do one more thing once per repository. Open codex in the main checkout and trust the project. If the repo has a .codex/hooks.json, run /hooks inside Codex, read the project hooks and approve them. Then run foreman doctor again. foreman refuses to start a run in a repo whose hooks aren’t trusted, and it never approves them for you.

When you ask Claude Code to delegate a task, the skill tells Claude to run foreman guide first. The guide ships inside the binary and walks through writing a contract, waiting, answering questions, reviewing and archiving, so Claude always has the workflow that matches the version you installed.

Why use Claude to plan and Codex to code?

In our runs, Opus plans better than Codex and reviews other agents’ work more effectively, whether Codex or a Claude subagent wrote it. Before dispatching anything, it checks the design against the code and decides which pieces can run on their own. When the pieces come back, it finds code that duplicates something already in the repository.

Writing code uses up a Claude session’s tokens and context. The code Opus writes counts as output tokens, which use up a Claude usage budget far faster than input tokens, and the logs from each test run go into Opus’s context. When Codex writes the code, those tokens are spent in the Codex session, and Claude keeps its budget and context for planning and review. Codex runs still use your Codex plan; what they save is Claude’s tokens and context.

Codex writes code faster than Opus and plans worse. Before we tightened our contracts and repo rules (described below), every unit it handed back needed a refactor. Since then, gpt-6.1-sol hands back code close to what Opus would have written, and Opus fixes the rest in review.

How is foreman different from codex exec or the Codex plugin?

You can already use Codex from Claude Code without foreman. Claude can run codex exec through Bash, and OpenAI’s Codex plugin adds slash commands for reviews and background tasks. Both work, and the plugin is enough if reviews and background tasks are what you need. foreman is for implementation runs where you want a contract per task, a separate worktree for each and a way for Codex to ask Claude a question while it works.

codex exec through Bash OpenAI’s Codex plugin foreman
Where the work runs The directory you pick, or a worktree with --worktree The same checkout as Claude Code A new or prepared git worktree for each run
During a long task Claude backgrounds the Bash command and reads its output --background, /codex:status, /codex:result A local daemon owns the run; Claude waits for attention
A question from Codex Report it in the final message, then resume Read the result and send a follow-up with --resume Codex calls ask_orchestrator; Claude answers the question id
Changing a running task Resume after the run ends Cancel, or follow up after it ends foreman steer on the running turn, or followup for the next

The foreman guide to using Codex from Claude Code covers all three in more detail.

What does Claude run to start Codex?

Claude runs a handful of foreman commands. For a task called search, the whole loop is below, where the comment marks work Claude does itself:

foreman guide contract > /tmp/search-contract.md
foreman start search --new-worktree --setup "bun install" \
  --contract /tmp/search-contract.md --write --wait
foreman answer search q1 "Keep the existing signature." --wait
foreman result search
# Claude reviews the diff, commits in the worktree, merges, runs your checks
foreman archive search

foreman guide contract prints a contract template, which Claude fills in outside the worktree. foreman start --new-worktree creates .claude/worktrees/search on a branch named foreman/search from the current commit, runs the --setup command there, checks the worktree and starts Codex. By default the run uses the newest gpt-*-sol model in Codex’s model cache, high reasoning effort and the priority service tier, which is Codex’s fast mode. --model, --effort and --tier change them.

--write lets Codex edit files. Without it a run is read-only, which is right for reviews and investigations and can’t run most test suites.

--wait makes the command return when the run needs attention: a question, or the end of the turn. Claude Code runs it as a background task so Claude stays available, and each result prints a next: command to run. foreman result shows the digest and Codex’s hand-off, and foreman archive frees the run’s name and keeps its records. It also removes the worktree and branch, but only if the worktree is clean with no untracked files and its commits are merged; otherwise it refuses.

Can Claude talk to Codex while it runs?

Yes, in three ways: Codex can ask Claude a question, Claude can steer the running turn, and Claude can start a follow-up turn in the same Codex thread.

Each run gives Codex a tool called ask_orchestrator. When Codex calls it, foreman holds the call, numbers the question q1, q2 and so on, and marks the run as waiting. Claude gets the question and answers it:

foreman answer search q1 "Keep the public interface unchanged." --wait

If the decision needs a person, Claude runs foreman defer instead of guessing. A question that goes unanswered for 15 minutes is deferred automatically. Either way Codex is told to keep doing the work that doesn’t depend on the answer, take no irreversible step on the decision, use a safe default if one exists and list the question under Open in its hand-off. That is an instruction to the model, which foreman doesn’t enforce, so read the Open section in review. When the decision arrives, the same foreman answer command still works. It steers a running turn or starts a follow-up if the run has gone idle.

While building foreman’s release, one delegate asked a scope question and Claude answered it 19 seconds later. Another question sat for 15 minutes, foreman told Codex to proceed and note it, and the answer arrived afterward.

foreman / session dispatch
LOCALREADY

Claude Code writes contracts and starts astra, sol and terra in separate git worktrees. The foreman daemon holds sol's question while the others keep working. Claude answers, steers terra, reviews astra and starts a follow-up turn. Claude reviews and commits each result before archiving the merged runs. foreman never commits.

Step 4 / 10

  1. 1. Write three contracts

    Claude splits the page into three tasks, each with its own May change line. Astra handles design taste, sol implementation, and terra tests.

  2. 2. Start three worktrees

    The daemon creates each .claude/worktrees/<name> directory on foreman/<name>, runs bun install, then starts a Codex turn. The starts are staggered.

  3. 3. Wait while all three work

    Claude runs one wait in the background and goes idle. Commands and file writes stream from the delegates to the dispatch board.

  4. 4. Hold a question for Claude

    site-commands calls ask_orchestrator. The daemon holds the tool call, marks the run waiting, and wakes Claude with question q1.

  5. 5. Answer and resume waiting

    Claude answers; the held call releases and site-commands keeps working. Claude runs the next wait command printed with the answer, including its cursor.

  6. 6. Steer the active test turn

    Claude adds the 375px check while site-e2e is running, with no question pending. Steer changes the current turn's instructions.

  7. 7. Review the first result

    The wait returns done for site-console with its digest. Claude reads the result and diff, runs the site's checks, and commits the reviewed work.

  8. 8. Follow up on the same thread

    Claude starts turn 2 in site-console's existing thread and worktree. The small correction finishes, and Claude reviews and commits it.

  9. 9. Land the remaining work

    site-commands finishes, then site-e2e. Claude reviews each diff, runs the checks, commits the work and merges all three branches.

  10. 10. Archive the merged runs

    Claude archives all three runs after their branches are merged and worktrees are clean. The worktrees and branches are removed; their records stay on the board.

Read the recorded question and answer

site-commands · q1

The required strict install-command drift check finds landing.ts install.options npx command `npx @steamfield/foreman doctor`, while README.md only contains `npx @steamfield/foreman` (Install). The contract forbids editing either here or loosening the test. Please align the source copy/README in your scope so the exact-command test can pass; I will retain the strict comparison.

Claude's answer

Your test is right and the page copy is wrong. Change the npx option in site/src/data/landing.ts to exactly "npx @steamfield/foreman" (I made the same one-line change on the base branch, so the hunks will match at merge). You may edit that one line of landing.ts; nothing else in it. Keep the strict comparison.

Fig. 2 Three Codex delegates work through foreman while Claude Code plans and reviews. Activity and the question exchange are recorded; narration is scripted and timings are shortened, with 54 seconds of story replayed in about 22. Pick a step to pause there, or Replay to start over. Source: foreman's recorded site-console, site-commands and site-e2e runs

foreman steer changes a running turn, foreman followup starts another turn with the thread’s context intact, and foreman interrupt stops one. Each working turn has a 60-minute budget by default. When it runs out, foreman interrupts Codex and asks for a read-only hand-off so the work done so far isn’t lost.

Our earlier shell wrapper could not do any of this during a run. It started codex exec and waited. To fix a wrong contract, we had to stop the run and start over. In one session a devil’s-advocate review found two design errors after dispatch, and we stopped Codex at 278 seconds and relaunched with a corrected contract. A blocker could only arrive in the hand-off’s Open section after the run ended: a stacks delegate finished with “One blocker remains: lint rejects the CLI-help test’s runtime imports under src/”, and the fix was a one-line move that would have been faster to answer mid-run.

codex exec has no way in once it starts. We tested codex queue --thread <id> --message "<text>" on November 5, 2026 with Codex CLI 0.166, and foreman now pins 0.169.0, so this may have changed. The run never saw the message and carried on through its remaining test steps, and the next codex exec resume <id> delivered it word for word. foreman drives codex app-server instead, whose protocol has turn/steer and turn/interrupt, and gives each thread a dynamic tool for questions.

Can you watch what Codex is doing?

Yes. foreman monitor opens a live terminal view of every run on your machine, grouped by repository. Each row shows the run’s state, task, model, current activity and budget, with pending questions pinned at the top. Press Enter on a run, or run foreman monitor search, for its contract, questions, hand-off, changed files, timeline and live event feed.

foreman monitor            # every run on this machine
foreman monitor search     # one run's detail and live feed

The monitor opens in watching mode. The first action you take asks you to switch to acting, which lets you answer or defer a question, steer, follow up, interrupt and archive from the keyboard. If Claude has already answered, the monitor rejects your answer and keeps your draft. If you answer first and Claude then answers the same id from the CLI, Claude’s text is sent as a correction. foreman monitor --line prints one compact line for a tmux status bar, and foreman events search --follow streams a run’s events as plain text.

Can Claude run several Codex agents in parallel?

Yes. foreman has no cap on concurrent runs, with one run and one worktree per unit. We normally run up to five at once, and for a batch of independent article drafts, where each delegate owned a separate file, we raised that to ten.

foreman wait --all waits on every run in the current repository and returns as soon as any one needs attention, and foreman status --all lists every run on the machine. Run names are global, so each unit needs its own name. Parallel tasks also need independent scopes, since two runs that edit the same file will conflict at merge.

Claude first creates an integration branch, feat/<name>, off main. Each unit starts from that branch with foreman start <name> --new-worktree --from feat/<name>. Finished units merge back one at a time, and the full gate runs after each merge, so a failure points at the unit that caused it. The integration branch merges to main last.

main → integration branchUp to five foreman runs at onceClaude reviews, gates, commitseach unit before its merge.WorktreeIntegrationUnit 1CodexMerge 1Gate ✓Unit 2CodexMerge 2Gate ✓Unit 3CodexMerge 3Gate ✓Unit 4CodexMerge 4Gate ✓Unit 5CodexMerge 5Gate ✓Pass each gate beforethe next merge.main
Fig. 3 Units run in parallel but merge into integration one at a time, with a gate after each merge so a break points to one unit; schematic. Source: Schematic of a foreman fan-out, as Steamfield runs it

A unit covers one subsystem and at most three or four tasks. A unit that needs another unit’s changes starts after those changes are merged into the integration branch. Worktrees still share ports and test services, and running coding agents without collisions covers how to isolate those.

What goes in the contract?

The contract gives Codex the goal, allowed files and definition of done, along with every applicable instruction it won’t otherwise see. Codex reads AGENTS.md on its own and finds installed skills by name, but it doesn’t get the Claude conversation. Claude copies relevant constraints from CLAUDE.md and .claude/rules/ into the contract, or tells Codex to read those files. Our guide to writing CLAUDE.md and AGENTS.md covers where shared repository instructions belong.

foreman guide contract prints the full template, and foreman guide contract tests prints one for a test author. A trimmed contract looks like this:

## Goal

Add the search behavior described in the design.

## Read first

Read the search design and the existing search module.

## Interface

Keep the existing search function's signature and result type.

## Scope

- May change: `src/search.ts`, `tests/search.test.ts`.
- Must not change: everything else.
- Locked: none.

## Acceptance

Run the named search tests, lint and typecheck; exercise the change as a user.

## Do not

Commit, push, weaken tests, disable lint rules or add unrequested features.

## Review before hand-off

Get one fresh read-only review of the diff, fix findings and rerun checks.

## Hand-off

Report Summary, Files, Decisions, Checks, Review, Look closer at and Open.

foreman reads the - May change: line and reports any dirty paths outside it in the run’s digest. That is a review aid and not a sandbox, so Codex can still write outside it. Follow-ups keep the original contract’s scope. When a unit connects two modules, its scope has to include the files that wire them together, or Codex stops at the boundary and reports the run as blocked. Locked files are tests another delegate wrote, which the implementer has to make pass without editing them.

Acceptance names the scoped tests, lint and typecheck commands. Codex runs those while iterating, plus one full test-suite run, and never the aggregate gate. Claude owns the final gate before the work is done, after its refactor pass.

How did we get Codex’s code close to Opus’s?

We got closer by turning repeated review findings into repository rules and more explicit contracts. We developed those rules in the stacks repo from October 26 through November 3, 2026, using the shell wrapper that foreman later replaced. The contract and the repo rules carried over unchanged. Early units passed their tests and stayed in scope, but every unit needed a refactor before merging.

Opus found a 140-line createEntry, three nested ternaries on one flag and an optional field with a fallback path computed from import.meta.url. Other runs added a second registry lookup with mutable state and about 30 lines re-parsing argv, or disabled formatters in 25 files instead of changing one setting. A change raised a preview command’s CPU time from 0.2 seconds to 1.5 seconds, about 7x, and the hand-off didn’t mention it; test timeouts exposed it. A test-author delegate handed back locked tests with four bugs, among them a binary compared as buffers that exhausted the heap and a compile in every test that took 57 seconds.

The fixes that held up:

  • Every run gets a worktree, a contract and uncommitted changes, so Claude reviews before anything lands.
  • Contracts tell Codex to read the repo’s skill files for writing tests, architecting systems and handling errors, since it can’t load Claude Code’s skills directly.
  • Codex gets a fresh, read-only review of its own diff in a separate process, fixes the findings and reruns the scoped checks before it hands back. The reviewer sees the diff and instructions without the implementation conversation.
  • The hand-off has a “Look closer at” section where Codex lists what it is least sure of, so Claude’s review starts there.
  • Test-first work splits in two: one delegate writes failing tests, and the implementer branches from them with those tests locked. A bug found in review needs a regression test in the repository, verified to fail when the fix is reverted.
  • Structure rules became lint errors, including a cognitive complexity limit of 15, no nested ternaries and a maximum parameter count. Codex runs lint itself, so it hits them before Claude does, and a “Code structure” section in AGENTS.md states them up front.
  • The repository’s reviewer prompt records defects that reached Claude: per-invocation cost, misplaced files, module boundaries, test traps and duplicated sources.
  • Contracts forbid mechanisms the acceptance tests don’t need, require measurement before optimization and require an invalidation test for every cache input.

Three of eight units in the next batch needed no changes; the others needed a small refactor or one follow-up. All passed the gate, stayed in scope and included real tests.

What does Claude fix when Codex hands back?

Claude fixes integration and design details that survive Codex’s self-review. In one run, Codex built a second demo-player wrapper beside the existing one, and Claude combined them into a shared component. Another run used calc(100vw - 32px), which overflowed when a scrollbar was present, and Claude switched the width to a container-query unit. Two build tests raced on a shared prerender directory, so Claude moved the build to a global setup that ran once.

Claude reads foreman result first, starting with “Look closer at”, then the diff, including new files and any paths outside the contract’s scope. It makes its edits with its own edit tools, so the repository’s Claude Code hooks run on the refactor. In our runs, Claude Code’s edit hooks didn’t run for Codex’s edits, though the same command guards ran for Codex through Codex hooks. Claude Code command hooks explains that enforcement.

Problems larger than a refactor go back to the same Codex session with foreman followup, so Codex keeps what it already read. Codex also catches mistakes in Claude’s instructions. Two delegates independently noticed a stale library version in their briefs, another caught a wrong claim about which demo a home page opens on, and one found MIT in a license template for an Apache-2.0 project.

Claude commits only after the worktree passes the full gate. It merges each unit with --no-ff, then runs foreman archive, which frees the run name and removes a managed worktree and branch only when the worktree is clean, has no untracked files and its commits are merged.

How much context and time does this use?

These numbers come from 58 completed runs on November 3–5, 2026 that used our earlier shell wrapper around codex exec, not foreman. Each feature or fix run read 4–17 million input tokens and wrote 25–84 thousand output tokens, all in the Codex session. For each of those runs, Claude read a hand-off 4,600 to 20,600 times smaller, plus the diff.

Left dots: Claude hand-off

Right dots: Codex input (including cache)

Log scale: each step to the right is ten times more tokens.

10010k1M100MTokens (log scale)ci-rerun-mergehero-vhshero-readouthero-atmosphere #2hero-atmosphere #1demo-linksdecline-flakeblog-scenariosblog-engine #4blog-engine #3blog-engine #2blog-engine #1
Fig. 4 Codex reads thousands of times more input tokens than Claude reads in each hand-off; the diff Claude also reads is not counted. Source: Codex run logs (events.jsonl and last-message.md) from the shell wrapper foreman replaced, Nov 3-5, 2026; hand-off tokens estimated as characters / 4

The runs used the same model, effort and tier that foreman defaults to, and foreman drives the same Codex agent through its app server, so we expect similar token use but haven’t re-measured it. Codex read 262 million input tokens, 97% cached, and wrote 1.14 million output tokens. The hand-offs totalled about 63 thousand tokens, estimated as characters divided by four. These totals include article drafts as well as code. Input totals count the context Codex re-reads on every turn, so a run’s total can exceed its context window.

Feature and fix runs took 9–32 minutes and issued 120–240 shell commands each; a small one that re-ran CI and merged a pull request took under 4 minutes. Article-drafting runs took 4–8 minutes, reading 1–7.5 million input tokens and writing 8–20 thousand output tokens. A whole job, a blog engine for one product plus ten articles, took 54–78 minutes end to end across 11–12 units, and Opus’s own output across such a session was roughly 100–280 thousand tokens. In the sessions we reviewed, we saw no run write outside its contract’s scope or hit the timeout.

What should you know before you use it?

--write runs Codex with full access to your machine and network and no approval prompts. foreman has no middle setting. The worktree keeps Codex’s file changes apart from your checkout, but it doesn’t restrict what Codex’s commands can reach, so use it on repositories and machines where you’d trust a developer with a shell. Does a git worktree sandbox Codex? explains the difference.

foreman never commits, merges or pushes. It also doesn’t judge the work: a done outcome means the turn ended, not that review passed. Run the repo’s gate yourself before committing.

Don’t delegate everything. Keep design work and shared contracts with the orchestrator. We also keep agent-harness changes there: .claude/, .codex/, git hooks and CI affect how later delegates work, so land those changes before branching the worktrees that depend on them. A few-line edit is usually faster to make than to describe in a contract. If you can’t write the contract’s Acceptance section yet, the task isn’t ready for Codex, and you should keep planning it with Claude.

Try foreman

Run the five setup commands from the quick start, then ask Claude Code to delegate one small task with a clear acceptance check: Use the foreman skill to delegate this task to Codex, then review its work. A first run shows whether the loop fits your repo.

$ npm i -g @steamfield/foreman

foreman is MIT licensed. The foreman site has a recorded session and the full setup, and the source and issue tracker are on GitHub. The package is on npm.