What are subagents and how do you use them in five coding tools?
In Claude Code, Codex, Cursor, Gemini CLI and Copilot, a subagent works in its own context and reports back. Setup, limits and best practices, from the docs.
Summary. A subagent is a helper that the main agent hands a task to and that works in a separate context: the files it reads and its intermediate output stay with it, and the result comes back to the main conversation. Claude Code, Codex, Cursor, Gemini CLI and GitHub Copilot all have them. We read every behaviour in each tool’s own documentation on 18 October 2026; the examples come from the repository we work in every day. We added Google’s Antigravity CLI on 28 October 2026.
- In Claude Code and Cursor, a subagent does not see your conversation history. Both say so outright in their documentation; the other three tools’ documentation is silent on it. In Claude Code a subagent starts with a fresh context that holds only the task message, the rules files and the git status (forks aside); in every tool, write the task message so that it stands on its own.
- In Codex, delegation depends on the effort level. At the top level, Ultra, Codex splits the work across subagents on its own; at the other levels, local Codex starts a subagent when you ask, or when AGENTS.md or a skill tells it to.
- In most tools, effort does not change how many subagents run. There are two exceptions: Codex’s Ultra level and Claude Code’s ultracode setting, which both split the work across subagents.
- Parallel edits need separate worktrees. On 27 August 2026, 41 worktrees had piled up in our repository; 37 of them were left over from a single review round.
A subagent works in its own context and hands you the result
When you give a coding agent a big job, it can go two ways: the main conversation does everything itself, or it hands part of the work to a subagent. The subagent does that part in its own context, so the files it reads and the tests it runs do not fill up the main conversation.
Cursor’s documentation says it in two sentences: “Intermediate output stays in the subagent. The parent only sees the final summary.” As of 18 October 2026, five tools have subagents: Claude Code, OpenAI’s Codex, Cursor, Google’s Gemini CLI and GitHub Copilot. Claude Code, Cursor and Copilot talk about the subagent’s own context window; Gemini CLI calls it a separate context loop, and Codex starts agents in parallel and collects their results in one response.
That is why subagents pay off in two kinds of work: jobs with a lot of output (running tests, scanning logs, reading dozens of files) and investigations that do not depend on each other. The examples come from the repository we use every day to build diffox, where we run Claude Code.
A subagent doesn’t see your conversation, so the task must stand on its own
The most common mistake with subagents is to assume they know what was said in the main conversation. According to Claude Code’s documentation, a subagent starts with a fresh context window: it does not see your conversation history, the skills already invoked or the files Claude has read. This is what it starts with:

So the task message has to say, on its own, what the goal is, which files the subagent may touch and what it should report. Whatever you called “that bug” in the main conversation does not exist for the subagent; write down the file path, the error message and the output you expect. Cursor’s documentation says the same: subagents start with a clean context and have no access to earlier conversation history. The Codex, Gemini CLI and Copilot documentation do not say this; whichever tool you use, a task message that stands on its own is the safe choice. Codex’s documentation also recommends asking a subagent to return a summary instead of its intermediate output.
Where each tool keeps subagents, when it delegates, and which come built in
In all five, a subagent is defined in a file that lives at project or user level. Where the tools really differ is whether the main agent hands off work on its own:
| Tool | Definitions (project · user) | Delegates on its own? | Built-in agents |
|---|---|---|---|
| Claude Code | .claude/agents/ · ~/.claude/agents/ | Yes, based on the description; call one by name with @ | Explore, Plan, general-purpose |
| Codex | .codex/agents/ · ~/.codex/agents/ | Yes at Ultra; at the other levels, when asked or when AGENTS.md or a skill says so | default, worker, explorer |
| Cursor | .cursor/agents/ · ~/.cursor/agents/ | Yes; call one by name with /name | explore, browser |
| Gemini CLI | .gemini/agents/ · ~/.gemini/agents/ | Yes, based on the description; @name steers it | codebase_investigator, cli_help, generalist |
| GitHub Copilot | .github/agents/ · ~/.copilot/agents/ | Yes in the CLI, where the model decides; pick one with /agent | explore, task, general-purpose, code-review… |
Source: each tool’s subagent documentation, 18 October 2026. In Codex a definition is a TOML file; in the others it is a Markdown file with YAML frontmatter. Gemini CLI’s browser agent is off by default. Copilot’s list of built-in agents changes from page to page: the reference page lists seven, the how-to page four.
The tools part ways in the “Delegates on its own?” column. In Codex it depends on the effort level: the models page says the top level, Ultra, runs the work by splitting it across subagents, while the subagents page says local Codex starts a subagent on a direct request such as “spawn two agents”, or on an instruction in AGENTS.md or a skill. In the other four, the main agent can also hand off work on its own; Copilot’s documentation adds that the model may just as well do the work itself instead of delegating it.
Definitions travel between tools: Cursor also reads the .claude/agents/ and .codex/agents/ folders (on a name clash, .cursor/ wins), and Copilot CLI reads .claude/agents/ too. So a file you put under .claude/agents/ is read by Claude Code, Cursor and Copilot CLI; the documentation does not guarantee that the frontmatter fields work the same in all three.
On 18 June 2026, Google stopped serving Gemini CLI to free users and to Google AI Pro and Ultra subscribers and pointed them to Antigravity CLI; with a paid API key or a company licence you can keep using Gemini CLI. We read Antigravity’s subagent documentation on 28 October 2026. Subagents are defined in .agents/agents/ for a project and in ~/.gemini/config/agents/ for the user. The main agent hands a task over by reading the subagent’s description; three agents come built in: research, browser and self. A subagent does not get the main agent’s conversation history and starts with a clean context; if its definition names no model, it runs on the main agent’s model. Subagents can be nested up to 10 levels deep.
A good subagent definition has a narrow job, few tools and a short report
The definition file sets three things: when the subagent is called (the description), what it can reach (the tools) and what it returns (the prompt). In Claude Code it looks like this; the required fields are name and description:
---
name: test-runner
description: Runs the tests and reports only the ones that fail
tools: Read, Grep, Glob, Bash
model: haiku
---
Run the test suite. Report only the failing tests, each with its
error message. Do not edit any file.- The description is a trigger. Claude Code and Gemini CLI decide whether to delegate by reading the description. Write in it when the agent should be called, not what the agent is.
- Narrow the tools. In Claude Code, the
toolsfield limits which tools the subagent can use; leave it out and the subagent inherits every tool available to subagents. Don’t give a write tool to an agent that only needs to read. - Permissions come from the main agent. In Codex, a subagent inherits the main agent’s permissions, provider and MCP servers, and a definition file cannot change them. The sandbox and approval settings are the main agent’s too.
- Ask for a short report. Let the last sentence of the prompt say what comes back: the failing tests, the files found, a decision. If long intermediate output is carried back into the main conversation, the point of using a subagent is lost.
- You can turn off automatic use. In the Copilot cloud agent, an agent with
disable-model-invocation: trueruns only when you select it by hand. In Copilot, a custom agent’s prompt can be at most 30,000 characters.
The model, concurrency and nesting limits differ by tool
If you don’t set a model in the definition, the documentation says a subagent in Claude Code, Codex, Cursor and Copilot runs on the main agent’s model. Gemini CLI’s subagents page says the same, but the model page of the same documentation says the /model command and the --model flag do not change the model subagents use; the two do not quite line up. How many subagents can run at once, and whether a subagent can start another one, depends on the tool:
| Tool | Model (if the definition sets none) | At once | Nesting |
|---|---|---|---|
| Claude Code | The main conversation’s | 20 | Up to 3 levels below the main conversation |
| Codex | The main agent’s, with its reasoning effort | Configurable; the default number is not published | Not stated in the documentation |
| Cursor | The main agent’s | Not stated in the documentation | Two levels: a subagent started by a subagent cannot start another |
| Gemini CLI | The main session’s; but /model does not change it (the pages disagree) | Not stated in the documentation | None: a subagent cannot call a subagent |
| GitHub Copilot | The main agent’s | 32 in the CLI; elsewhere the page says it depends on the plan | 4 or 6 in the CLI, as the page gives two values; none in the IDE |
Source: each tool’s subagent documentation, 18 October 2026. “Not stated in the documentation”: in the pages we read that day, we found no sentence that gives this. Copilot CLI’s reference page gives the depth as 4 in its environment variables section and as 6 in its limits table. By default, Gemini CLI limits each subagent to 30 turns and 10 minutes.
Claude Code looks for the model in four places, in order: the model parameter of that call, the model field in the definition, the CLAUDE_CODE_SUBAGENT_MODEL environment variable, then the main conversation’s model. What happens at the limit is documented too: while 20 subagents are running, a new one cannot start, and the error tells Claude not to retry. Gemini CLI turns nesting off to prevent infinite loops and excessive token use.
In most tools, the effort level doesn’t change how many subagents run
All five tools have a setting for how much thought the model puts into an answer: effort, or reasoning effort. How it relates to subagents comes down to two questions: does a subagent inherit the main agent’s level, and can it pick its own?
| Tool | Effort setting | Does a subagent inherit it? | Can a subagent pick its own? |
|---|---|---|---|
| Claude Code | low, medium, high, xhigh, max | Not stated explicitly in the documentation; agent team members inherit the lead’s | Yes: effort in the definition; the per-call effort parameter since v2.1.292 |
| Codex | model_reasoning_effort: low … ultra | Yes, unless the subagent sets its own | Yes: model_reasoning_effort in the TOML |
| Cursor | A model parameter: [effort=high] | Not stated in the documentation | Yes: model: claude-opus-5[effort=high] |
| Gemini CLI | thinkingConfig: a thinking budget or level | Not stated in the documentation | With a per-agent override |
| GitHub Copilot | --effort: low … max | Yes in the CLI; per the SDK page, only on the same model | Yes: reasoningEffort |
Source: each tool’s model and subagent documentation, 18 October 2026. In Cursor, the names of the levels depend on the model.
The Claude Code, Cursor, Gemini CLI and Copilot documentation do not tie effort to the number of subagents. Claude Code’s documentation describes the difference it observed at a higher level: Claude “tested more edge cases and verified more of its work before answering. It also made more choices on its own.” It says nothing about the number of subagents. In Copilot, parallel subagents depend not on effort but on a separate mode: with the /fleet command, the main agent decides for itself whether it can split the work into parts.
The exception is Codex’s top level, ultra. The models page uses the same sentence for the CLI, the app and the IDE: “Ultra mode goes beyond a single-agent run. It uses subagents to accelerate complex work.” In ChatGPT Work, too, Ultra lets ChatGPT hand suitable work to subagents on its own. At the other levels, according to the subagents page, local Codex starts a subagent when you ask, or when AGENTS.md or a skill tells it to.
Claude Code’s ultracode setting splits the work across dozens of subagents
Next to the effort levels, Claude Code’s /effort slider has an ultracode toggle. The documentation describes it not as a level but as a separate setting: “a Claude Code setting rather than a model effort level”. With it on, Claude plans a dynamic workflow for every substantive task without being asked: it writes a script that splits the work and manages the subagents, and a runtime executes the script in the background while your session stays responsive.

