How to Set a Dollar Budget for a Fleet of Coding Agents
Coding agent bills are rising fast. LangChain's "Your coding agent bill doubled. Here's how to fix it." (Amy Ru, 2 Jul 2026) opens with an engineering lead whose bill grew six times in two quarters. Most of the controls on offer put the limit on a person or a key: a monthly cap per developer, a budget on a gateway key. That works for people at keyboards. It works less well for a fleet, where the useful question is "how much may this job cost?"
This guide shows how to put a dollar budget on a unit of work, a fan-out of agents, so the whole job stops when it has spent what you allowed. It also explains how the cost is estimated, because every figure here is an estimate.
In this article "factory" means a Forkit factory, a saved fan-out that can be run on request. It does not mean the company Factory.
Three places to put a limit
| Where the limit sits | Examples | What happens at the limit |
|---|---|---|
| A person or team over a period | Portkey's budgets per developer or team; LangSmith's LLM Gateway cost caps at user, team and org level | Depends on the product; see below |
| A key | Portkey virtual keys with a budget | The key expires |
| A unit of work | Forkit's --max-cost on a fan-out or factory |
Every agent of the job is stopped and settled |
Portkey's documentation for budget limits says a key that reaches its limit will "automatically expire the key to prevent further usage and overspending". Budgets start at $1 and can reset weekly or monthly, or not at all (read 25 Nov 2026). Its platform guide (24 Apr 2026) describes "hard budget limits" per developer or team but does not say what an agent sees when one is reached. LangChain's 2 Jul post mentions cost caps at the user, team and org level through its LLM Gateway, without saying whether they stop agents.
These are useful and they combine with a job budget. They answer a different question. A key budget fails model calls; the agent's session then ends in whatever state it was in. A job budget stops the job as a whole.
Step 1: Start a fan-out with a budget
forkit fanout create --name migrate-http --agents 20 \
--max-cost 10 --max-tool-calls 8000 --ttl 3600
This prints twenty keys once, as JSON. Start your agents with them, in sandboxes or on CI. A factory takes the same flag:
forkit factory create --name deps --prompt-file ./deps-prompt.md \
--agents 6 --max-cost 10 --push
Step 2: Know what happens at 80% and at 100%
From Forkit's engineering notes ("What agents cost, and budgets in dollars", migration v18):
- At 80% of the budget Forkit sets
cost_alerted_at, and fan-out views showbudget_warning. - At the budget, the fan-out is stopped in the same database UPDATE that adds the cost.
- It is then settled like any other stop: every request from its keys is answered with 403 and the reason, its pending permission requests are denied, its file claims are released, and its working and waiting threads move to idle. The Claude Code hook prints
continue: falsewith the reason and refuses the tool in hand.
There is one gap. Cost arrives in reports, and a report comes at the end of a turn or session and at most every 20 s during a turn. So a fan-out can pass its budget by what its agents spend in about 20 s. Set the budget with that margin in mind.
Step 3: Add a tool-call limit for agents that report no cost
A dollar budget sees only what is reported. Claude Code and Codex report through Forkit's hooks. Any other agent reports with forkit usage or POST /api/v1/usage, or not at all. An agent that reports nothing is invisible to the dollar budget.
--max-tool-calls covers that. It counts the fan-out's tool calls, so it stops agents whatever their cost reporting. It is counted in memory and written in steps, so it can overshoot by a few calls.
Use both. The dollar budget for spending, the tool-call limit as a brake that does not depend on reports.
Step 4: Report cost from other agents
For an agent without Forkit's hooks, report what each session used:
forkit usage --model gpt-5 --input 120000 --output 8000
or, when the agent tool gives you a cost directly:
forkit usage --model my-model --cost 0.42
A figure the agent gives is used as given. The HTTP form accepts providers' own field names too (prompt_tokens, completion_tokens, cached_tokens).
How the cost is estimated
Claude Code gives hooks no cost. Forkit's hook reads the tokens of every model reply from the session's transcript, and from its subagents' transcripts. A reply is written on several lines with one id, so each id is counted once, at its largest. For Codex, the hook reads the session file Codex writes, which holds running totals and the model.
Forkit then prices the tokens, in this order (CLAUDE.md, "Cost for any model", 21 Nov 2026):
- The agent's own figure, when a report carries
cost_usd. - A catalog of about 1,500 chat models in dollars per million tokens. A snapshot ships with Forkit, built from LiteLLM's public price file, and it is fetched again every day at 04:17 UTC, so a new model is priced without a deploy. A fetched price replaces a shipped one only within a fifth to five times it: a catalog that says a model is nearly free must not switch a budget off. Hand-checked Claude prices win over the catalog, and a
MODEL_PRICESsetting on the server wins over both. - An unknown model is priced at $10 in and $50 out per million tokens, and flagged. Pricing it high makes a budget stop early rather than late.
Checked once on staging with real Codex 0.160.1 sessions: the tokens Forkit counted equalled Codex's own total (31,731). That first check found the model name being forgotten when it was read before any count, which was fixed with a test.
Where the estimate is off
Every figure is an estimate. Forkit's notes list why:
- Prices are list prices. Discounts, committed-use deals and subscriptions are not known to Forkit.
- Cache writes are all priced as 5-minute writes.
- Tiered prices are not modelled.
- The Claude Code transcript format is one Anthropic's documentation calls internal, and could change.
Braintrust, which also estimates coding agent cost from traces, makes the same point: "Costs come from traced model calls and may differ from your provider's subscription bill" (7 Oct 2026).
So treat a Forkit budget as a stop for a job, set with margin, and reconcile with your provider's bill.
What a budget looked like in practice
Two recorded runs on staging, one run each, estimates at list price:
- Penguins study (20 Nov 2026): twelve Claude Code agents (Sonnet), each testing one hypothesis about the Palmer Penguins dataset in its own fork. Every agent had pushed 69 s after starting. The fan-out showed about $1.24 of its $10 budget.
- CO2 model comparison (21 Nov 2026): twelve agents started from a factory with a $10 budget. The run finished 63 s after it started at about $1.25, and
forkit factory showgave $1.25 and 63 s a run.
Neither reached its budget. A budget is for the run that goes wrong: an agent stuck in a loop, a prompt that sends twenty agents exploring.
Choosing a number
- Run one agent by hand and look at its cost on its thread.
- Multiply by the number of agents.
- Add margin for about 20 s of spending across all agents, and for retries.
- Set
--max-costto that, and--max-tool-callsto a count you would also call runaway. - After a few runs, read the cost per run from
forkit factory show(for a factory) or from the fan-out's totals, and adjust.
What is not covered
From CLAUDE.md:
- Agents that report nothing are not seen by the dollar budget. Use
--max-tool-calls. - Tiered prices are not modelled.
- OpenTelemetry is not a source of cost.
- A plan's monthly limits (agents a month, agents per fan-out) are separate from a dollar budget and apply when billing is enforced.
Related: how to stop a runaway agent, agent fan-out explained, coding agent cost tracking compared and estimating coding agent cost from transcripts.
Where Forkit fits
Forkit is the coordination system for agent teams: plans, handoffs, file claims and decisions, shared by every agent and the people behind them. A budget is one of those decisions, made once for a whole job. Forkit runs no agents; it stops the ones you started when the job has spent what you allowed. It is free to try at forkit-mcp.com.
Sources
- LangChain, "Your coding agent bill doubled. Here's how to fix it.", Amy Ru, 2 Jul 2026, https://www.langchain.com/blog/fix-your-coding-agent-bill (read 25 Nov 2026).
- Portkey, "Who owns Claude Code at your company? A platform team's guide", 24 Apr 2026, https://portkey.ai/blog/platfrom-guide-to-coding-agents/ (read 25 Nov 2026).
- Portkey documentation, "Budget limits", https://portkey.ai/docs/product/ai-gateway/virtual-keys/budget-limits (read 25 Nov 2026).
- Braintrust, "Optimizing coding agent usage and costs", 7 Oct 2026, https://www.braintrust.dev/blog/coding-agent-insights (read 25 Nov 2026).
- Forkit engineering notes (CLAUDE.md): "What agents cost, and budgets in dollars"; "Cost for any model", 21 Nov 2026; "The research demo", 20 Nov 2026; "The model-comparison demo", 21 Nov 2026.