Claude Code can write a change and then praise it in the same breath. That is not malice. The model that made a choice tends to defend that choice, because the reasoning that produced the code is still sitting in its context. An audit breaks that loop. A second model reads the diff fresh, with no stake in the work and no memory of why each line seemed like a good idea at the time.
This tutorial sets up two layers. The first stays inside Claude Code: a custom subagent, meaning a separate assistant that Claude Code starts for one task in its own context window, pinned to a different model and limited to tools that read. The second layer leaves the family entirely. The Codex CLI from OpenAI reviews the same diff without the power to change a file. The facts and commands below follow the Claude Code subagent documentation and the Codex documentation for work without interaction, checked on November 29, 2026. This article does not claim a live run of its own.
What You Will Build or Learn
You will build a reviewer that lives in your project and travels with the repo. Any teammate who clones the project gets the same auditor with the same model choice and the same limits. You will also build a short external audit you can run from the terminal before a commit.
The point is not volume. Two models saying the code looks fine proves little. The point is independence: a fresh context, a different model, and tools that cannot quietly fix the evidence while reviewing it. For context on keeping agent work bounded, see our guide to stopping Claude Code from leaking secrets to GitHub and our tutorial on running Claude Code, Codex and OpenCode together.
The diff is the evidence. The auditor reads the diff, not the story about the diff. Illustration: Dirty Static
Before You Begin
Work on a branch and commit or stash anything you cannot afford to lose. The auditor in this tutorial cannot edit files, but the main Claude Code session still can, and a clean git status makes the diff honest. Run git status first and read what it says.
Step 1: Check Both Tools
Action: confirm that Claude Code, Git and Codex are installed and signed in.
claude --version
git --version
codex --version
Expected result: each command prints a version. If Codex is missing, finish Steps 2 to 4 now and add the external audit later. The first layer needs Claude Code alone.
Step 2: Create the Auditor Subagent
Action: create the folder for project subagents, then create the auditor file inside it. Project subagents live in .claude/agents/ and Claude Code loads them at the start of a session.
mkdir -p .claude/agents
Expected result: the folder exists. Now create .claude/agents/auditor.md with this exact frontmatter and prompt. Only the name and description fields are required by Claude Code. The rest here do the real work: the model field pins the auditor to a different model than your main session, and the tools list gives it reading tools only, while the disallowed list takes editing tools away even if the tool list later grows.
---
name: auditor
description: Audits recent code changes for bugs, security flaws and missing tests. Use after Claude Code finishes a change and before any commit.
tools: Read, Grep, Glob, Bash
disallowedTools: Write, Edit
model: opus
---
You are an auditor. You did not write this code and you owe it nothing.
Read the git diff first. Then read the full files around each change.
Report findings in this order: bugs that change behaviour, security
flaws, missing tests, then style notes. For each finding give the file,
the line, what goes wrong, and a concrete case that triggers it.
If you find nothing in a class, say so in one line. Do not praise the
code. Do not suggest edits beyond naming the fix in one sentence.
Expected result: the file sits in the project where Claude Code can find it. If your main session already runs on the model named here, change the model value to a different one, such as sonnet or haiku. An auditor on the same model still gains a fresh context, but it loses the value of a different set of weights. The documentation lists sonnet, opus, haiku, fable, a full model ID, and inherit as model values.
Step 3: Run the First Audit
Action: finish a small change with your main session, leave it uncommitted, then ask for the auditor by name.
Use the auditor subagent to audit the uncommitted changes in this repo.
Expected result: Claude Code delegates to the auditor, the auditor works in its own context window, and the main session gets back a summary of findings. The auditor can run git diff through Bash and read files, but any attempt to write or edit fails because those tools are not in its hands.
Step 4: Judge the Report Like an Editor
Action: take each finding and test it yourself before you change a line. Ask three questions. Does the named file and line hold what the finding claims? Can you state the input or action that triggers the fault? Does the fault matter for this project, or is it a generic worry?
Expected result: some findings die under those questions, and that is normal. A second model produces claims, not proof. Keep the findings that survive, fix those, and run the auditor once more on the new diff. Stop after two rounds on the same change. A third round mostly trades one style opinion for another.
A finding earns a fix when you can reproduce the fault it names. Illustration: Dirty Static
Step 5: Add the External Audit With Codex
Action: save the diff to a file outside the repo, then hand that diff to Codex with a sandbox that can only read. Passing the sandbox on the command line matters. Recent Codex versions can take a default from your own config or from a project trust decision, so a script that omits the flag can run with more power than you meant to give it.
git diff HEAD > /tmp/audit-diff.txt
codex exec --sandbox read-only -o /tmp/audit-report.md "Audit the diff in /tmp/audit-diff.txt for bugs, security flaws and missing tests. For each finding give the file, the line, and a concrete case that triggers it. Do not edit any file."
Expected result: Codex works without interaction, prints progress to the terminal, and writes its final report to /tmp/audit-report.md. The command expects a Git repository, so run it from inside your project. Open the report and put it through the same three questions from Step 4.
Step 6: Make the Audit a Habit, Not a Ceremony
Action: add one line to your project notes for Claude, in CLAUDE.md, telling the main session when to call the auditor.
After finishing any change that touches more than one file, run the
auditor subagent on the diff before reporting the work as done.
Expected result: the main session starts offering or running the audit at the right moment instead of waiting for you to remember. Keep the trigger narrow. An audit on every tiny edit costs time and tokens and teaches you to ignore the report.
Verification
Start a fresh Claude Code session in the project and ask it to list the subagents it can use. The auditor should appear. Then make a small change with a known flaw, such as a function that divides by a value that can be zero, and run the auditor. A working setup names the flaw, the file and a case that triggers it, and the working tree stays exactly as the main session left it, because the auditor holds no editing tools.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| The auditor never runs | The description does not match the request | Name the auditor in your prompt, and sharpen the description |
| The auditor uses the wrong model | The model field is missing or set to inherit | Set the model field to a named model and start a new session |
| The auditor edits files | Write or Edit reached its tool list | Remove both from tools and list both in disallowedTools |
| Codex edits files during the audit | The sandbox flag was omitted and a config default applied | Pass the sandbox flag on every run, as in Step 5 |
| Findings sound confident but wrong | The auditor read the diff without the surrounding files | Tell it to read the full files around each change, as the prompt in Step 2 does |
| The report repeats the main session | Both layers run the same model | Change one layer to a different model or a different provider |
Next Steps
Once the habit holds, audit plans as well as code. Send the auditor a design note before the main session builds from it, and let it hunt for gaps while gaps are still cheap. Teams can also wire the Codex step into a pull request flow later, but earn trust in the local version first. A report you read beats a pipeline you ignore.
Sources
- Anthropic, Claude Code documentation, Create custom subagents, at code.claude.com/docs/en/sub-agents. Covers subagent files, scope, the model field, tool limits and delegation.
- OpenAI, Codex documentation and guides on work without interaction, at developers.openai.com. Covers
codex exec, sandbox choices and writing the final message to a file. - Illustrations: Dirty Static.
END OF TRANSMISSION
Stay curious. Question everything.


