daBongo LMS AI Training Courses

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

Lesson 2: Spawning and Configuring Sub-Agents

Lesson Objectives

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

  • Initiate a sub-agent spawn in Claude Code Cowork mode
  • Transfer the right context to a sub-agent
  • Configure a sub-agent's task scope and file access
  • Understand what the sub-agent inherits from the parent vs. what must be explicitly provided

Lesson Content

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:

  • Task description: Specific, measurable goal for the sub-agent
  • Scope: Which files or directories the sub-agent should work in
  • Relevant background: What the sub-agent needs to know about the project to do its task
  • Expected output format: How the sub-agent should report its findings

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:

  • Specific and measurable ("identify all SQL queries that are not using parameterized inputs in src/db/")
  • Scoped file access ("only read files in src/db/ – do not modify any files")
  • Defined output format ("return a list of file paths and line numbers for each finding, with a brief description of the issue")
  • Defined stop conditions ("stop if you find more than 20 issues – return what you have found so far")

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.

Practical Example

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.

Safety Notes

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.

Scroll to Top