Developer workflows · Advanced

How to Connect Claude Code and Codex for Automated Checks and Second Opinions

Как связать Claude Code и Codex для автоматизации проверок и вторых мнений
Temporary fallback cover; replace in editorial pass.

Use one coding agent to do the work and another to inspect the result, while keeping the hand-off reproducible, local, and explicit.

20 min read Updated 26 November 2026 English

The practical problem is not whether two coding agents can generate useful text. It is how to make them cooperate without repeatedly copying a plan, an image path, or a diff from one terminal into another.

This guide connects Claude Code and Codex through a small shell wrapper. Claude Code remains the primary operator. It writes a request file containing the relevant context, calls the Codex CLI, and reads the resulting report. The same mechanism can check a screenshot, review an implementation plan, or challenge a technical decision.

The result is a controlled automated check, not an autonomous approval system. The second agent produces evidence and questions; a human still decides whether the change is safe to merge.

What the finished workflow looks like

The hand-off has four explicit artifacts:

  1. A request file with the question and bounded context.
  2. Optional local inputs, such as an image, plan, or diff.
  3. A Codex report written to a known output path.
  4. A short summary returned to Claude Code.
Claude Code
    │
    ├── writes /tmp/agent-review/request.md
    ├── selects local files
    └── invokes review-codex.sh
              │
              └── codex exec ...
                        │
                        └── writes /tmp/agent-review/report.md
    │
    └── reads the report and decides what to do next

The wrapper is intentionally boring. It gives the second agent a stable interface, avoids shell quoting problems in long prompts, and makes it easier to audit what was sent.

Prerequisites and assumptions

This article assumes:

  • Both command-line tools are already installed and authenticated in the environment where the wrapper runs.
  • The shell can execute the Codex command.
  • The files being reviewed are local and readable by that process.
  • You are comfortable checking the installed command syntax with --help.

Command names and flags can vary by release. The examples below use the common codex exec pattern. Before adopting them, run:

command -v codex
codex --help
codex exec --help

If your installed version exposes different flags, preserve the design but adjust the invocation. This article does not claim that the commands were executed in your environment.

Step 1: Create a review directory

Use a project-local directory when the review should be retained with the project, or a temporary directory when it should disappear after the session. The following example keeps review material outside the repository:

mkdir -p /tmp/agent-review
chmod 700 /tmp/agent-review

Do not place API keys, session tokens, private customer data, or unredacted production logs in this directory. Treat every request file as input that may be sent to an external model service.

Step 2: Write a narrow request

A second opinion is most useful when the question is falsifiable. “Review this” is weak. “Find contradictions between the stated constraints and the proposed retry behavior” is actionable.

Create a request file like this:

cat > /tmp/agent-review/request.md <<'EOF'
You are reviewing work produced by another coding agent.

Goal:
Check whether the proposed implementation is internally consistent and
whether the stated verification plan would detect the important failures.

Review rules:
- Do not modify files.
- Do not invent facts about the repository.
- Separate observations, risks, and assumptions.
- If evidence is missing, say exactly what is missing.
- End with: PASS, NEEDS_REVIEW, or INCONCLUSIVE.

Question:
Does the attached plan adequately cover image validation, error handling,
and rollback behavior?

Relevant context:
- The primary agent is preparing a change for local review.
- The reviewer should inspect only the files explicitly listed below.
EOF

The heredoc is quoted so that the shell does not expand variables inside the request. If the prompt contains sensitive data, redact it before writing the file.

Step 3: Build the Codex wrapper

Create a wrapper named review-codex.sh somewhere on your executable path, or keep it in a project’s scripts/ directory.

#!/usr/bin/env bash
set -euo pipefail

review_dir="${1:?usage: review-codex.sh REQUEST_FILE [INPUT_FILE ...]}"
request_file="$review_dir"
shift

output_file="${CODEX_REVIEW_OUTPUT:-/tmp/agent-review/report.md}"

if [[ ! -f "$request_file" ]]; then
  printf 'Request file not found: %s\n' "$request_file" >&2
  exit 2
fi

