daBongo LMS AI Training Courses

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

Lesson 3: Delegating Tasks Effectively to Sub-Agents

Lesson Objectives

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

  • Write a complete sub-agent task delegation with all required components
  • Specify output format to enable parent aggregation
  • Set appropriate stop conditions to manage sub-agent scope
  • Evaluate whether a delegation is ready to send to a sub-agent

Lesson Content

The complete delegation structure.

An effective sub-agent task delegation has five components:

  1. Goal: What the sub-agent must accomplish – specific, measurable
  2. Scope: Which files, directories, or operations are in bounds
  3. Background: What the sub-agent needs to know about the project for this task
  4. Output format: Exactly how the sub-agent should report its findings
  5. Stop conditions: When to stop and return even if not complete

Goal specification.

Vague: "Review the authentication code." Specific: "Identify all places in src/auth/ where session tokens are stored or transmitted without encryption – return file, line number, and a description of the vulnerability."

The specific goal gives the sub-agent a precise success criterion. The vague goal produces a general "review" with no defined scope of findings.

Output format specification.

Standardized output format enables the parent to aggregate findings from multiple sub-agents without reformatting:

“` Return your findings as a list in this format:

  • File: [file path] | Line: [line number] | Severity: [High/Medium/Low] | Issue: [one sentence]

If no issues are found, return: "No issues found in scope." “`

When multiple sub-agents return findings in the same format, the parent can concatenate and sort without parsing.

Background – what the sub-agent needs to know.

Provide only project-specific context the sub-agent cannot get from CLAUDE.md alone:

  • The specific component architecture relevant to this task
  • Conventions the sub-agent should respect (do not flag X, Y is intentional)
  • Reference points (the database schema, the API spec)

Stop conditions.

  • Max findings: "Stop and return findings when you have identified 10 issues – do not continue after 10"
  • Max file count: "Analyze up to 20 files – stop and return after 20 even if the directory has more"
  • Decision point: "Stop and ask the parent if you find a pattern that is unclear – do not make assumptions about intent"

Practical Example

A complete delegation for a documentation coverage sub-agent:

"Goal: Identify functions and classes in src/api/ that have no JSDoc documentation.

Scope: Read-only access to src/api/ only.

Do not modify files.

Background: This is a TypeScript API codebase.

Functions decorated with @internal are exempt from documentation requirements.

Output format: Return a list: - [file path]:[line number] - [function/class name] for each undocumented item.

If all items are documented, return: 'All public API items in src/api/ are documented.' Stop condition: If you find more than 50 undocumented items, stop and return the first 50 with a note that the full list was truncated."

This delegation is ready to send: specific goal, clear scope, relevant background, structured output, and a defined stop condition.

Safety Notes

Sub-agent task delegations that include "fix" or "update" instructions (not just "identify") grant the sub-agent write access intent. Before delegating a writing task to a sub-agent, ensure: (1) the sub-agent is scoped to the right files, (2) the change type is specific (not "improve the code"), and (3) the sub-agent's output is reviewed before the changes are committed – just as with any AI-generated code change.

Log in and enroll to access lesson quizzes.

Scroll to Top