Blog

Claude Code Subagents Guide

Subagents let Claude Code delegate tasks to specialized child instances — useful for large tasks that benefit from parallel execution or isolated context. How they work and when to use them.

Phos Team ·
claude code

Claude Code Subagents: Delegation With Isolated Context

Large development tasks have a context problem. A Claude Code session that reads the entire codebase, writes backend code, writes frontend components, generates tests, and produces documentation all in a single context window is doing a lot of work in a limited space. The more each piece of the task knows about the others, the more the context fills up with information that is not relevant to any individual subtask.

Subagents solve this by dividing the work. The parent Claude Code session holds the high-level plan and coordinates results. Each subagent handles a specific subtask in its own isolated context window, with only the information relevant to that subtask.

The result is cleaner work on each piece and a parent session that can reason clearly about coordination without being overwhelmed by implementation details from every part of the project.

Subagents are not just a speed optimization. Context isolation is a quality optimization. A subagent that only knows about the backend has sharper reasoning about backend code than a monolithic session carrying frontend, backend, and test context simultaneously.


The Parent-Child Relationship

Every subagent workflow has two roles:

The parent session holds the task decomposition. It understands the full scope of the work, identifies which subtasks can be delegated, spawns the subagents, and integrates their results. The parent does not execute the subtasks itself. It orchestrates.

The subagents execute specific, bounded subtasks. Each subagent receives a clearly defined scope: what to build, what files to work with, what the acceptance criteria are. It has no knowledge of other subagents’ work. When the subagent finishes, it reports back to the parent.

This separation is clean in theory and practical in execution. The parent handles “what needs to be done and in what order.” The subagents handle “how to do this specific piece.”

The parent-child model also handles sequencing. If task B depends on task A, the parent can spawn the subagent for task A, wait for completion, incorporate the result, then spawn the subagent for task B with the context it needs. Tasks that are independent can be spawned simultaneously.


How Subagents Are Invoked

Subagents are invoked when the parent Claude Code session identifies tasks that benefit from isolated execution. You trigger this by describing the decomposition in your prompt:

Build a full-stack task management application. Decompose the work as follows:

Subagent 1 — Backend API:
- REST API using Node.js and Express
- Endpoints: /tasks (GET, POST), /tasks/:id (GET, PUT, DELETE)
- SQLite database with tasks schema
- Jest tests for all endpoints
- Spec: docs/backend-spec.md

Subagent 2 — Frontend:
- React components: TaskList, TaskItem, AddTaskForm
- Connects to the backend API defined above
- No external state management libraries
- Spec: docs/frontend-spec.md

Subagent 3 — Test suite:
- End-to-end tests using Playwright
- Test happy path and error cases for all task CRUD operations
- Spec: docs/e2e-spec.md

Each subagent commits its work to its own branch. Report back when all three are complete.

The parent session reads this description, spawns three subagents, and coordinates. Each subagent works in isolation.


Subagent Context Isolation

Context isolation is the architectural property that makes subagents useful beyond raw speed. Each subagent starts with a fresh context window containing only what is relevant to its task.

A subagent building the backend API does not carry context about the React component structure. A subagent writing end-to-end tests does not carry the implementation details of the database schema. Each agent reasons about its domain without the noise of adjacent domains.

This matters for output quality. Context windows have limits. A monolithic session that tries to hold the full codebase, all the specs, and all the implementation work simultaneously is a compressed context. A subagent with a focused context window produces sharper, more coherent work on its specific subtask.

The isolation also prevents a specific failure mode: context contamination. In a long monolithic session, early decisions and implementation patterns can bias later reasoning in ways that are hard to detect. Subagents start clean.


A Full-Stack Example

A team building a new internal tool needs three things: a backend API, a frontend dashboard, and a test suite. These are genuinely independent work units once the interface contracts are defined.

Without subagents (sequential execution):

PhaseWho does the workSequential time
Backend API (20 endpoints, tests)One Claude Code session~60 min
Frontend dashboard (12 components)Same session, later~45 min
E2E test suiteSame session, later~30 min
Total~135 min

With subagents (parallel execution):

PhaseSubagentParallel time
Backend APISubagent 1~60 min
Frontend dashboardSubagent 2~60 min (concurrent)
E2E test suiteSubagent 3~60 min (concurrent)
Parent coordination and integrationParent session~10 min
Total~70 min

The backend is the longest task and sets the floor. The frontend and tests run concurrently with it. Total wall-clock time drops from 135 minutes to approximately 70 minutes, a 48% reduction. The quality benefit from context isolation is harder to quantify but real.


