nested-subagents
What it does
This skill guides an agent to build a tree of sub-agents, up to five levels deep, for large problems that would overload one agent's memory. It is for people with complex tasks that break into layers.
When to use it
- βWhen a problem breaks into layers such as research, expansion, checking and summary.
- βWhen one agent's context would not hold all the intermediate work.
- βWhen different parts of the work need different specialist roles.
Skill link
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-agent/skills/nested-subagents/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βBreak this market research into layers, with sub-agents researching, verifying and then summarizing each part.β
5 new skills a week. 1 minute to read.
How it works
The agent starts a coordinator, which plans the tree of tasks first, then creates child agents that can create their own children within the depth limit.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Nested 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
FAQ
Why use nesting instead of running agents side by side?
The skill says nesting is for managing context, not for speed, since each level has a fresh context window.
How deep can it go?
Up to five levels deep.
When should I skip it?
The skill says to skip it when a simple set of parallel tasks is enough, because nesting adds time.
Details
Original description by the author
Spawn nested sub-agents (agents that spawn sub-agents, up to depth=5) via Claude Code's native Task tool β for context-managed deep delegation
repo: ruvnet/ruflo
Popularity
- GitHub stars
- 81k
- Ranking position
- #1558
- License
- MIT
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
agent-adaptive-coordinator
81kHelps your agent split and rebalance a group of AI agents as the workload changes, choosing a layout that fits the task.
agent-agent
81kTeaches your agent to turn a big goal into an ordered plan of actions, and to replan when conditions change.
agent-agentic-payments
81kHelps your agent manage spending mandates for AI shopping, with spend caps, time windows, merchant rules and signed approvals.
agent-analyze-code-quality
81kHelps your agent review code for quality, finding code smells, technical debt and refactoring ideas without changing the files.
Similar skills
add-model-provider
394kLets your agent connect a new AI model provider to OpenClaw using safe setup commands, keep API keys out of plain text, and run a live test.
acp-router
394kHelps your agent send a task to a coding assistant such as Claude Code or Cursor through OpenClaw, so the work runs in that tool.
browser-automation
394kTeaches your agent to control web pages step by step, including logins, tabs, and recovery when a page stops responding.