There are four ways to turn it on:
- For one task: put the word
ultracodein your prompt; the session’s effort level does not change. The word only counts in a prompt you type yourself. - For the session:
/effort ultracode, or the toggle on the slider. - At launch:
claude --effort ultracode, which also sets the effort level toxhigh. - In every session:
"ultracode": truein the settings file.
The documentation is clear about the cost: every request uses more tokens and takes longer, and on a subscription you reach your session or weekly limit sooner. With ultracode on, the limit of 20 subagents is not enforced; a workflow has limits of its own: by default 16 agents at once and at most 1,000 agents in a run. With ultracode off, more than 25 agents, or a projected total above 1.5 million tokens, brings up a “Large workflow” warning; with ultracode on, that warning is not shown either.
Dynamic workflows arrived at the end of May 2026 and were announced as a “research preview” in the weekly digest; on 18 October 2026 the workflows page carried no status label. Don’t confuse ultracode with two things that have similar names: ultrathink asks for deeper thinking on that turn only and does not change the effort level; /code-review ultra is a separate command that runs review agents in the cloud, and Claude does not start it on its own.
Can subagents talk to each other?
In all five, a subagent’s result goes back to whoever called it. The tools differ on three questions: can subagents write to each other, can the main agent write to a running or finished subagent later, and is there a team feature?
| Tool | Subagent to subagent | Main agent writes later? | Closest team feature |
|---|---|---|---|
| Claude Code | Yes: subagents that Claude has named, with SendMessage | Yes; a finished subagent resumes with its full history (except Explore and Plan) | Agent teams: members write to each other by name |
| Codex | Not stated in the documentation | Yes; you ask Codex to steer or stop a subagent | None in the documentation |
| Cursor | Not stated in the documentation; the result goes back to the main agent | Resumed by its agent ID, with its context kept | Projects: a coordinator agent manages many agents |
| Gemini CLI | No | Not stated in the documentation | Remote subagents (A2A): delegation, not a team |
| GitHub Copilot | Yes in the CLI: to sibling agents, with write_agent | Yes in the CLI: a message to a running agent | /fleet: the main agent manages parallel subagents |
Source: each tool’s documentation, 18 October 2026. In Copilot, writing to sibling agents needs shared sibling communication to be on; the documentation does not say how to turn it on.
Claude Code’s agent teams take this furthest: one session is the team lead, the members are separate sessions, each works in its own context window, and they write to each other by name. There is no broadcast; each recipient gets a separate message. The documentation’s own rule of thumb: “Use subagents when you need quick, focused workers that report back. Use agent teams when teammates need to share findings, challenge each other, and coordinate on their own.” Agent teams are experimental and off by default, and they use more tokens because each member is a separate Claude instance.
Being able to message each other does not mean you should depend on it. The sturdiest setup is still to split the work into independent parts and combine the results in the main agent. Copilot’s fleet documentation says the same: coordination runs on explicit state, not implicit shared memory, and subagents keep no state between calls, so give each one complete context.
Parallel agents need separate worktrees and separate files
Subagents that only read can work side by side in the same directory. The trouble starts when several agents edit files and commit: they share the same directory, the same branch and the same git index. That is a git problem, whichever tool you use. Our repository has four rules for it.

