A subagent is an agent that a main agent hands a task to, which runs in its own context window and returns only a summary. Anthropic describes the use case as a side task that “would flood your main conversation with search results, logs, or file contents you won’t reference again”. GitHub’s documentation defines a subagent as an agent doing delegated work in a separate context window, and separates it from a custom agent, which is the definition of a specialist that can be run as a subagent or selected for a whole session.

Why teams use them

Anthropic, OpenAI and GitHub give overlapping reasons.

  • Context. OpenAI says subagents move noisy work such as exploration notes, test logs and stack traces off the main thread, so the main agent stays focused on requirements and decisions and receives summaries instead of raw output.
  • Parallel work. OpenAI lists codebase exploration and multi-step feature plans as tasks that split into independent parts.
  • Constraints. Anthropic lists limiting which tools a subagent can use among the benefits, along with reusing configurations across projects and routing tasks to faster, lower-cost models.
  • A cost to weigh. OpenAI notes that subagent workflows use more tokens than comparable single-agent runs. Anthropic says a subagent’s own requests count toward the same usage limits as the main conversation.

How the four tools compare

Claude CodeCodexOpenCodeGitHub Copilot CLI
Custom agent fileMarkdown with YAML frontmatterStandalone TOML fileMarkdown with frontmatter, or an entry in a JSONC configMarkdown with YAML frontmatter (an agent profile)
Project location.claude/agents/.codex/agents/.opencode/agents/Depends on the environment
Personal location~/.claude/agents/~/.codex/agents/~/.config/opencode/agents/Personal profiles are supported
Required fieldsname, descriptionname, description, developer_instructionsNo required field is named in the docs reviewed; a new custom agent defaults to primary mode, so set mode: subagentNot listed on the overview page
Built-in agentsExplore, Plan, general-purpose and othersdefault, worker, explorerbuild and plan (primary), general and explore (subagent)explore, task, general-purpose, code-review, research, rubber-duck, security-review

Claude Code

Claude Code reads subagent files from several places, and when names collide the higher-priority location wins: managed settings, then the --agents CLI flag, then .claude/agents/, then ~/.claude/agents/, then a plugin’s agents/ directory. Only name and description are required. Optional frontmatter includes tools, disallowedTools, model, permissionMode, maxTurns, skills, memory, background and isolation. Setting isolation: worktree runs the subagent in a temporary git worktree.

Two behaviors matter for design:

  • A subagent can spawn subagents of its own, up to three layers below the main conversation by default. The CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH setting changes the limit.
  • Anthropic warns that when the descriptions of your non-built-in subagents add up to more than 15,000 tokens, Claude Code shows a warning at startup, since those descriptions take up context.

Codex

OpenAI says current Codex releases enable subagent workflows by default and that you ask for them directly, for example by telling Codex to spawn one agent per review area, or by putting the request in AGENTS.md or a skill. In the CLI, /subagents inspects and switches between agent threads.

Custom agents inherit the parent’s permissions, provider and MCP servers, and an agent file cannot override sandbox or approval settings. A custom agent’s instructions can ask it to avoid edits, but OpenAI states that this does not create a separate read-only sandbox. Global limits live under [agents] in the Codex configuration, including agents.max_concurrent_threads_per_session.

OpenCode

OpenCode defines three modes: primary, subagent and all. A subagent runs only in a child session through the subagent tool, with fresh context. Its docs say subagents always run in the background and the parent receives a report when a child goes idle. Unlike Codex, where custom agents inherit the parent’s sandbox and approvals, the child uses its own configured permissions, while the parent’s subagent permissions control which agents it may launch.

GitHub Copilot

GitHub documents custom agents as Markdown profiles with YAML frontmatter that describe a purpose, give instructions and can restrict tools. They work in the Copilot app, Copilot CLI, the cloud agent on GitHub.com and supported IDEs, and profiles can be shared at repository, organization and enterprise levels. One detail to know: in Copilot CLI, repository instructions are included for the session agent but not for a custom subagent by default.

Subagent or skill

The tools draw the line in a similar place. A skill loads instructions into the agent that is already working, as covered in what agent skills are. A subagent gets a separate context and its own tool access. GitHub suggests a skill when you only need task-specific instructions and resources, and a custom agent when you need a reusable role with a particular approach and toolset. The surrounding software that runs either one is the agent harness.