Sub-Agents in Claude Code – Context, Delegation, and Focus By the end of this lesson, students should be able to: 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: Sub-agents address this by giving each domain or phase its own focused context: Tasks appropriate for sub-agents. Tasks NOT appropriate for sub-agents. Sub-agents add overhead: spawning, context transfer, result aggregation. Use them when the context management benefit outweighs the overhead. 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. 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.
Lesson 1: What Sub-Agents Are and Why Context Management Matters
Lesson Objectives
Lesson Content
Practical Example
Safety Notes