Spend-capped Claude Code sub-agent chains for debugging workflows
Teams using Claude Code for incident triage or code-quality sweeps should treat nested sub-agents as a configured workflow with a budget, an allowlist, and a depth rule. Claude Code v2.1.172 allows sub-agents to spawn sub-agents up to five levels deep, with each frame carrying its own prompt, model choice, and 200K-token context. That is useful for noisy jobs such as log search, where the parent session only needs a short verdict.
A practical setup is a project-level .claude/agents/<name>.md chain for one debugging path: an Opus triage agent, Sonnet repro agents, and Haiku leaf agents for grep, test generation, or log summarization. Each agent definition should use Agent() to name the only child agents it may spawn. Add a per-session spend cap before using the chain on production incidents. The article’s reported failures are large enough to justify this control: about 7x token overhead per branch per level, one user reaching 887,000 tokens per minute, and a reported $47,000 invoice after 23 sub-agents ran for three days.
The cheap test is one real incident replay. Measure tokens, wall time, number of spawned agents, and whether the parent session receives enough evidence to make a decision without raw log dumps.