Stackness
Sign up
Runaway subagent cost in coding agents: what the $78,000 Codex report shows, a test for each cause and the caps that hold

Runaway subagent cost in coding agents: what the $78,000 Codex report shows, a test for each cause and the caps that hold

When a coding agent's bill jumps because it spawned hundreds of subagents, the most likely cause is nesting that no limit stops, made expensive by children that inherit the parent's model and effort. To tell, count the depth of the spawn tree in the local logs. In OpenAI's own issue tracker, Codex users reported trees 3 to 22 levels deep in July and August 2026, although Codex's depth setting defaulted to 1, because the newer subagent system ignores the depth setting. A depth of more than one or two, with every child on the parent's top model, is this cause. The fix is a depth cap in the harness, a count in a hook and a hard spend limit at the provider, because each of the three has failed on its own.

The $78,000 Codex report: what is claimed and what is checked

The $78,000 Codex report is one Hacker News post from 26 September 2026 by an account created about three hours earlier, and the post is now flagged. Its author, who names himself as Lorenzo Massaro of Eternal Tech, says a Codex task opened from VS Code on 10 July spawned 826 child tasks and that 162 invoices totalling $79,664.88 followed. Nobody else has seen his logs.

The Hacker News post, now marked flagged, titled OpenAI Codex agents go rogue and consumes USD 78,000 without authorization, by lorenzomassaro with 84 points. Its opening claims 826 parallel agents, nearly 2,146 trillion tokens and roughly USD 78,000. Below, a Codex task opened from VS Code on July 10, 2026 running GPT-5.5 at medium reasoning, whose root created 826 children recorded as GPT-5.6 Sol at ultra.

Screenshot of the Hacker News post by lorenzomassaro, 16 October 2026. Every figure in it is the author's own claim.

His other claims: the parent ran GPT-5.5 at medium effort, the children were recorded as GPT-5.6 Sol at ultra effort, and OpenAI support replied only that "credits were consumed". His figures disagree with each other. The post says "2,146 trillions tokens", a comment says 2,130 billion, and his per-build counters add up to about 162 billion. He also wrote that "these local token counters are not the authoritative OpenAI billing ledger". As of 16 October I found no OpenAI statement on the case.

What the GitHub issues confirm is the pattern, not the bill. In issue #32587, opened two days later on the same alpha build he names, a parent on GPT-5.6 Sol ultra "silently spawns every tool-backed multi-agent v2 child I inspected with the same model and effort". No public issue shows a cheaper parent producing pricier children, so his escalation claim remains unexplained.

Claude Code had its own version. In issue #68110, still open with no reply from Anthropic, users report one session that spawned 905 agents and "900+ agents" costing about $700 in 30 minutes on Bedrock, all self-reported.

Why does a coding agent spawn so many subagents?

A coding agent spawns too many subagents for one of six reasons, ranked here by how much of the public evidence each explains: nesting with no working depth cap, a concurrency cap mistaken for a total cap, children inheriting the parent's model, forked history, loops, and billing with no hard ceiling. The first two decide how many agents run; the next three decide what each one costs.

Fan-out is expensive even when it works. Anthropic measured its multi-agent research system at about 15 times the tokens of a chat, and Systima, which sells cost optimisation, measured Claude Code subagents at 2.6 to 5.9 times the input tokens of sequential work on one small task per model.

Codex's V2 subagents ignore the depth setting

The first cause is nesting that no limit stops. Codex's source code on 16 October still carries the comment "Maximum nesting depth for V1 agent threads. Ignored by V2." on agent_max_depth, and agents.max_depth has dropped out of the config reference. Reporters in issue #35463 found fork trees 4, 14 and 22 levels deep, one with 1,218 descendants in under 50 minutes. Claude Code versions 2.1.172 to 2.1.216 nested five layers deep with no setting to change it.

Test: count depth. Codex keeps spawn edges in its state database and per-session logs under ~/.codex/sessions; Claude Code writes each subagent's transcript to ~/.claude/projects/<project>/<session>/subagents/ (docs). Anything past one or two levels you did not ask for is this cause.

