anomalyco / anomalyco/opencode
[FEATURE]: Subagent fan-out is bounded by depth but not by breadth
@nexxeln is already working on this.
Since Jul 26, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
subagent_depth bounds how deep a subagent tree can go. Nothing bounds how wide it gets.
A subagent that spawns children in a loop will keep spawning — each child is a real session with real token spend — and the only thing that stops it is someone noticing. Depth 1 hides this today because subagents cannot spawn at all, but that is a side effect of the default, not a guard. Raising subagent_depth removes the only thing standing between a buggy prompt and unbounded fan-out.
The failure mode that matters is sequential, not concurrent: a subagent dispatching one child, waiting, dispatching another, indefinitely. A concurrent-only limit would not see it.
Suggested behaviour
A subagent_max_children config option, enforced at spawn time.
Two details that are easy to get wrong:
- Root sessions should be exempt. A root orchestrator legitimately dispatches hundreds of subagents over a long session. Capping that breaks normal use. The pathological case is a subagent spawning many children, not a human-driven root doing so.
- The count should be lifetime, not concurrent — otherwise the sequential loop above passes straight through.
Version
v1.18.5
Additional context
PR #38954 implements this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.