{
  printf '%s\n\n' 'The following is the review request:'
  cat "$request_file"

  if (($# > 0)); then
    printf '\n\n%s\n' 'Explicitly listed local inputs:'
    for input_file in "$@"; do
      if [[ ! -f "$input_file" ]]; then
        printf 'Input file not found: %s\n' "$input_file" >&2
        exit 2
      fi
      printf '\n--- FILE: %s ---\n' "$input_file"
      cat "$input_file"
    done
  fi
} > /tmp/agent-review/codex-prompt.txt

codex exec \
  --full-auto \
  "$(cat /tmp/agent-review/codex-prompt.txt)" \
  > "$output_file"

printf '%s\n' "$output_file"

Make it executable:

chmod 700 ./scripts/review-codex.sh

The wrapper treats listed files as data and passes their contents in one prompt. This is suitable for text plans, decision records, and diffs. It is not sufficient for visual inspection: an image must be supplied through a supported image-input mechanism, or converted into a form the installed Codex interface can actually inspect.

If your Codex version does not support --full-auto, remove that flag or replace it with the documented non-interactive option from codex exec --help. For a review-only wrapper, a mode that prevents file changes is preferable.

Step 4: Call the wrapper from Claude Code

In Claude Code, ask the primary agent to create the request and invoke the wrapper. A useful instruction is:

Prepare a Codex review of the current implementation plan.

1. Write the review request to /tmp/agent-review/request.md.
2. Include only the plan and the specific question.
3. Call ./scripts/review-codex.sh with that request file.
4. Read the returned report.
5. Summarize observations separately from assumptions.
6. Do not change code until I approve the review findings.

The important part is the contract: Claude Code owns the preparation and interpretation, while the wrapper owns the second-agent call. This prevents a vague “ask another model” instruction from becoming an uncontrolled loop.

You can also make the call explicit in a shell step:

report_path="$(
  ./scripts/review-codex.sh /tmp/agent-review/request.md
)"

sed -n '1,240p' "$report_path"

Review case A: a technical plan

For a plan review, include the plan, constraints, affected interfaces, and proposed verification. Do not include the entire repository unless the question requires it.

./scripts/review-codex.sh \
  /tmp/agent-review/request.md \
  docs/implementation-plan.md \
  docs/decision-record.md

Ask the reviewer to answer concrete questions:

  • Are the preconditions and postconditions explicit?
  • Does the rollback path cover partial failure?
  • Are retries idempotent?
  • Does the test plan exercise the most dangerous branch?
  • Which claim depends on an assumption rather than evidence?

A useful report should point to the supplied material and say when it cannot verify a claim. “The plan mentions retries but does not define an idempotency key” is stronger than a general score.

Review case B: a technical decision

For architecture or implementation decisions, use a decision record with alternatives and constraints. The review request should ask for counterexamples, not a replacement design by default.

cat > /tmp/agent-review/decision-request.md <<'EOF'
Evaluate this technical decision.

Return:
1. The strongest argument in favor.
2. The strongest argument against.
3. A failure mode that the decision record does not address.
4. A condition under which the decision should be revisited.
5. One small verification experiment.

Do not select a winner unless the supplied evidence supports one.
EOF

./scripts/review-codex.sh \
  /tmp/agent-review/decision-request.md \
  docs/decision-record.md

This turns the second model into an adversarial reader. It does not make the model an authority, and it does not remove the need to validate the proposed experiment.

Review case C: an image or screenshot

Image review needs a separate handling decision. A path such as screenshots/home.png is meaningful to the local shell, but it does not automatically give a model visual access to the pixels.

First establish what the installed Codex interface accepts. Check its help output and local documentation for an image-input option. If it supports a path directly, pass the image using that documented mechanism. If it requires an attachment or a different input format, use that mechanism instead.

A review request can still be prepared consistently:

cat > /tmp/agent-review/image-request.md <<'EOF'
Inspect the supplied screenshot as a visual QA review.

Check:
- content clipping at the viewport edges
- unreadable text or insufficient contrast
- inconsistent spacing and alignment
- missing focus, loading, empty, or error states
- visual differences from the stated acceptance criteria

Report each finding with:
- severity
- visible evidence
- affected area
- suggested next check

If the image is unavailable or cannot be inspected, say so.
EOF

Do not claim that an image was checked merely because its filename appeared in a prompt. The verification is successful only when the reviewer confirms that it received and inspected the image, or when you can otherwise establish that the visual input was available.

Make the hand-off safer

Keep the context boundary explicit

List every file sent to the reviewer. Avoid commands such as find . -type f -exec cat {} \;; they can expose secrets, generated files, and irrelevant context.

Use a clean output path

Set a per-review output path when several checks can run concurrently:

CODEX_REVIEW_OUTPUT="/tmp/agent-review/plan-$(date +%s).md" \
  ./scripts/review-codex.sh /tmp/agent-review/request.md \
  docs/implementation-plan.md

For reproducibility, record the request file, input file list, command version, and report path. Do not record authentication tokens or private prompts in shared logs.

Separate review from execution

The reviewer should normally be read-only. If it recommends a code change, Claude Code can inspect the recommendation and make the change under a separate approval step. Avoid giving a second opinion permission to edit the same working tree while the primary agent is still reasoning about the result.

Defend against instructions inside inputs

Plans, source files, screenshots, and logs may contain text that looks like instructions. Treat those files as untrusted data. The wrapper’s request should state that instructions found inside reviewed material are evidence to analyze, not commands to execute. This is a basic defense against prompt injection.

Verification checklist

Run these checks before relying on the setup:

test -x ./scripts/review-codex.sh
test -f /tmp/agent-review/request.md
command -v codex
codex exec --help

Then perform a harmless smoke test with a deliberately small request:

cat > /tmp/agent-review/smoke.md <<'EOF'
Return exactly:
SMOKE_OK

Do not inspect files or make changes.
EOF

CODEX_REVIEW_OUTPUT=/tmp/agent-review/smoke-report.md \
  ./scripts/review-codex.sh /tmp/agent-review/smoke.md

grep -Fx 'SMOKE_OK' /tmp/agent-review/smoke-report.md

This verifies the local wrapper contract only: the request can be read, the command can be invoked, and output can be written. It does not verify the quality of a model’s review, visual understanding, account permissions, or production suitability.

Failure cases and fixes

codex: command not found

The process running Claude Code cannot see the same executable path as your interactive shell. Check command -v codex in that process and use an absolute path only after verifying it. Avoid silently installing software from inside the review wrapper.

The wrapper hangs waiting for input

The selected command may be interactive, or it may require a different non-interactive flag. Compare the invocation with codex exec --help. A review automation path must fail clearly when it cannot run unattended.

The report is empty or contains only a generic answer

Check that the request file exists, that its contents are included, and that the listed inputs are readable. Narrow the question and require evidence references. A second model cannot recover context that was never sent.

An image review says the image is unavailable

A local path alone is not proof of visual access. Use the image-input feature supported by your installed client, or mark the result as inconclusive.

The reviewer proposes changes to files

Remove write permissions from the review workflow, use a read-only mode if available, and keep the report separate from the working tree. A review and an implementation should be distinct operations.

Private data appears in the report

Stop the workflow, remove the sensitive material from subsequent prompts, and review where the request and output are retained. Do not add credentials to “make the integration work.”

Limitations

This pattern coordinates two command-line clients; it does not create shared memory between them. Each invocation sees only the context you provide. It also does not guarantee that the agents will disagree, detect a defect, or understand a visual input correctly.

Long prompts increase cost and reduce attention. A compact evidence packet is usually better than a repository dump. Conversely, an overly small packet can make the conclusion meaningless. The correct boundary is the smallest set of files that can support or falsify the question.

Finally, a model-generated PASS is not a test result. Treat it as a review observation that still needs deterministic checks, human judgment, or both.

Conclusion

The reliable way to connect Claude Code and Codex is to make the hand-off explicit: write a narrow request, list local inputs, invoke the second CLI through a small wrapper, save the report, and inspect its evidence. The same interface supports plan reviews, architectural second opinions, and image checks, while keeping secrets and execution authority under control.

For related workflows, continue with the guides or look up unfamiliar terms in the glossary.

We publish what works for us—and implement the same solutions for your business. We design AI automation, Telegram bots, chats, and AI agents for real-world processes. Discuss your project →