Guide
How to test code written by Codex
OpenAI's Codex will write and run tests when it has a clear command, then keep going until they pass. That is a good start, not a release check. This page is the Codex setup: put the real test commands in AGENTS.md, use a lifecycle hook to run them, review the diff with a fresh pair of eyes, then confirm the tests would fail if the new code were wrong.
The same method works in Claude Code, Cursor and GitHub Copilot. Codex reads AGENTS.md, supports lifecycle hooks, and connects to local MCP servers through its config. Those facts are from OpenAI's Codex docs (custom instructions, hooks, and config basics) as of 23 November 2026.
Put the test commands in AGENTS.md
Codex reads AGENTS.md before it starts work. It layers global guidance from ~/.codex/AGENTS.md (or AGENTS.override.md) with project files from the repository root down to the working directory. Closer files override earlier ones. The /init command can create a starting AGENTS.md. Put the exact test commands there.
## How to check work in this repo
- Typecheck: pnpm tsc --noEmit
- Unit tests: pnpm vitest run
- One file: pnpm vitest run path/to/file.test.ts
- Integration tests need DATABASE_URL (see .env.example)
- Never edit snapshot files to make a test pass. Ask first.Instructions guide the agent. They do not guarantee it ran the right command, or that the tests would catch a fault. For a bug fix, ask Codex to write a failing test, show the failure, then fix the code and show the same test passing, with the commands and output pasted.
Run checks with a lifecycle hook
Codex hooks can run scripts or already-connected MCP tools during the agent loop, including a Stop hook when a chat turn stops, which OpenAI describes as a way to run a custom validation check and enforce standards. Local Codex looks for hooks.json in /etc/codex/, $CODEX_HOME/hooks.json (usually ~/.codex/hooks.json), and, in a trusted project, .codex/hooks.json. You can also declare hooks inline under [hooks] in config.toml.
Two limits from the official hooks docs matter here. Non-managed hooks must be reviewed and trusted before they run (/hooks in the CLI). Matching command hooks for the same event are launched concurrently, so one hook cannot prevent another matching hook from starting. Use a Stop hook to run your typecheck and unit tests, and treat hook trust as part of the setup, not an afterthought.
Review the diff separately
Do not let the same Codex session be the only reader of its own diff. Start a fresh session with only the spec and the patch, or run a pull request reviewer, and ask for bugs rather than style comments.
Prove the tests catch a break
A passing test command still does not prove the tests would fail if the new behavior were wrong. OrangePro is a local MCP server that ranks weak test evidence and can show whether a test catches a break. Codex configures MCP servers in ~/.codex/config.toml, or in a trusted project's .codex/config.toml. The CLI and IDE extension share those layers. Project .codex/ files load only when the project is trusted.
Print the current client snippet with npx -y @orangepro/mcp-server@latest agent --client codex and add it in the Codex MCP settings or config file that command names. You can also inspect connected servers with codex mcp. Mapping, ranking and proof stay on your machine. A green Codex run is not the same as proof that the tests protect the change.
Frequently asked questions
From AGENTS.md. Codex layers ~/.codex/AGENTS.md with project AGENTS.md files from the repo root down to the working directory. Closer files override earlier ones. OpenAI's /init command can create a starting file.
Codex supports a Stop hook for a custom validation check when a turn stops. Official docs also say matching command hooks run concurrently, and non-managed hooks must be trusted before they run. Do not assume one hook can cancel another, and review hooks with /hooks.
Codex reads MCP servers from ~/.codex/config.toml or a trusted project's .codex/config.toml. Run npx -y @orangepro/mcp-server@latest agent --client codex to print the current snippet, then add it in the place that command names.
No for mapping, ranking and proof. Drafting tests with real assertions uses a model provider you choose, with your own key, called directly from your machine.
Try it on your code
Print the Codex MCP snippet and add the local server, then ask for the top unprotected function. Local runs do not upload your source.
npx -y @orangepro/mcp-server@latest agent --client codexBuilt for after merge, before release. It is not a pull request or release gate. Local scans do not upload source.