Subagents, hooks and the cost of autonomy
For engineers
Subagents, hooks, MCP in the harness, and when multi-agent orchestration pays for itself.
Autonomy is a budget, not a switch: split work across agents only where the parts are independent, fence the agent with hooks and narrow tools, and measure what each extra agent costs before you scale it.
The case
Tallyfox Payments runs 58 small services. On 2 December 2026 an engineer, Priya, asks a coding agent (a Claude model in a terminal harness, though Cursor, Copilot or an open-weight setup behave the same way) to replace a deprecated chargeLegacy() call with payments.createCharge(). The new call needs an idempotency key, so a retry never charges a customer twice.
The first run looked impressive. The lead agent started twelve subagents, one per group of services. Within an hour three of them had edited the shared libs/payments-client in different ways, one had pushed a branch to the remote, one had read a ticket whose text told it to "also update the billing schema", and the token meter showed far more than anyone had planned. Nothing was lost, but nothing could be merged either. Six skills explain why.
What failed, and where
When to use many agents (multi-when). Searching 58 services for call sites is breadth-first work: each part stands alone and the answers can be merged. Changing the shared client is coupled work: every worker must see every other worker's decisions. Anthropic's write-up of its research system reports that agents use about 4 times the tokens of a chat and multi-agent systems about 15 times, so the split must earn that cost.
Subagents (harness-subagents). Each subagent has its own context, tools and model. The twelve workers had no narrow role: they inherited all tools, so an "auditor" could edit. Their briefs said "fix the payments calls" with no paths, no acceptance check and no return format. One report said "all fixed, tests pass" without a test run behind it.
Hooks (harness-hooks). The rule "never push" sat in a memory file and was ignored once. A hook is code the harness runs at a lifecycle event, such as before a tool call. A pre-tool hook that returns a deny decision is deterministic. An instruction is not.
MCP (harness-mcp). The team had connected a ticket server and a database server. Together they exposed 38 tool definitions, which were loaded on every turn of every worker. One ticket was written by a customer, so its text was data from outside and not an instruction.
Cost (harness-cost). Every worker used the strongest model at high effort, even for read-only search, and test output of thousands of lines flowed back into context. Nobody had a spend alert.
Orchestration (multi-orchestrator). The lead merged worker reports by pasting them together. A claim only one worker made, and no one checked, became part of the plan.
The working pattern
- Split the job. Fan out only the read-only inventory. Keep the client change in one agent.
- Define each subagent with one role, a tool allow-list and a model sized to the work.
- Brief each worker with goal, exact paths, acceptance check and return format.
- Add a pre-tool hook that denies
git pushand writes outside the worker's paths, and an after-edit hook that runs a fast check. - Connect only the MCP tools the task needs, read-only where possible.
- Run a small trial, read the token and cost report, then widen.
- The lead verifies claims by running the check itself and marks anything unchecked as unchecked.
Before and after
Before, the brief read: Fix the payments calls in the billing group.
After:
Goal: list every chargeLegacy() call in services/billing-*.
Scope: read only services/billing-*; touch nothing.
Return: JSON array of {file, line, has_retry_wrapper}. Say "not checked" for any path you could not read.
Stop when all 9 services are covered or after 30 tool calls.
What still goes wrong
- A hook that exits with the wrong code only logs a warning; the action goes ahead.
- A stop hook that fails the tests and blocks the stop with no loop guard can keep the agent running for hours.
- A repository you cloned can ship its own hooks and MCP servers, which run with your permissions.
- Cheaper models used for review can miss what a strong model would catch.
The questions that follow ask you to make these calls: what to fan out, what to deny, what to connect, what to measure and what to believe.
Steps
Decide what to fan out
List the work items and mark each as independent or coupled. Only the read-only inventory of call sites is independent. The new client, the idempotency key format and the retry policy are shared decisions, so one agent makes them in one place.
Work split for the migration Tallyfox migration, 2 December 2026 Work item Parts independent? Shared decisions? Plan Inventory call sites in 58 services Yes No Parallel read-only workers Rewrite libs/payments-client No Yes One agent Choose idempotency key format No Yes One agent, then written into the brief Update each service to the new call Mostly Uses the client's API Workers after the client is merged Define narrow subagents
Give each subagent one role, the fewest tools that do it and a model that fits. An auditor reads and reports; it does not edit. The brief states goal, exact paths, acceptance check, return format and a stop rule.
Auditor subagent definition .claude/agents/call-site-auditor.md
---name: call-site-auditordescription: Lists chargeLegacy() call sites in the services it is given. Read-only.tools: Read, Grep, Globmodel: haiku---Report file, line and whether the call sits in a retry wrapper.Reply with a JSON array. Write "not checked" for any path you could not read.Fence the agent with hooks
A pre-tool hook reads the pending tool call as JSON and blocks what must never happen. Exit code 2 denies the call and sends the message back to the agent. Exit code 1 only logs a warning, and the call goes ahead.
Pre-tool guard for Bash .claude/hooks/guard.sh
#!/usr/bin/env bashcmd=$(jq -r '.tool_input.command' < /dev/stdin)if echo "$cmd" | grep -Eq 'git +push'; then echo "Blocked: pushing is done by a person." >&2 exit 2fiexit 0Connect only the tools the task needs
Vet the server's publisher and source, pin its version, and allow only the tools the audit uses. Read tool descriptions as untrusted text, and treat ticket content as data. Every connected tool definition costs tokens on every turn.
Measure, then widen
Run the audit on 6 services first and read the cost report. Use a small fast model for search and a stronger one for the client change and the review. Trim test output to failing lines so it does not fill the context, and set a spend alert before the full run.
Merge only what was verified
The lead reads each worker report, removes duplicates, resolves contradictions and re-runs the acceptance check itself. A path a worker marked "not checked" stays open in the merged plan until someone checks it.
Skills this scenario uses
Where to study
- Create custom subagents (Claude Code docs) (opens in a new tab)DocsFree
How a subagent file sets role, tools and model, and how the lead delegates.
- How we built our multi-agent research system (Anthropic) (opens in a new tab)ArticleFree
Where parallel agents pay off, the token cost, and how workers are briefed.
- Hooks reference (Claude Code docs) (opens in a new tab)DocsFree
Lifecycle events, the JSON a hook receives, and what exit codes and decisions do.
- Manage costs effectively (Claude Code docs) (opens in a new tab)DocsFree
Where agent tokens go and the settings that cut them.
- Connect Claude Code to tools via MCP (Claude Code docs) (opens in a new tab)DocsFree
Adding servers, scopes, and the context cost of connected tools.
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Why to prefer simple workflows over agent teams until the task needs more.
- Prompt caching (Claude docs) (opens in a new tab)DocsFree
What a stable prefix is and which changes invalidate the cache.