Sub-Agents in Claude Code – Context, Delegation, and Focus By the end of this lesson, students should be able to: How sub-agents are spawned. Sub-agents in Claude Code are spawned within Cowork/Agent mode. The parent agent spawns a sub-agent by providing it with a task description and relevant context. The sub-agent runs as a separate agent instance and returns results when complete. Verify current sub-agent spawn syntax and configuration at docs.anthropic.com/en/docs/claude-code. Context transfer – what to give the sub-agent. A sub-agent starts with a fresh context window. It does not inherit the parent's conversation history – it starts with only what you explicitly give it. Transfer: Do NOT transfer the entire parent conversation history – that defeats the purpose of a focused context window. Transfer only what this sub-agent needs for its specific task. Task description quality for sub-agents. Sub-agent task descriptions follow the same quality rules as Cowork mode tasks: What sub-agents inherit. Sub-agents in Claude Code inherit: the CLAUDE.md context for the project directory, available Skills, and the MCP servers configured for the project. They do NOT inherit: the parent's conversation history, intermediate findings, or decisions made during the parent session. A parent agent is coordinating a security audit. It spawns three sub-agents with explicit context transfer: Sub-agent 1: "Audit src/auth/ for authentication vulnerabilities. Focus on: session management, token validation, and privilege escalation risks. Read-only access to src/auth/ only. Return: list of files, line numbers, severity, and description for each finding." Sub-agent 2: "Audit src/api/ for input validation vulnerabilities. Focus on: unvalidated parameters, injection risks. Read-only access to src/api/ only. Return: same format." Sub-agent 3: "Audit src/db/ for SQL injection and ORM misuse. Read-only. Same return format." Each sub-agent has focused scope, focused context, and consistent output format. Parent aggregates three reports. Sub-agents inherit the project's CLAUDE.md and Skills – which may include broad permissions or instructions appropriate for general development work but not for a narrowly scoped sub-agent task. When spawning sub-agents for read-only analysis, explicitly scope the task description to read-only operations. Do not rely on inherited context alone to constrain sub-agent behavior. Log in and enroll to access lesson quizzes.
Lesson 2: Spawning and Configuring Sub-Agents
Lesson Objectives
Lesson Content
src/db/")src/db/ – do not modify any files")Practical Example
Safety Notes