A separate worktree. In Claude Code, if you add isolation: worktree to the definition, the subagent gets a temporary worktree, a separate working directory of the repository, which is removed automatically if the subagent finishes without changes. According to the documentation, this worktree branches by default from the repository’s default branch, not from the branch you are working on.
Separate files. Our rule for agents that share one directory: each commits only its own paths (git commit --only <paths>), because a bare git commit takes the whole index, including work another agent has staged. When you split the work, give each agent its own set of files.
A task message that stands on its own. In Claude Code and Cursor a subagent does not see your conversation history; the task message has to say, on its own, what the goal is, which files it may touch and what it should report. Hooks in the settings file, on the other hand, reach it automatically: in Claude Code a PreToolUse hook also runs before a subagent’s tool calls.
Cleanup. A worktree with changes stays on disk. On 27 August 2026, 41 worktrees had piled up in our repository, 37 of them from a single review round. The clutter came from workflows, not people, so that is where the fix went: every session opens with a script that removes the branches of merged pull requests and the worktrees whose work is done.
Not every task needs a subagent
A subagent protects your context, but it builds its own from scratch; writing the task message and reading the result cost something too. Claude Code’s documentation recommends staying in the main conversation when:
- The task needs frequent back-and-forth. You will refine the work together, step by step.
- The phases share the same context. Planning, implementation and testing rest on the same information.
- The change is small and targeted. A few lines in one file.
- Speed matters. A subagent starts from scratch, and gathering context takes time.
A subagent fits work that answers one question on its own: “run the tests and bring back the failures”, “who calls this module?”, “compare these three libraries”. diffox’s review rests on the same idea: it splits an AI code review across specialist agents, and each one looks at the change with its own question. We explain how they are chosen in our architecture post.
Frequently asked questions
What is a subagent, and when should you use one?
A subagent is a helper that the main agent hands a task to and that works in a separate context; in Claude Code and Cursor it does not see your conversation history, and it returns its result to the main agent. Claude Code, Codex, Cursor, Gemini CLI and Copilot all have them, and so does Google’s Antigravity CLI. They help with work that produces a lot of output (tests, logs, searches across many files) and with independent investigations run in parallel.
What is the difference between subagents and skills?
A skill is a set of instructions or a workflow that can be loaded into any context; it is added to the context of the conversation that loads it. A subagent is a separate worker that runs in its own context window; it does the work there, and only the summary comes back to the main conversation. In Claude Code the two can be combined: a subagent definition can preload skills, and a skill can run in a separate context.
Can subagents talk to each other?
It depends on the tool. In Claude Code, subagents that Claude has named can write to each other with SendMessage; in Copilot CLI, with shared sibling communication on, messages go to sibling agents through write_agent (the documentation does not say how to turn it on). In Gemini CLI a subagent cannot call another subagent; the Codex and Cursor documentation do not describe messages from one subagent to another. In Antigravity, agents can write to each other by conversation ID; a subagent that has finished its work and is waiting picks up where it left off when a message arrives. A separate feature in which members write to each other directly is Claude Code’s experimental agent teams.
Which model and effort level does a subagent use?
Unless the definition sets one, it uses the main agent’s model in Claude Code, Codex, Cursor and Copilot; Gemini CLI’s subagents page says so too, but its model page says the /model command does not change a subagent’s model. Effort depends on the tool: in Codex a subagent inherits the main agent’s reasoning effort, and in Copilot CLI it does too. In Claude Code, the effort field in the definition or the effort parameter on the call (v2.1.292 and later) gives a subagent its own level. In most tools, raising effort does not change how many subagents run; Codex’s Ultra level is the exception.
How do you use Codex subagents?
Custom agents are TOML files under .codex/agents/ or ~/.codex/agents/; name, description and developer_instructions are required. At the top effort level, Ultra, Codex splits the work across subagents on its own; at the other levels a subagent starts on a direct instruction such as “spawn two agents”, or on an instruction written in AGENTS.md or a skill. In the CLI you switch between running agents with /subagents.
What is ultracode in Claude Code?
Ultracode is not an effort level in Claude Code but a separate setting. With it on, Claude plans a dynamic workflow for every substantive task: it writes a script that splits the work and manages dozens of subagents, and the script runs in the background. For a single task you write ultracode in the prompt; for the whole session you turn it on with /effort ultracode. Every request uses more tokens and takes longer.
How many subagents can run at once?
In Claude Code the default limit is 20, and you can change it; in an ultracode workflow, 16 agents run at once and at most 1,000 in a run. In Codex the limit is a setting, but its default number is not published. Copilot CLI’s reference page gives two different values; on 18 October 2026 we found no number in the Cursor or Gemini CLI documentation.