daBongo LMS AI Training Courses

Sub-Agents in Claude Code – Context, Delegation, and Focus

Lesson 1: What Sub-Agents Are and Why Context Management Matters

Lesson Objectives

By the end of this lesson, students should be able to:

  • Explain what a sub-agent is in Claude Code
  • Describe why context window limits create a need for sub-agents
  • Identify task types where sub-agents improve results
  • Distinguish between tasks appropriate for a single agent vs. multiple sub-agents

Lesson Content

What sub-agents are.

Sub-agents are separate Claude Code agent instances spawned by a parent agent (or the user). Each sub-agent has its own context window – its own focused conversation history and working state. A sub-agent completes a scoped task and returns results to the parent, which uses them to continue the larger workflow.

Why context management drives sub-agent use.

A Claude Code agent session's context window is finite. In a long, complex session:

  • Early context gets compressed or dropped as the session grows
  • The agent may have reduced recall of decisions and findings from early in the session
  • Complex multi-domain tasks fill the context with information from multiple domains, diluting focus

Sub-agents address this by giving each domain or phase its own focused context:

  • A sub-agent analyzing security has a context window dedicated to security findings
  • A sub-agent analyzing performance has a context window dedicated to performance
  • The parent aggregates findings with clean, high-level summaries – not raw detail

Tasks appropriate for sub-agents.

  • Large codebase analysis: Each sub-agent analyzes a module or layer; parent aggregates
  • Multi-phase projects: Each phase runs in a fresh sub-agent context; parent coordinates
  • Parallel workstreams: Multiple sub-agents run independently on separate tasks; parent merges results
  • Specialized analysis: Security sub-agent, performance sub-agent, documentation sub-agent – each with focused context

Tasks NOT appropriate for sub-agents.

  • Simple, focused tasks that fit within a single context window
  • Tasks where continuity of the full conversation history is important
  • Tasks that require tight feedback loops between phases

Sub-agents add overhead: spawning, context transfer, result aggregation. Use them when the context management benefit outweighs the overhead.

Practical Example

A developer asks a single Claude Code agent to analyze a 50-file codebase for security vulnerabilities, performance bottlenecks, and documentation gaps.

By file 35, the agent's early security findings are compressed out of context.

The final report misses issues found early.

Second approach: three sub-agents – one per concern, each analyzing the full codebase for one concern only.

Each sub-agent's context is fully dedicated to its domain.

Three focused reports returned to the parent; parent produces a comprehensive summary.

Full coverage, no compression loss.

Safety Notes

Sub-agents execute with the same file system and shell permissions as the parent agent. A sub-agent assigned a vague or broad task can make widespread changes across the codebase. Apply the same scoping discipline to sub-agent tasks as to Cowork mode tasks in general: specific goal, defined file scope, defined stop conditions.

Log in and enroll to access lesson quizzes.

Scroll to Top