Subagent Runtime
Claude Code ships a few built-in agents, and a set of rules limits every subagent. The rules cover tool filters, forks, background runs, depth limits, and agent teams. For example, a subagent cannot start another one past the depth limit, which is 3 by default. A fork is a subagent that inherits the whole conversation and shares the prompt cache with its parent.
Your own agent file replaces a built-in one of the same name. Limits come from env vars and settings. The switches are CLAUDE_CODE_FORK_SUBAGENT, CLAUDE_CODE_DISABLE_BACKGROUND_TASKS, CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS, and CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS.
Example
Limit nesting to one level and run every subagent in the foreground.
export CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1
export CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1
claude
Built-In Agents
The program lists 14 names. Six are in the docs. The rest are internal or are not agents.
| Agent | Status | What it does | Notes |
|---|---|---|---|
Explore | Documented | A fast read-only search agent. | Uses the main model, with omit and no git status. Denies Agent, Edit, Write, Notebook, and two more internal tools. A user agent named Explore overrides it. CLAUDE_ removes it (2.1.198). |
Plan | Documented | A research agent for plan mode. | Model inherit. The same disallowed as Explore. omit is true. |
general- | Documented | A capable agent for multi-step work. | tools:. Model: CLAUDE_ or the main model. The default when subagent_ is left out. CLAUDE_ removes it in -. |
claude | Documented | A catch-all agent with every tool. | tools:, append true, no model of its own. Also the default agent for a dispatched background session. |
statusline- | Documented | Configures the status line for /. | Tools Read and Edit. Model sonnet. Color orange. Interactive. |
claude- | Documented | Answers questions about Claude Code. | The docs say model Haiku. The prompt text was not extracted. |
fork | Documented | A fork of the main conversation. | Inherits the system prompt, tools, model, and history. Cannot start a fork. At the depth limit it keeps Agent, but the tool returns an error. Needs fork mode. |
workflow- | Undocumented | The agent that Workflow scripts use. | Model from CLAUDE_. Not verified. |
comment- | Undocumented | Analyzes artifact comment threads. | One tool. Model inherit. max 6. omit true. |
| Web-reading agent | Undocumented | Fetches URLs for a caller. | Prompt "web-reading specialist". max 15. Color blue. omit true. Model haiku or inherit, by a flag. Env var CLAUDE_ exists. When it runs is not verified. |
The names worker, renewal, killed, decorations, and main-session also appear in the program. They are not spawnable agent types as far as anyone read.
The prompts of the built-in agents were not read. Only their purpose and tools were.
Tools and Context of a Subagent
| Rule | Status | What it does | Notes |
|---|---|---|---|
| First filter | Documented | Removes tools from every subagent. | Removed: Agent at the depth limit (not for a fork), Ask, End, Enter, Exit (kept in plan mode), Schedule, Wait, Workflow. Forks skip both filters. |
| Second filter | Documented | The built-in tools that a background subagent keeps. | File and search tools, shell tools, web tools, Todo, Skill, Tool, the worktree tools, Monitor, Task, Send, Artifact, Subagent, and every MCP tool. |
| Foreground or background | Documented | How a start is placed. | A teammate start and CLAUDE_ run in the foreground. Fork mode and background: run in the background. Otherwise the default is background, and Ctrl+B backgrounds a running task. |
| Resume | Documented | Continues a finished subagent. | Use Send with the name or agent ID. A per-call model also applies on resume (2.1.211). |
| Initial context | Documented | What a non-fork subagent loads. | The agent prompt, the task message, CLAUDE. files (unless omit), git status (not for Explore and Plan), preloaded skills, and a roster of siblings with Send. No output style and no auto memory. |
Limits and Switches
| Item | Status | What it does | Notes |
|---|---|---|---|
CLAUDE_ | Documented | Layers of nesting below the main session. | Default 3. At the limit Agent is withheld, except from a fork. 1 turns nesting off. Earlier defaults: 5 (2.1.172), 1 (2.1.217). |
CLAUDE_ | Documented | The most subagents running at once. | Default 20. The error is Concurrent subagent limit reached. Ultracode sessions are exempt. Resumes and / forks take a slot but are not blocked. |
CLAUDE_ | Documented | Fork mode. | On in interactive sessions (since 2.1.232), off in - and the SDK. 1 forces on, 0 forces off. In fork mode every subagent runs in the background, and Agent has no run_. |
CLAUDE_ | Documented | Runs all subagents in the foreground. | Set 1. Also removes run_. |
CLAUDE_ | Documented | The stall timeout. | Default 600000. |
CLAUDE_ and -- | Documented | Sends subagent text in stream-. | Print mode only. |
CLAUDE_, CLAUDE_ | Documented | The default model, and forcing it. | See model on Subagent Frontmatter. |
CLAUDE_, subagent | Documented | The cache TTL for subagent requests. | 5m or 1h. Frontmatter experimental. is the third source. See Request and Cache. |
CLAUDE_, CLAUDE_, CLAUDE_, CLAUDE_, CLAUDE_ | Undocumented | Other subagent variables in the program. | Names only. The effect was not verified. |
Settings agent, teammate, subagent | Documented | agent sets the main-session agent. teammate picks the teammate display. subagent sets a status line for subagents. | The values of teammate were not verified. |
All variables are also listed on Environment Variables for Agents and Teams.
Agent Teams
An agent team is a group of Claude sessions that work as teammates.
| Item | Status | What it does | Notes |
|---|---|---|---|
| 🧪 Agent teams | Gated | Several sessions work as teammates. | A named subagent started in an interactive team session starts as a teammate. team_ and mode on Agent are deprecated and ignored. |
| Teammate tools | Gated | Extra tools for a teammate. | Teammates keep Task, Task, Task, Task, Cron, Cron, Cron. Send routes by name, main, or agent ID. |
Teammate hook | Documented | Runs when a teammate is about to go idle. | Exit 2 or continue: keeps it working. See Hook Events. |
Task, Task hooks | Documented | Task lifecycle events. | Task also fires when a teammate finishes its turn. |
agent. mod event | Documented | Fires before a subagent or teammate starts. | e. is true for a teammate. next({... sets the model. See Plugin Mods Reference. |
CLAUDE_ | Documented | The wait at exit for team teardown. | 1000 to 60000 ms in print mode. |
How It Works
Related Pages
- Subagents: where agent files live.
- Subagent Frontmatter: the keys of an agent file.
- Hook Events: the agent and task events.
- Environment Variables for Agents and Teams: the full variable list.
- Agents and Tasks Tools for
Agent.
Source: Create Custom Subagents, Environment Variables, Hooks Reference, and the program (the agent definitions and the Agent tool schema).