🪞Composition

Skill calls subagent

Composition example: skill delegates heavy reads to an Explore subagent, keeps main context clean.

Surfaces
skill · subagent
Complexity
intermediate
Trigger
natural
Est. tokens
6,500

What It Does

A pattern, not a product. The skill body never reads source files directly; it constructs a structured prompt for an Explore subagent and consumes the subagent's short summary. Use this any time a step would otherwise load >20 files into the main context.

When It Triggers

  • "Find all usages of useAuth in the repo"
  • "Survey how pricing is calculated across services"
  • "Locate every call site of the legacy API"

SKILL.md

markdown
---
name: skill-calls-subagent
description: Example skill that delegates a heavyweight step (reading 50+ files) to an Explore subagent, preserving main context. Use when user says "find all X in the codebase" or "survey usage of Y".
---

# Skill Calls Subagent

## Pattern
The skill body never reads source files directly. Instead, it builds a
structured prompt for a subagent and consumes the subagent's short summary.

## Steps
1. Build subagent prompt: target pattern, paths to search, return shape
2. Invoke Explore subagent with that prompt
3. Consume the subagent's summary (typically <500 tokens)
4. Main agent proceeds with the summary as context

## Why
Subagent has its own 200k window. Main context stays clean even for
repo-wide scans.

Why Composition Matters

Reading 50 files into the main context inflates cost and pollutes reasoning. Delegation keeps the main agent's context focused on the decision, not the data. The subagent's context dies when its task ends; the main context never bloats.

Gotchas

  • Specify the return shape explicitly — "return JSON with fields path, line, snippet".
  • Subagents cannot call other subagents — flatten your delegation.
  • If the subagent's summary is over 2000 tokens, ask for a tighter schema.

Before you continue

We use analytics cookies to understand how the documentation is used and improve the experience. Privacy Policy.