
Nested Sub-Agents
FreeManage complex tasks with context-aware delegation.
Free · Opens the source repo
What Nested Sub-Agents does
Nested Sub-Agents enables the spawning of a hierarchy of sub-agents, allowing for deep delegation of tasks while maintaining context isolation. This skill is particularly useful when a problem can be broken down into multiple layers, such as research, expansion, verification, and synthesis. Each sub-agent operates within its own context window, preventing the clutter of intermediate states from overwhelming the top-level agent's context budget.
To utilize this skill, you start by invoking a top-level nested-coordinator, which will decompose the problem into a structured tree of tasks. The coordinator lays out the spawn tree using TodoWrite, allowing you to inspect and approve the structure before any deep work begins. Each child agent can further spawn its own children, creating a multi-level hierarchy that is well-suited for complex tasks requiring specialized handling at different levels.
The context isolation feature ensures that the top-level coordinator only receives structured summaries from its child agents, preserving the clarity and focus needed for effective task management. This approach eliminates the need for re-summarization that can occur with flat fan-out strategies, allowing for deeper delegation without losing track of the overall task structure. Additionally, the tree shape of the delegation provides clear cost attribution, enabling better resource management and understanding of the task flow.
This skill is designed for developers and designers who need to manage complex workflows efficiently, particularly when dealing with tasks that require multiple specialized agents. By leveraging nested sub-agents, users can maintain a clean context while effectively delegating responsibilities across different layers of their projects.
When to use it
Use this skill when a task can be broken down into nested layers that require specialized handling at each level.
When not to use it
Avoid this skill if a flat delegation approach suffices, as nesting can introduce unnecessary latency.
What you can build with it
Complex Research Projects
When managing a multi-phase research project, use nested sub-agents to handle each phase's specific tasks without losing context.
Specialized Task Handling
For tasks that require different types of agents at various stages, such as testing and verification, utilize nested sub-agents for clear delegation.
Cost Management in Delegation
When tracking costs associated with different phases of a project, the tree structure of nested sub-agents allows for precise cost attribution.
How to install Nested Sub-Agents
View source1. Install with the skills CLI
npx skills add ruvnet/ruflo/nested-subagents --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by ruvnetNested Sub-Agents
Spawn a tree of sub-agents where each child can itself spawn children, up to 5 levels deep. The motivation is context management, not parallelism: each level gets a fresh context window so deep work doesn't blow the top-level agent's context budget.
When to use
- The problem decomposes into nested layers (research → expand → verify → synthesize), each of which would otherwise pollute the parent's context.
- A single agent's context window would not be enough to hold all the intermediate state.
- The leaves of the tree are different
subagent_types and need their own specialized prompts (e.g.,pii-detectorat one leaf,testerat another).
Skip this skill when flat fan-out (Task × N in one message) suffices — nesting adds latency.
Steps
-
Invoke the coordinator — spawn
nested-coordinatoras your top-level agent:Task({ subagent_type: "nested-coordinator", name: "root-coordinator", description: "Decompose and delegate <problem>", prompt: "<problem statement, with constraints and expected output shape>" }) -
The coordinator decomposes first — it lays out the spawn tree via
TodoWritebefore anyTaskcall. Inspect the tree before approving deep work. -
Children spawn children — any
nested-coordinator(or any other agent whose YAML frontmatter declarestools: [..., Task]) can itself callTaskto spawn the next level. Leaf agents (withoutTaskin their tools list) cannot. -
Each level reports a summary — children return ~200-token structured summaries, not full transcripts. The whole point is to keep the parent's context clean.
-
Tree shape is persisted — the
post-taskhook writesparent_agent_idanddepthto AgentDB on every spawn (ADR-147 P2). Query after the run for cost attribution and pattern learning.
Depth budget
| Source | Limit |
|---|---|
| Anthropic API | 5 levels (announced 2026-06-09) |
Ruflo default (pre-task hook) | 4 levels — one-level guard band, configurable in claude-flow.config.json |
| Strict-mode env var | CLAUDE_FLOW_STRICT_NESTING=true to enforce the ruflo cap |
The hook returns a typed NESTING_DEPTH_EXCEEDED error at the cap, with the full chain in the payload so the parent can decide to summarize, hand off, or abort.
Benefits
- Context isolation per level — top-level coordinator never sees inner chatter; leaf summaries climb back up.
- Deeper delegation without re-summarization — eliminates the "summarize at level 1 to fit it all" anti-pattern that flat fan-out forces.
- Tree-shaped cost attribution —
parent_agent_idlineage gives accurate per-tree spend, not just flat per-agent. - Maps cleanly onto ruflo's existing orchestrators —
ruflo-sparc:sparc-orchestrator(5 phases ≈ 5 levels),ruflo-goals:dossier-investigator(recursive entity expansion),v3-queen-coordinator(hierarchical-mesh top).
Anti-patterns (do NOT)
- Pass
Taskto leaf agents. Leaves must not spawn. Add the leaf'ssubagent_typedirectly under the coordinator instead. - Wrap a Tier-1 codemod in a coordinator. Codemods (
hooks_codemod) are depth-0 deterministic transforms — never put them inside a spawn tree. - Nest "for cleanliness". A premature nesting layer wastes latency and cost without saving context. If one agent can do the work, use one agent.
- Return full transcripts from a child. That defeats the entire purpose of nesting. Children return structured summaries.
Related
- Agent:
ruflo-agent:nested-coordinator— the orchestrator - ADR-147 — design rationale and four-phase rollout
- ADR-144 — authorization propagation shares the depth counter as
AuthScope.delegationDepth - ADR-099 — dossier investigator (recursive parallel research) is the textbook deep use case
Frequently asked questions about Nested Sub-Agents
Similar skills
Agent Skill Stack
Assemble compatible AI Agent Skills for workflows.
AI Team Orchestration
Streamline multi-agent development workflows.
Advisor Orchestrator Worker
Efficiently manage complex tasks with multiple AI models.
Agent Orchestrator
Automate multi-agent workflows with zero manual intervention.
Agent Governance
Implement safety and trust controls for AI agents.
Microsoft Foundry
End-to-end management for Microsoft Foundry agents.
