Codex Subagents
Subagents are an advanced Codex feature that lets you break large tasks into smaller parts and process them in parallel or sequentially. This section details how to configure and use subagents.
What Are Subagents?
Subagents are auxiliary agents that Codex can invoke in parallel to handle different parts of a complex task. By configuring subagents, you can:
- Break large tasks into manageable parts
- Process multiple independent tasks in parallel
- Configure specialized agents for different types of tasks
- Improve efficiency when working on large projects
Subagents are especially suited to scenarios that require working on multiple files or multiple independent tasks simultaneously.

Configure subagents
Basic configuration
Configure subagents
Enable Multi-Agent Functionality
[features]
multi_agent = true
Configure Agent Parameters
[agents]
Maximum Number of Parallel Threads
max_threads = 6
Maximum nesting depth
max_depth = 1
Maximum Job Runtime (seconds)
job_max_runtime_seconds = 1800
Custom Agent Roles
You can define custom agent roles in the configuration:
Define an Agent Role
Define a code review agent
[agents.reviewer]
description = "Focused on code review and quality issues"
nickname_candidates = ["Reviewer", "CodeChecker", "QualityBot"]
Can point to a configuration file
config_file = "agents/reviewer.toml"
Using Subagents
Manually Invoke Subagents
In Codex, you can invoke subagents in the following ways:
Invoke a Subagent
Mention a Subagent with @
@
reviewer reviews src
/
auth.py file
Use the /agents Command
/
agents run reviewer
--task
"Review all test files"
Automatically Using Subagents
Codex can automatically choose to use subagents based on the task. For example, for a large refactoring task, Codex may automatically launch multiple subagents to handle different modules.
How Subagents Work
Parallel processing
When a task can be broken into independent parts, subagents can work in parallel:
任务:审查整个代码库
├─ 子代理 1:审查 src/auth/ 目录
├─ 子代理 2:审查 src/api/ 目录
├─ 子代理 3:审查 src/utils/ 目录
└─ 主代理:汇总结果
Sequential Processing
When tasks have dependencies, subagents work sequentially:
任务:实现新功能
└─ 子代理 1:创建数据模型
└─ 子代理 2:创建 API 端点
└─ 子代理 3:编写测试
Nesting Depth
The max_depth setting in the configuration controls how many levels agents can be nested:
- Depth 0: root session
- Depth 1: direct subagents
- Depth 2: subagents of subagents
It is recommended to keep max_depth at 1 or 2; too much nesting increases complexity and cost.
Tool call
Subagents can use all of Codex's standard tools:
- Read and edit files
- Execute the command
- Using skills
- Invoke MCP servers
Result summary
The main agent is responsible for aggregating the results of all subagents and providing a unified output.
Agent Role Configuration
Create a Custom Agent Role
Create an Agent Role Configuration File
agents/tester.toml
description = "Focused on writing unit and integration tests"
nickname_candidates = ["Tester", "TestBot", "QABot"]
[behavior]
Agent Behavior Configuration
test_framework = "pytest" # preferred test framework
include_coverage = true # requires inclusion of a coverage report
Reference in the Main Configuration
Reference the Agent Configuration
[agents.tester]
config_file = "agents/tester.toml"
Monitoring Subagents
View Active Agents
View Active Agents
View in Codex
/
agents status
View Detailed Information
/
agents list
Agent Output
Codex displays the output of each subagent and aggregates the results in the main interface.
A progress indicator is shown while subagents run, keeping you informed of the overall task status.
Best Practices
Task decomposition
- Break large tasks into independent subtasks
- Ensure there are no strong dependencies between subtasks (when they can run in parallel)
- Define clear inputs and outputs for each subtask
Configuration Optimization
- Adjust max_threads according to task complexity
- Configure specialized agent roles for different types of tasks
- Set a reasonable job_max_runtime_seconds to avoid long-running tasks
Monitoring and debugging
- Regularly check subagent output
- Use /agents status to understand overall progress
- Cancel specific subagents when necessary
Subagents are an advanced feature; it is recommended to familiarize yourself with Codex's basic operations before using them.
Common questions
Q: What is the difference between subagents and skills?
Subagents are independent AI agents that can perform complex, multi-step tasks. Skills are predefined workflows focused on specific types of tasks.
Q: What is the maximum number of subagents that can run simultaneously?
Configured via max_threads, the default is 6. The actual number available depends on your subscription plan.
Q: Can subagents access my files?
Yes, subagents can read and modify files, subject to sandbox and security policy restrictions.
Q: How do I debug issues with subagents?
Use /agents status to view agent status and check their output logs to locate problems.