TechniquecurrentRunning agents

Cap sub-agent spawns with a hook, and let the cap fail open

A hook caps spawns per session, and allows them if it breaks.

SymptomA session's transcript shows sub-agents spawning sub-agents, and the token budget empties mid-session.

Sub-agents with the full tool set can spawn sub-agents of their own, and a runaway swarm drains the token budget I share with everything else. Telling an agent in prose not to spawn will not hold a limit.

So a pre-tool hook counts every agent spawn in a session and denies spawns past a fixed cap. It fires no matter which agent makes the call.

It also fails open, so any error in the hook allows the spawn. A cost guardrail should never block legitimate work. Guards on sends, CRM writes and deletes fail closed.

The agents carry their own limits too. The builder and the checker have no spawn tool. The research agent is told not to spawn, and the session cap bounds it.

Large fan-outs I intend go through a workflow runner with its own concurrency and total caps.

Watchers get a funnel instead of a swarm. Each stage costs more than the last and sees only what the earlier stage couldn't settle:

  • Code prefilters by term overlap.
  • A Haiku pass labels what's left.
  • One Sonnet triage ranks by match strength.
  • Opus audits only on a match, scoped to the affected files.

A count can't tell an intended fan-out from a runaway one, so put a person at the cap to decide whether to raise it.

Check your setup read-only

Take the largest of your last 10 sessions by tokens. Count the sub-agent spawns in its transcript. Count only the tool-call records whose tool name is your spawn tool. Do not count the tool's listing or definition, which transcripts also carry. Count how many spawns came from sub-agents rather than the main session. Look in your hook config for a per-session spawn cap. Any spawn from a sub-agent with no cap behind it is a gap.

Passes ifNo sub-agent spawned another, or a per-session spawn cap in the hook config covers every spawn in the session.

Access needed:agent-transcriptslocal-config

If it fails: changes to make later (not part of the check)
  1. 01Count agent spawns per session in a pre-tool hook. Deny spawns past a fixed cap.
  2. 02Make a cost cap fail open: any error in the hook allows the spawn. Make guards on sends, writes and deletes fail closed.
  3. 03Note that hook errors and timeouts allow the call by default, per the Claude Code hooks reference. Configure fail-closed guards to block on failure.
  4. 04Give builder and checker agents no spawn tool.
  5. 05Route large intended fan-outs through a runner with its own concurrency and total caps.
  6. 06Put a code prefilter and a small-model labeler ahead of any large-model call in a watcher.
Applies ifAn agent's tool list or config in your setup includes a tool that spawns other agents.

← Back to the stream

For your agent

Each post has a read-only check your agent can run against your own setup. Paste this into a read-only session:

Never asks your agent to change anything · send anything anywhere · fetch other pages · run code · read something you can't.

What each rule means, and how it's enforced
  • Change anything. Every check is a question answered by reading. Each one names what it reads. The steps under “If it fails” are for you to weigh later, never part of a check.
  • Send anything anywhere. No post asks an agent to email, post, submit, upload or report back. Your results stay with you; sharing them is your call.
  • Fetch other pages. Post text carries no links, and no post tells an agent to visit one. The only URLs in the feed point to this site's own post pages.
  • Run code. Snippets are illustrations, not commands.
  • Read something you can't. posts.json is generated from this page, field for field. Nothing is hidden from a human reader.

A gate enforces these rules before every publish: it refuses links, instructions aimed at an agent, write verbs inside a check, hidden Unicode characters and any check without an "access needed" line. Each published version carries a version number and a sha256 fingerprint, so you can pin the version you reviewed. Every post is reviewed by a person before it goes out.

Feed version 1.0 · 2026-11-16 · sha256 88d19978389827b7…

Found something that breaks these rules? Tell me on LinkedIn.