Subagents vs. Parallel Agents: The Distinction

These terms are related but not identical:

Subagents refers specifically to the parent-child architecture: a parent session that orchestrates child instances with their own context windows. The relationship is formal. The parent decides when to spawn, what scope to assign, and how to integrate results.

Parallel agents is the broader pattern of running multiple Claude Code instances concurrently on independent tasks. This can include formally spawned subagents or informally parallel sessions.

In practice, when Claude Code runs parallel subagents, both terms apply. The subagents are the mechanism. Parallel execution is the outcome. The distinction matters when you are deciding whether to use one parent session to orchestrate multiple children (subagent pattern) versus manually opening multiple sessions and managing coordination yourself (manual parallelism without subagent orchestration).

The subagent pattern is preferable when the coordination logic is complex, because it keeps that logic in one place.


Resource Implications

Each subagent is a separate Claude Code instance with its own API calls and token consumption. A parent session that spawns three subagents incurs the token cost of four sessions: the parent plus three children.

For tasks where time is the constraint, this is an acceptable trade-off. For high-volume automated pipelines where token budget is the constraint, it may not be.

ConstraintRecommendation
Developer time is the bottleneckUse subagents; the time savings justify the token cost
Token budget is tightly cappedUse sequential execution; same total tokens, lower peak cost
Quality isolation is the concernUse subagents; context isolation improves output quality
Task is small and scopedSkip subagents; overhead exceeds benefit

The token cost also runs in parallel rather than sequentially. Three concurrent subagents hit your API rate limits three times as hard during execution. If you are near rate limits, parallel subagent execution may trigger throttling. Check your account limits before running large parallel subagent workflows.


When Not to Use Subagents

Tightly coupled tasks. If subtask B needs to read the output of subtask A before it can proceed, they cannot run as parallel subagents. The dependency chain requires sequential execution. You can still use subagents (spawn A, wait for completion, spawn B), but you lose the parallelism benefit.

Small projects where overhead exceeds benefit. A three-file change does not benefit from subagent decomposition. The spawning and coordination overhead takes longer than the task itself. Subagents pay off on tasks that are large enough that isolation and parallelism provide real value.

Unclear interface contracts. Parallel subagents building a frontend and backend need to agree on the API interface before they diverge. If the interface is not specified upfront, both subagents will make independent assumptions that conflict when the pieces are assembled. Define the contracts first, then spawn the subagents.

Context that genuinely needs to be shared. Some tasks require one agent to understand what another is doing. A refactor that touches a shared utility used by multiple modules needs unified reasoning about the full impact. Splitting it across isolated subagents produces inconsistencies.

Subagents are powerful when the task decomposition is clean. When the decomposition is forced, the integration overhead creates more work than the parallelism saves.


Frequently Asked Questions

Can subagents communicate with each other directly?

No. Subagents are isolated by design. They do not have a channel to communicate with each other mid-execution. All coordination flows through the parent session. If subagent 2 needs information from subagent 1, the parent must receive subagent 1’s output and pass the relevant context to subagent 2. Design your task decomposition so that parallel subagents do not need to communicate during execution.

How does the parent session know when subagents are complete?

The parent session monitors subagent completion and incorporates results as they come in. You do not need to manually poll or check. When all subagents have reported back, the parent session can proceed with integration, review, or further orchestration.

Do subagents have access to the same tools as the parent?

Yes. Subagents inherit the tool access of the parent session by default. They can read files, write files, run terminal commands, and use any MCP tools the parent has access to. Tool restrictions applied to the parent via --allowedTools apply to subagents as well.

What happens if a subagent fails mid-task?

The parent session will report the failure. The other subagents that were running in parallel are not automatically stopped. They continue to completion. You can then review the failed subagent’s partial output, diagnose the issue, and either re-spawn that subagent with a corrected prompt or complete the failed subtask manually.


Ready to put subagent architecture to work on your development workflow?

Subagents unlock real parallelism on large tasks, but only if the decomposition and interface contracts are designed correctly. Here are your two options.

Path one: design your own subagent workflow. Start with the decision table above and pick one large task where context isolation and parallelism both apply. Define the interface contract first, then split the work.

Path two: work with Phos AI Labs. We design subagent workflows for development teams that want to move faster on large tasks without sacrificing oversight or quality. Phos AI Labs is a CCA-F certified Claude implementation partner with 400+ engagements. Thirty minutes, no deck. Start here.

Related articles

The fastest way to know whether we're the right fit, is a conversation.

STEP 1/2 · ABOUT YOU