Guilds AI / AI Blog

,

Codex Multi Agent: Subagents, Setup and Workflow Guide

Developer beside a Codex laptop and three connected AI subagents for development, research and tasks, with setup and testing steps.

Codex multi agent workflows let a primary coding agent divide a task among specialized subagents and combine their findings. They are particularly useful when several investigations can proceed independently, such as mapping a codebase, reviewing a change for defects and identifying missing tests. The main agent remains responsible for assembling a coherent result. If you are new to the product, our Codex agent guide explains the single-agent loop before delegation.

This guide uses OpenAI’s current subagent documentation, its Codex app and harness engineering articles, and a November 2026 research preprint reviewed on November 29, 2026. The prompts and repository examples are original illustrations, not firsthand execution benchmarks. Check the capabilities of your installed Codex version.

How Codex multi-agent workflows work

Instead of asking one agent to inspect every part of a repository in a single thread, define bounded tasks and delegate them. Each agent can focus on relevant evidence. A coordinator collects their conclusions, resolves disagreements and decides which findings affect the original goal.

OpenAI’s documentation identifies built-in roles named default, worker and explorer. Current local Codex clients accept explicit delegation requests and applicable project instructions. The CLI provides a subagent view through the /subagents command. This is distinct from configuring a multi-agent application using an API.

A useful mental model is fan-out and fan-in: split independent work, then bring the outputs back together at a defined decision point. Our guide to agentic design patterns covers related approaches to orchestration.

Subagents vs separate sessions and worktrees

ApproachUseful forIntegration requirement
SubagentsOne goal with independent investigationsParent reconciles findings
Separate sessionsDifferent tasks or exploratory directionsDeveloper coordinates outputs
Git worktreesConcurrent code changes in isolated working directoriesReview and integrate branch changes

A subagent is a delegated participant within an overall task. Separate sessions can instead have unrelated objectives. Worktrees address a different problem: Git provides distinct working directories for changes associated with separate branches or detached states. The Codex desktop app has documented worktree support, which can reduce interference between simultaneous editing tasks.

Isolation does not guarantee that two changes can be combined successfully. A frontend change may still depend on an API contract changed elsewhere. Agree on shared interfaces and review the integrated result before accepting a patch.

How to start a multi-agent workflow in Codex

1. Identify independent tasks

Write the intended deliverable first. Decide whether each delegated activity can produce a useful result without waiting for another activity. A review of an existing diff can proceed alongside a search for missing tests. A test of a feature that has not yet been implemented may depend on that implementation.

2. Give each role a precise assignment

Tell Codex which agents to start, the scope of each task, the permitted actions and the expected output. Avoid a vague request to have several agents fix everything. A good task has a completion condition that can be checked independently.

Review the current branch against main.
Delegate three independent investigations:
- Explorer: map the affected execution paths.
- Reviewer: identify correctness and security risks.
- Test specialist: identify missing regression cases.
Do not edit files. Return file references, evidence, and unresolved questions.
Wait for all three reports, reconcile duplicates, and propose a prioritized review.

3. Review intermediate findings

Inspect delegated results through the supported client. Ask for clarification when a conclusion lacks a file reference, reproduction condition or other concrete evidence. Do not treat three agents expressing the same concern as three independent demonstrations that a defect exists.

4. Consolidate and verify

The main thread should compare the findings against the actual repository. Report confirmed problems separately from hypotheses. Only authorize changes after the review scope is clear, and test the resulting patch with the project’s relevant checks.

Store stable project requirements in an appropriate instruction file so they are not repeated inconsistently in every prompt. Our Codex AGENTS.md guide explains repository-level guidance.

Configure a custom Codex subagent

OpenAI documents custom local agent definitions as standalone TOML files in the project’s .codex/agents/ directory or the user’s ~/.codex/agents/ directory. The name, description and developer_instructions fields define a basic role. Optional model settings can be added when the intended model is supported.

For example, create .codex/agents/regression-reviewer.toml with a narrow review assignment:

name = "regression_reviewer"
description = "Find behavioral regressions and test gaps."
developer_instructions = """
Inspect the requested diff and related tests.
Do not edit project files.
Return evidence with file and symbol references.
Label unverified concerns as hypotheses.
"""