Fix: in Claude Code, set CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1 to turn nesting off; the default is 3 (docs). In Codex there is no working depth key for V2 as of 16 October, so block spawn_agent in a hook (below) or turn subagents off with features.multi_agent = false.

Concurrency caps count running agents, not the total

The second cause is a cap that limits agents running at once, not agents spawned. Claude Code fails a spawn with Concurrent subagent limit reached at 20 running, does not enforce that in ultracode sessions, and since v2.1.224 on 7 August 2026 has "no limit on the total number of subagents Claude can spawn over a session". Codex's agents.max_concurrent_threads_per_session also counts open threads, and its docs say only that when unset, "Codex chooses the default".

Test: many short-lived agents, never more than the cap at once, with the total in the hundreds.

Fix: lower CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS or Codex's agents.max_concurrent_threads_per_session, and count total spawns in a hook. Check third-party configs too: one reporter in #35463 traced a value of 1000 to a migration script from another tool.

Subagents run on the parent's model unless you pin them

The third cause is inheritance, which looks like escalation on an invoice. Codex's subagent docs say: "If you don't configure a subagent model or model_reasoning_effort, the subagent inherits the parent agent's model and reasoning effort." A parent on the most expensive model and effort makes every child as expensive, however small its task.

Test: read each child's model and effort. Codex records them in the child's log as turn_context.payload.model and effort; in Claude Code, a PostToolUse hook on Agent receives resolvedModel.

Fix: in Codex, set agents.default_subagent_model and agents.default_subagent_reasoning_effort. In Claude Code, set CLAUDE_CODE_SUBAGENT_MODEL to a cheaper model, such as haiku, and, from v2.1.257, CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1, which stops Claude passing its own model when it starts a subagent. The force flag on its own keeps every child on the main conversation's model.

Forked history makes every child re-read the parent's context

The fourth cause is children that start with a copy of the parent's conversation. In issue #38989, a run with 74 subagents recorded 5.39 billion tokens; the 30 started with forked history accounted for about 4.8 billion, against about 153 million for the 44 started without it. Most of it was cached input, which is billed at a lower rate, not free.

The same copying distorts the evidence. Child logs replay the parent's token history, so summing them overcounts: ccusage fixed a 91x overcount for Codex subagent sessions in issue #950. Check the provider's usage page before trusting a sum of local counters, in either direction.

Fix: ask for subagents without forked history unless the task needs it, and pass the files they need in the task instead.

Review loops and waiting loops spend without finishing

The fifth cause is a loop: review, fix and re-review rounds that never converge, or a parent repeating "Waiting for agents" until a usage limit stops it, as in Codex issue #33276. In #38989 the root stopped spawning when told "do not create any more subagents", which shows the instruction works once someone is watching.

Fix: a turn cap. Claude Code subagents take maxTurns in their definition, and print mode takes --max-turns, which has no limit by default (CLI reference). Orchestrate a fixed number of agents in a script when the job allows it.

Billing with no hard ceiling turns a bug into an invoice

The sixth cause turns the first five into money: nothing at the provider stops spending. OpenAI's ChatGPT credits reload automatically "up to any maximum monthly spend you set" (help), and the author of the Codex report says his invoices came through "Automatic Reload" and credits. On the API, OpenAI's spend alerts "do not enforce a cap", and its hard limit's "Enforcement is not instantaneous". Anthropic's Custom tier has no monthly spend cap (rate limits).

Fix: set a monthly maximum on automatic reload, enforce a hard limit per project on the OpenAI API, and set workspace spend limits in the Anthropic Console, where the Claude Code workspace also takes per-user monthly limits.

Put a cap in the harness, a hook and the provider

