Overview
Run the main Codex thread on a stronger model to plan a change, and define a custom Codex agent on a lighter, lower-cost model that carries out each clearly scoped step as a subagent.
Problem or Objective
- How do teams design the context, tools and memory of their own AI agents?
- Which agents build a non-trivial feature with you?
More in Coding and Code Review
AI Agents and Models
Tools and Integrations
- Tools
- Codex
- Prerequisites
- A current local Codex client (CLI or IDE) signed in with a plan that offers both a stronger and a lighter model, and a project with tests.
How It Works
In your project, create a custom agent file under .codex/agents/, for example executor.toml, with a name, a description and developer instructions: follow the plan step exactly, touch only the files named, run the tests and report what changed and anything unclear instead of guessing. Set its model to a lighter, lower-cost model; the subagents guide suggests one for fast, narrowly scoped, repeatable work. Keep your main session on a stronger model for planning. Ask Codex to write a numbered plan for the change, with the files, the expected behaviour and the test for each step, and read the plan yourself. Then ask it to spawn the executor for each step, wait for the results and check every summary against the plan. Review the combined diff and run the full test suite before you commit. If the executor keeps getting a step wrong, move that step back to the main thread or raise its reasoning effort.
Implementation Workflow
Steps assembled from the agents, tools and prompt of this entry. Adapt them to your own setup.
- Choose the agentSet up Codex CLI.
- Connect the toolsConnect the tools this workflow relies on: Codex.
- Check the prerequisitesA current local Codex client (CLI or IDE) signed in with a plan that offers both a stronger and a lighter model, and a project with tests.
- Gather your detailsCollect what the prompt asks for: The change you want, Name of your custom executor agent, Command that runs the tests.
- Run the starter promptPaste the starter prompt below into Codex CLI and adapt it to your case.
- Check against the documentationCompare what you get with the documentation at developers.openai.com before you rely on it.
Practical Starter Prompt: Plan, then delegate each step
Fill the fields to adapt the prompt. Empty fields stay as visible [placeholders].
Plan this change: [The change you want]. Write a numbered plan where each step names the files to edit, the expected behaviour and the test that proves it. Show me the plan and wait for my approval. Then, for each step in order, spawn the [Name of your custom executor agent] agent with only that step and the relevant files, wait for its result, and check its summary and diff against the plan. If a step fails twice, do it yourself. At the end, run [Command that runs the tests] and give me a summary of every change. Do not commit or push.Run this in a Codex session on your stronger model, with the executor defined in .codex/agents/ on a lighter model. Approve the plan before delegation starts, and review the diff and test results yourself before you commit.
Expected Results and Benefits
This is a suggested workflow, not a reported result. The points below are what the cited documentation says the tools can do.
This is a suggested workflow, not a reported outcome. The Codex subagents guide documents custom agents defined as TOML files that can set their own model and reasoning effort, recommends a lighter model for lower-cost work, and explains that a model set in the file takes precedence. It does not measure savings or quality for a planner and executor split, so both are untested here.
Limitations and Considerations
Subagents consume more tokens than a single-agent run because each one does its own model and tool work, so a cheaper executor saves money only when the steps are small and clear. Custom agents inherit the parent session's permissions and sandbox, so set those on the main session. Which models you can pick depends on your plan and client; check the model picker. Review the full diff and tests yourself before committing, since a summary from a subagent is not proof that the step is correct. Results depend on your setup and were not independently reproduced by Top 200 Repos.
GitHub Repositories
AI Agent Repository
Source code of the agent that does the work.
Official Website
The official site of the main tool or project in this use case.
Visit Website (opens in a new tab)developers.openai.com
Related Videos
About openai/codex
Meet the New Codex CLI (opens in a new tab)
Published by the project’s official channel.
Watch on YouTube (opens in a new tab)Independent creators. Listing a video implies no endorsement, sponsorship or partnership.
Sources
- Subagents | ChatGPT Learn (opens in a new tab)
Project documentation · developers.openai.com · Undated · Source checked 25 Nov 2026, 12:11 UTC
What this source supports
- Each file defines one custom agent.
- If a custom agent file sets model or model_reasoning_effort , the value in the file takes precedence.
- Use gpt-6-luna for lighter, lower-cost work.
- Subagent workflows consume more tokens than comparable single-agent runs because each subagent does its own model and tool work.
- openai/codex README (opens in a new tab)
Project documentation · github.com · Undated · Source checked 25 Nov 2026, 11:59 UTC
What this source supports
- Codex CLI is a coding agent from OpenAI that runs locally on your computer.