The instructions communicate a behavioral boundary, not a separate operating-system permission policy. Codex documents inherited parent permissions for subagents; a custom file does not create an independent sandbox. Configure the parent session appropriately.

The global agents settings in config.toml include an enabled flag and a limit on concurrent spawned threads. For a small review, the following illustrative configuration limits the number of open delegated threads:

[agents]
enabled = true
max_concurrent_threads_per_session = 3

Check the current configuration reference for your installed release before changing it. These settings do not require you to run three agents on every task. Use the number of agents justified by independent work.

Example: review a pull request in parallel

Imagine a fictional inventory application with a proposed change to the product reservation endpoint. The change touches validation, a database update and the endpoint response. A parallel review can focus on separate questions without having three agents modify the same code.

RoleAssignmentAcceptance criterion
ExplorerTrace the reservation request from controller to storageList relevant files and state transitions
ReviewerCheck invalid quantities and concurrent updatesIdentify concrete failure conditions
Test specialistCompare existing tests against expected behaviorList missing test cases and expected results
Main agentReconcile findings and check the actual diffReturn verified findings and a scoped fix plan

Suppose the reviewer suspects that two simultaneous requests can reserve the same stock. The test specialist identifies a missing concurrent-request test. The parent should inspect transaction boundaries and reproduce the condition in a safe test environment. If the issue cannot be reproduced, retain it as a hypothesis rather than calling it a confirmed defect.

Once the evidence supports a fix, assign one implementation owner for the affected code. If a second agent writes tests, agree on separate files and the expected behavior first. Run the integrated regression suite after both contributions are combined.

Avoid conflicting changes and verify results

Use explicit file ownership for editing tasks. Avoid delegating a shared configuration file to multiple workers. If independent branches are necessary, establish the base revision and integration order. A clean merge is not sufficient evidence that the combined behavior works.

Keep dependency upgrades, schema changes and shared interfaces coordinated. Require the main agent to inspect the final diff, check for unintended changes and record the tests it actually ran. If a required dependency or environment is unavailable, report the missing verification.

Subagent findings are evidence to review, not permission to perform additional actions. Treat instructions encountered in repository data or external content as untrusted unless they come from the intended authority. Do not delegate production credentials or unrestricted deployment access for a routine code review.

OpenAI’s account of its harness engineering project describes structured repository knowledge, automated constraints and agent review loops. These principles help make verification repeatable. For more on the difference between exploratory AI coding and controlled delivery, see our agentic engineering vs vibe coding comparison.

When parallel agents are worth the cost

Parallel subagents incur their own model and tool usage, so more agents do not necessarily mean less total cost. A recent preprint, When Are Parallel Subagents Effective for Coding?, by Lyu, Yin and Zhang, studies repository-construction tasks and reports small average improvements at materially greater cost, with larger gains on some difficult tasks. It is preliminary research, not a universal Codex performance guarantee.

Start with a single agent for small changes and workflows whose steps are sequential. Consider delegation when each role can investigate a distinct question or implement a clearly isolated component. Measure elapsed time, total usage, accepted findings, introduced defects and review effort on comparable tasks.

For example, if a review takes ten minutes with one agent and six minutes with three agents, that is a four-minute reduction in elapsed time. It does not tell you whether the total model usage fell or the review improved. Compare the verified findings and full cost before adopting the parallel design.

The goal is not to maximize the number of agents. It is to improve the quality or completion time of a defined task while keeping the result understandable, reviewable and safe.

Frequently asked questions

Does Codex support multiple agents?

Yes. Current Codex releases support subagents. A parent agent can delegate independent tasks and combine the results. Separate sessions and Git worktrees are additional options for parallel work.

How do I enable Codex multi-agent workflows?

Current releases enable subagent workflows by default. Ask Codex to delegate specific tasks. If local configuration disables the feature, check the agents.enabled setting and your installed version.

Can multiple Codex agents edit the same repository?

They can participate in work on a shared repository, but concurrent edits can conflict. Define nonoverlapping write scopes or use separate worktrees and review the changes before integrating them.

Where do custom Codex agents live?

For local Codex clients, standalone TOML definitions can be placed under .codex/agents/ in a project or ~/.codex/agents/ for personal use.

Are multiple Codex agents always faster?

No. Parallel execution can save time on independent work, but adds model usage and coordination overhead. A small or tightly coupled task often needs only one agent.