Codex · Part 6

Codex — Part 6 — Subagents in Codex

Codex can spawn subagents that run in parallel threads and report back a consolidated summary, which keeps a deep investigation from flooding your main session with intermediate noise.

Quick idea: A subagent does a side task on its own thread and hands your main session only the result, not every intermediate file it read to get there.
explorer

Built-in, read-heavy exploration agent, the closest match to Claude Code’s Explore subagent.

worker

Built-in, execution-focused agent for implementation and fixes.

/agent

Switches between active agent threads and lets you inspect ongoing work.

Introduction

Part 5 covered packaging a repeatable procedure as a Skill. This post covers a related but different problem, the same one the Claude Code series raised in its own Part 6: a task worth doing, but whose intermediate work you have no reason to keep looking at afterward. Codex’s answer is subagents, run in parallel threads, with results consolidated back into your main conversation.

What Is a Subagent?

A subagent is a delegated agent Codex spawns to handle a specific task independently. Subagents run in parallel, letting the main thread stay focused on decisions while specialised agents handle exploration, testing, or analysis. Codex waits for the results it asked for, then returns a consolidated summary, keeping the noisy intermediate output on the subagent’s own thread.

Built-in Agents

Agent Purpose
defaultGeneral-purpose fallback
workerExecution-focused, for implementation and fixes
explorerRead-heavy codebase exploration

Spawning a Subagent

Subagents currently spawn when you ask directly, or when your AGENTS.md or a skill’s instructions request it. Structure the request so the work is genuinely separable.

Review this branch with parallel subagents. Spawn one subagent for
security risks, one for test gaps, and one for maintainability. Wait
for all three, then summarize findings by category with file references.

Use /agent inside a session to switch between active threads and inspect what each one is doing.

Key point: Subagents spawn only when explicitly requested, either by you or by instructions in AGENTS.md or a skill. Codex does not decide on its own to fan a task out in the background.

Creating a Custom Subagent

Custom subagents are standalone TOML files, saved to a specific location depending on scope.

Scope Location (Windows)
Project.codex\agents\<name>.toml
Personal%USERPROFILE%\.codex\agents\<name>.toml

Each file requires name, description, and developer_instructions. sandbox_mode can restrict what the agent is allowed to do, the same idea as restricting tools on a Claude Code subagent.

Following on from the AGENTS.md example in Part 4, here is a read-only agent that audits PowerShell scripts against that same quality baseline.

# Save to .codex\agents\script-auditor.toml

name = "script-auditor"
description = "Reviews PowerShell scripts for quality baseline violations: missing StrictMode, aliases, untyped parameters. Use after writing or updating a script, or when asked to audit the scripts folder."
model_reasoning_effort = "medium"
sandbox_mode = "read-only"
developer_instructions = """
You are a PowerShell quality auditor. For each script you review, check for:
- Set-StrictMode -Version Latest present
- No aliases such as ? or % in place of full cmdlet names
- Typed parameters with validation attributes where appropriate
- Comment-based help header present

Report findings as a short list per file: what was checked, what passed,
and what needs fixing. Do not edit files yourself.
"""
Important: Setting sandbox_mode = "read-only" means this agent physically cannot edit a file, even if asked to. That is a real constraint enforced by Codex, not just an instruction it might ignore.

When It Is Worth Delegating

Codex’s own guidance draws a clear line: subagents excel at read-heavy work, exploring a codebase, mapping test coverage, triaging logs, summarising documents. They are riskier for write-heavy work, since multiple agents editing files at once create conflicts and coordination overhead rather than saving time.

Practical rule: Reach for a subagent for exploration, triage, and analysis. Be more careful handing out simultaneous file edits, and remember each subagent does its own model and tool work, so a delegated run costs more tokens than doing the same thing on one thread.

Controlling Parallelism

Two settings under [agents] in config.toml control how far delegation is allowed to go.

# %USERPROFILE%\.codex\config.toml
[agents]
max_threads = 6   # concurrent agent threads, default 6
max_depth = 1      # nesting depth, default 1: a child can spawn, a grandchild cannot

The default max_depth of 1 lets the root thread spawn direct children but stops a spawned agent from spawning further agents of its own, a sensible default before you have a feel for how much parallel work actually helps on your machine.

Final Thoughts

Subagents in Codex and Claude Code solve the same problem, keeping disposable intermediate work off your main thread, with different mechanics: explicit parallel spawning with a thread limit in Codex, versus a single delegated worker returning a summary in Claude Code. Both are about protecting the conversation you are actually trying to have, not about making any single task smarter.

Start with the built-in explorer agent for anything read-only, and only reach for a custom TOML agent once you notice yourself asking for the same kind of audit or research more than once.

Key takeaway: Delegate read-heavy work you will not need to look at step by step. Restrict a custom agent’s sandbox_mode to read-only where it belongs, that restriction is enforced, not just requested, and remember parallel agents cost more tokens than one thread doing the same work in sequence.
Next in this series

Next, we cover approval modes, sandboxing, and config.toml: how to control what Codex is allowed to do without asking, and the safety model underneath it.