A budget guardrail belongs in three places, because each one leaks. Claude Code's --max-budget-usd stops new spawns with Budget limit reached and halts background subagents, but it checks a client-side estimate and works only in print mode; one user of the same cap in the Agent SDK logged "$20.95 of $20" from subagents already in flight. Codex's docs say to "Treat tool hooks as a useful guardrail, not a complete enforcement boundary." A paper on recursive harnesses shows the gap from the other side: when the parent writes a script that launches subagents through its shell, they bypass the per-turn tool-call cap and scale to thousands.

For Claude Code, this .claude/settings.json turns nesting off, allows four running subagents and blocks the 31st spawn in a session:

{
  "env": {
    "CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH": "1",
    "CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS": "4"
  },
  "hooks": {
    "PreToolUse": [
      { "matcher": "Agent", "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/cap-agents.sh" }] }
    ]
  }
}
#!/bin/sh
f="/tmp/agent-count-$(jq -r .session_id)"
n=$(( $(cat "$f" 2>/dev/null || echo 0) + 1 ))
echo "$n" > "$f"
[ "$n" -le 30 ] || { echo "Subagent cap of 30 reached for this session" >&2; exit 2; }

Make the script executable with chmod +x. Exit code 2 blocks the call and shows the message to Claude (hooks). Codex accepts the same kind of PreToolUse hook with the matcher spawn_agent (hooks), and its features.rollout_budget.enabled token budget is "under development and off by default". For traffic sent with an API key, a LiteLLM proxy adds per-key max_budget, which is unset by default and is skipped on a deployment without a database (budgets). It sees only the traffic you route through it with an API key.

Among the AI tools developers run beside their agents, ccusage, Langfuse, Orca and coucou show usage or send alerts, and none of them stops a spawn. None of them, nor LiteLLM, appears on a public Stackness stack yet as of 16 October 2026 (data sources), where Claude Code is on eight. The agent fleet post compares the consoles.

Log spawns, models and tokens per agent before you need them

An incident can only be reconstructed from data recorded while it happened, and the Codex report shows what is missing otherwise: its author says "most of the logs seem to have been automatically deleted". Claude Code deletes transcripts after cleanupPeriodDays, 30 by default. Raise it, and turn on OpenTelemetry before you need it.

  • Claude Code: CLAUDE_CODE_ENABLE_TELEMETRY=1 with OTEL_METRICS_EXPORTER=otlp exports claude_code.cost.usage and claude_code.token.usage, which can be split by subagent; beta tracing nests each subagent's spans under the call that spawned it (monitoring). Set these in the shell or user settings, since a project's settings file cannot turn them on.
  • Codex: OpenTelemetry export is off until you add an [otel] section to the user config, and it records a multi_agent.spawn metric by role (advanced config).
  • Both: keep the provider's invoice-grade usage export next to the local logs, since local counters are estimates.

If you see this, check that, fix it this way

You see Check Fix
Hundreds of agents from one request Spawn depth in subagents/ or Codex's spawn edges CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1; Codex: hook on spawn_agent or features.multi_agent = false
Never more than the cap at once, hundreds in total Total spawns per session Lower the concurrency cap; count spawns in a PreToolUse hook
Small tasks billed at top-model rates Each child's model and effort agents.default_subagent_model; CLAUDE_CODE_SUBAGENT_MODEL=haiku with CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1
Billions of cached input tokens Children started with forked history Spawn without forked history; pass files in the task
The same review or wait message over and over Turn counts per agent maxTurns, --max-turns, a fixed-size script
Invoices you never approved Automatic reload maximum and hard limits Reload maximum, per-project hard limit, workspace limits
A local token sum far above the bill Replayed parent history in child logs Trust the provider's usage page

New posts by email

About one email a week with what we published. No account needed.

One email to confirm first. Every email has a one-click unsubscribe.

Which of these do you use?

Nobody on Stackness runs GPT yet. Tick what you use and be the first.

Lonny skating the lakeside path, kickflipping onto a bench, grinding it and flipping offStackness gamesPlay Lonny Eagle Amateur Skater 4A pixel art skateboarding game. Signing up opens it straight away.+2 secret games you unlock as you goSign up to play