0008 - Agent Usage: Tokens per Run and Subscription Windows¶
Status¶
Accepted; amended 2026-09-26 (subscription limits come from the provider — see
Subscription limits); amended 2026-09-29 (the
runner refreshes Codex limits without a run, and holds a subscription proactively before it runs a
session dry — see Refreshing limits without a run and
Proactive session hold); amended 2026-09-30 (Claude limits are refreshed
between runs by a minimal probe call); amended 2026-10-02 (the Usage page shows what tokens delivered,
not only what they cost — see
Delivered points and the effectiveness index);
amended 2026-10-04 (agent-runner v0.5.5: a hold set by an actual limit message is lifted once a fresh
report shows room in every window and the hold's until falls after that report's own session reset —
see Usage limits); amended 2026-10-06 (the Usage page's headline effectiveness
indicator is the first-pass rate, beside the points index, and Codex's cached input is counted once — see
First-pass rate); amended 2026-10-13 (usage-limit hand-backs do not count toward
the three-in-a-row parking, and a usage_limit run holds its subscription on that runner until its
next heartbeat — see Usage limits).
Builds on ADR-0006 and ADR-0007.
Touched 2026-10-27 by ADR-0024 (accepted; task #1741): the organization's Team tab shows the API-equivalent cost this ADR records, per role and per subtree over the last 30 days, with triage runs as their own figure (Taskbase task #1764). Nothing new is recorded, and budgets per role and subtree stay deferred (ADR-0024 §7.5).
Date¶
2026-09-26
Context¶
Agent runs cost tokens, and we cannot see how many. Without that we cannot tell which kinds of task are expensive, whether a cheaper model tier would do, or what a review round costs.
The runners also bill against subscriptions — a Claude Max plan, for example — that limit use over rolling windows: a five-hour session and a week. When a window runs out, every run on it fails at once and its task lands in Blocked. The next task fails the same way, until someone notices.
Two constraints shape the design:
- Taskbase stays runtime-agnostic (ADR-0005). How usage is printed differs per agent program; Taskbase must store only neutral numbers.
- What a subscription has left is the provider's to say. Only the provider knows everything that counts against a subscription — interactive sessions and other machines included.
Decision¶
Usage per run¶
A run reports what it used when it finishes. Taskbase stores it on the run:
| Field | Meaning |
|---|---|
input_tokens |
Tokens sent to the model, not counting cache reads |
output_tokens |
Tokens the model generated |
cache_read_tokens |
Input tokens served from the provider's prompt cache |
cache_write_tokens |
Input tokens written to the prompt cache |
turns |
Model turns the agent took |
cost_usd |
Cost as the provider reports it, or null. For a subscription this is an API-equivalent figure, not money spent |
model_usage |
The same numbers per model, when one run used several |
Every field is null when unknown, never zero: an adapter that cannot read usage reports none, and a run that crashed or timed out reports none.
The run also records the model requested at claim time — the task's tier or model id, or the runner's default — beside the model it resolved to, so usage can be compared by tier even after a task's model is changed.
Reading usage is the adapter's job¶
Each runner adapter has an output format that turns the agent's output into the result text and the neutral usage:
| Output format | Reads |
|---|---|
text |
Nothing: today's behaviour; the output is the result text and usage is unknown |
claude-json |
Claude Code run with --output-format json: the result text and its usage, turns, cost and per-model usage |
claude-stream-json |
Claude Code run with --output-format stream-json --verbose: the same from its final result line, plus the subscription's limits from its rate_limit_event lines |
codex-json |
Codex run with codex exec --json: the usage — input, cached input, cache write and output tokens — from its turn.completed event, and the failure text from failed turns and errors; the result text comes from --output-last-message. The run's output carries no limits: the runner reads them from the Codex app-server's account/rateLimits/read right after the run, and between runs (see Refreshing limits without a run) |
A second agent program gets its own output format in the runner; Taskbase does not change. The summary, pull request link and review verdict (ADR-0007) are read from the result text as before.
Subscription limits as the provider reports them¶
A subscription — a Claude Max plan, for example — limits use over windows: a five-hour session and
a week. The provider reports how much of each is used with every run: Claude Code's streaming
output carries a rate_limit_event with each window's utilization and reset time, and a status that
warns as a window fills and rejects once it is full. These are the provider's own figures, so they count
everything on the subscription, not only this runner's runs.
The adapter's output format reads the latest report from each run and turns it into neutral windows:
{ "subscription": "claude", "provider": "anthropic", "status": "allowed_warning",
"as_of": "2026-09-26T10:41:13Z",
"windows": [ { "name": "session", "length_seconds": 18000, "used": 0.55, "resets_at": "2026-09-26T14:30:00Z" },
{ "name": "week", "length_seconds": 604800, "used": 0.95, "resets_at": "2026-09-28T20:00:00Z" } ] }
usedis a fraction of the window, as the provider gives it; Taskbase needs no token budgets.subscriptionnames what the adapter bills against — by default the adapter's name; adapters that share a subscription can name the same one.- The report carries
as_of, and the UI shows it, so a consumer can tell how old a snapshot is rather than assume it is current. Between runs the runner probes idle subscriptions, so it is normally no older than about twolimits_refreshintervals (with probes off, as old as the last run) — see Refreshing limits without a run. The runner keeps the latest report across restarts and sends it with every registration and heartbeat. statusis the provider's, normalised toallowed,allowed_warningorrejected.
Amended 2026-09-26: the first version had the runner keep its own ledger of the usage of its runs per rolling window, because a run seemed unable to learn the provider's figures. Claude Code's streaming output turned out to carry them, and they count what a ledger cannot. A ledger is deferred for providers that report no limits.
Refreshing limits without a run¶
A subscription's figures are only as fresh as the last thing that reported them. Until now that was
always a run's own output, so a subscription that a runner was not currently using could show hours-old
numbers. Taskbase #260 added a probe: at startup and then every limits_refresh (default 30m;
0 disables both the startup pass and the ticker), the runner asks each idle subscription's provider
for its current allowance and merges the answer into the same snapshot a run would have produced. A
subscription with a run in progress is skipped — the run's own report will be at least as current — and
a failed probe keeps the previous snapshot rather than erasing it. A probe that flips or changes a hold
sends a heartbeat immediately, the same as a run finishing at a limit; otherwise the new snapshot waits
for the next heartbeat like any other report (internal/runner/refresh.go).
- Codex: zero tokens. For an adapter whose
outputiscodex-json,agent-runnercalls the local Codex app-server'saccount/rateLimits/readover itsapp-server --stdioprocess, using the same logincodex execuses — no token or account identifier of its own, and no model turn (internal/adapter/codex.go). - Claude: a minimal call. Claude Code's interactive
/usagereadsGET /api/oauth/usage, which needs auser:profilescope the runner'sCLAUDE_CODE_OAUTH_TOKENsetup token does not carry (Taskbase #264), so there is no zero-token source. For an adapter whoseoutputisclaude-stream-json, the runner instead makes a one-word call and reads therate_limit_eventit returns (internal/adapter/claudeprobe.go): the adapter'ssmallmodel (else its first), no tools, no MCP servers, no saved session, in an empty directory, with the runner's setup token. A call at a full window fails but still reports the rejection, and the subscription is held as after a run. The runner skips this probe while a run's report on the subscription is younger thanlimits_refresh, so a busy runner makes none; only a runner that claims tasks (and so holds the setup token) probes Claude. - Why Claude spends tokens on it (decided 2026-09-30). An idle Claude subscription otherwise kept
its last run's figures indefinitely — a window a run had filled showed 100% used long after it reset.
A probe costs about a thousand tokens (around $0.002 API-equivalent on the small model), so at most 48
a day per idle subscription, against figures that are no older than about two
limits_refreshintervals. The trade-off: the probe counts against the subscription, and on an idle subscription it can start a new session window. This is revisited if Anthropic documents a usage endpoint that accepts a setup token, or another verified zero-token source (#264), which would replace the call. - How a future provider's probe fits in. A probe is keyed off the adapter's
outputformat, not its provider name, because that is what tells the runner which program it is talking to and what that program can answer outside a run. ALimitProbeis a plain function of an adapter to a*taskbase.Limit, ornilwhen the adapter has no source (internal/runner/refresh.go);RefreshLimitscalls it across every adapter, and the executor'sProbeLimitspicks the Codex or Claude probe by output format. A new output format with its own source adds its own case, the same way these did — no change to Taskbase, which only ever sees the resulting neutralLimit.
Usage limits¶
When a run's report says rejected — or the run ended because a window is full — the runner:
- Marks the subscription
limited_untilthe window's reset time (an hour from now when none is given) and keeps it across restarts. - While limited, the subscription's adapters are unavailable for claims. Taskbase skips adapters
whose subscription (or adapter name when omitted) has a future
limited_until, even if they remain in the report. Matching keeps reported order among available adapters: a tier may fall back to another provider serving that same tier; an explicit model id waits if no available adapter offers it. Expired holds are ignored without waiting for another heartbeat. Other runners carry on. - Finishes the run as
failedwith reasonusage_limit. Taskbase records the reason and requeues the task instead of parking it in Blocked. After three usage-limit runs of the same task in a row, it parks it in Blocked after all, so a misread limit cannot loop forever.
Amended 2026-10-13 (Taskbase #929, agent-runner #928): a run the runner hands back before its
agent starts — usage_limit with no usage, no context reuse, and finished within a minute of its
claim — requeues its task without counting toward the three in a row, and without breaking a row of
real limit hits; ten such hand-backs in a row still park it. After any usage_limit run, the
runner's adapters on that subscription are held for claims until its next heartbeat, which brings
its current limits. On 2026-10-09 a runner whose report still showed room handed back 18 runs in
3 s and parked six tasks. Details are in
Runners and Runs.
Clarified for Taskbase #258: claim-time filtering also enforces reported holds. This preserves the existing same-tier matching order and does not introduce ranking by remaining budget.
Amended 2026-10-04 (Taskbase #345): claim-time filtering also holds a subscription when an
administrator-set usage cap is reached: each runner can carry a session_max and week_max
(whole percentages) per subscription, and while the last reported used of that window is at or
above its cap, before the window's reported reset, the subscription's adapters are skipped exactly as
for a hold. The cap lives only in Taskbase and lifts by itself at the reset. It does not replace the
runner's own holds: limited_until from an actual limit, and the local hold_session_at floor
below, still apply, and whichever is reached first holds the subscription.
Details are in Runners and Runs.
Since Taskbase #1910 the cap is also sent to the runner in the heartbeat answer, so a runner with a
Claude API key offers the key while its login is capped (agent-runner #1909,
Claude API credit).
Amended 2026-10-04 (agent-runner v0.5.5): a hold from an actual rejection or limit message is keyed
to the window's own reset time, but a report can be late, missed, or — for Codex — come from the
periodic probe instead of a run, so the window can reset for real
before the runner hears about it, leaving the hold in place indefinitely. When a fresh report shows
every window with room and the hold's until falls after that report's own session reset, the
runner lifts it: the hold has clearly outlived the window it was protecting. A hold that does not
outlive the fresh report's session reset is left alone, and this never shortens a hold whose until
is still inside the window it is guarding (outlivesReport, internal/runner/limits.go). This is
distinct from the proactive session hold below, which always ends at the
session reset it is tied to and so is never lifted this way, and from the per-adapter hold
ADR-0006 added for a login failure or the
fast-failure circuit breaker, which takes out one adapter regardless of its subscription's limits.
Proactive session hold¶
The hold above only starts once a window is actually full: a run that begins with almost nothing left of the session dies mid-way at the limit, and the work is wasted. The owner decided (2026-09-29) to hold a subscription before that happens:
- When a subscription's session window has
usedat or abovehold_session_at— a fraction configurable per runner, default0.95(5% or less left) — the runner holds it back until the window's reportedresets_at(an hour from now when none is given), the same way it holds one that a run or probe foundrejected. This reuses the existing hold mechanism (limited_until), so it needs no new state on the Taskbase side: claim-time filtering (#258,match.go) already skips any adapter whose subscription is held, regardless of why. - It applies to both Claude and Codex, because both report a
sessionwindow through the samelimitBook.record— from each run and from the probe alike. The week window is out of scope for this rule. - A proactive hold never shortens a hold already in place from an actual rejection with a later reset, and the runner tells Taskbase about a new or changed hold with an immediate heartbeat, the same as after a limit hit.
- While a subscription is held this way, Taskbase gives same-size tasks to another adapter (#258) or they wait for the window to reset, exactly as for a rejection-based hold — there is no separate "proactive" state visible to Taskbase.
This landed in agent-runner with task #266 (internal/runner/limits.go). hold_session_at defaults
to 0.95 and must be greater than 0 and at most 1. This is a hold on the whole subscription,
distinct from the per-adapter hold ADR-0006 added
for a login failure or the fast-failure circuit breaker, which takes out one adapter regardless of its
subscription's limits. Unlike the hold from an actual limit message (see the
2026-10-04 amendment above), a proactive hold always ends at the session reset it is
tied to, so it is never lifted early by that rule.
What Taskbase shows¶
- On each task: the task carries its usage totals — its own runs, and its review tasks' runs apart — in the API and MCP, so any consumer can look into a task's consumption later. The task dialog lists each run with its usage; the board card shows a small cost figure.
- Per subscription: each runner card shows its subscriptions' windows — how much of the session and the week is used, when each resets, and how old the figures are — and "Limited until" while limited.
- Over time: a Usage page sums usage by day, model, requested tier, persona, project and runner,
and lists the most expensive tasks — the view for tuning which tier a kind of task gets. The same page also shows what those
tokens delivered: completed tasks, delivered points and the effectiveness index.
Accessed via the UI or
GET /api/organizations/{orgId}/usageand the MCPget_usagetool.
Taskbase ships each step before the runner does: strict decoding refuses a report with fields it does not know.
Delivered points and the effectiveness index¶
Tokens say what a day cost. They say nothing about what it bought, so two days of equal spend can look the same even when one shipped real work and the other burned itself out on a stuck task. The owner confirmed these definitions (2026-10-02):
- Completed: a task whose
done_at(tasks.done_at, set the momentdoneflips to true, by any path — see Taskbase — Database Schema) falls on the day, and that has at least one agent run recorded against it, implementation or review. A task a person finished without ever handing it to a runner does not count — there is no agent cost to weigh it against. A legacy review task's runs are folded into the task it reviewed, not counted again. - Points: the task's
complexity_pointsoverride (1–13,tasks.complexity_points) when a person set one, otherwise its own model tier at completion —small= 1,medium= 3,large= 8 — never the tier a run escalated to (ADR-0007, Taskbase #281): escalation is a sign the work cost more to finish, not that it was harder, so it must not inflate the points side of the index. A task pinned to an explicit model id, or left on the runner's default with no override, has no tier to read points from and is unsized: it still counts as completed, but contributes no points and is reported separately (unsized_completed_tasks) so it is not mistaken for free work. Only a person can set the override through the task API, MCP or UI; an agent's attempt is refused (403), since it would be grading its own work. - Effective tokens:
input + output + cache_write + 0.1 × cache_read, summed over every run — implementation and review, whenever it ran, even before the task's own completion day — of the tasks completed on a day. A task's full cost meets its full value exactly once, on the day it finished. Cache reads are charged at about a tenth of a fresh input token, and they are about 95% of tokens today; at full weight they would dominate every figure, so they count at0.1instead. - Effectiveness index: delivered points per million effective tokens of the tasks completed in
the period. It is
null, not0, for a period with no completions — a quiet day is a gap in the chart, not a day that looks free of cost. Points per dollar is the same points divided by cost, and isnullunless every run of every task behind it reported a cost (a Codex subscription run with no cost figure makes the whole period's points-per-dollar unknown, even though its tokens still count toward the index).
Why this is comparable across days: the cache-read weight keeps a single large cached run from dominating the figure the way raw token counts would; attributing a task's whole cost to the day it finished, not the days it ran, means a long task is not spread thin across several quiet-looking days nor double-counted; and pricing points by the task's own tier — never the escalated one — makes escalation show up as a worse index on a cost that stayed in place, rather than as more "delivered" value, which is the opposite of what happened.
On GET /api/organizations/{orgId}/usage and the MCP get_usage tool, total always carries
completed_tasks, delivered_points, unsized_completed_tasks, effective_tokens,
effectiveness_index and points_per_usd for the whole range. Each groups[] entry carries them too,
but only when group_by is day alone — grouping by anything else, including day paired with a second
dimension, omits them from that group, since a task's full value cannot be split across a dimension like
model or persona without double-counting it. See Usage Trends for the
full field reference and the Usage page's chart and table.
First-pass rate¶
Amended 2026-10-06 (Taskbase #447–#452). The owner said the effectiveness index "doesn't really show any relevant number". An analysis of 10 days of prod data (#448: 472 runs, 143 completed tasks) found why:
- It counted Codex tokens about three times over. Codex includes its cached input in
input_tokens, and the index added that in full on top of 10% of the cache reads. The index's daily swings (0.15–5.71) followed whether Codex ran, not the quality of the work. - 34% of completed tasks named a model id instead of a tier, so they scored 0 points.
- Tier barely predicts tokens (rank correlation 0.23), so points measure how the planner sized tasks.
points_per_usdwas almost always null, because Codex reports no cost.- Quality was not in it, yet rework roughly doubles a task's tokens (median 0.81M against 0.42M).
Decision (#449, option A): the Usage page's headline effectiveness indicator is the first-pass rate over a rolling 7 days. The points index stays beside it, unchanged except for the Codex correction.
- Passed first time: the task had one implementation attempt, which succeeded, no run of it was
escalated, and its round-1 review approved it. Runs that failed within 60 seconds (login, limits, an
unavailable adapter) are not attempts.
blockedcounts as not approved. - Rate: tasks that passed first time ÷ completed tasks with a round-1 verdict, over the 7 days up to
the range's end. "Completed" is the same as for the index:
done_atin the window and at least one agent run. Tasks without a round-1 verdict are left out and shown as a count. - Rework token share, beside it: effective tokens of implementation runs after the first attempt and of review runs after round 1, ÷ effective tokens of all runs of those tasks. Lower is better.
- Effective tokens everywhere (index, cohorts, rework share, model effectiveness) take Codex's cached
input out of its input once: fresh input = input − cache read for the
codexadapter.
It needed API and UI changes only, no migration and no runner change.
Why this indicator: it measures quality directly and does not depend on how a task was sized or on cost, which Codex does not report. Of the options (#448), the rework share of spend (B) had the same reviewer bias and was noisy when one task mixed Codex and Claude runs. A repaired points index (C) still measured the planner's sizing.
Known weaknesses: it depends on how strictly the reviewing model judges (in #448, Opus approved Opus
39 times out of 43 but Haiku once out of 10). It ignores cost. Daily counts are small, so read it with its
n. See Usage Trends for the fields.
What we deferred (and what would trigger adding it)¶
| Concept | Trigger to add |
|---|---|
| Choosing a model or runner by remaining subscription budget | Limits are hit regularly and tasks wait on one subscription while another has room |
| Money cost for subscription runs, not just tokens and API-equivalent cost | We compare a subscription against API billing, or add an API-billed adapter |
| Per-organization usage limits or chargeback | Several organizations share runners and ask who used what |
| Alerts on usage, e.g. at 80% of a window | We are surprised by a limit more than once |
| A runner-side ledger of usage per window | A provider reports no limits of its own |
| Rollup tables for usage queries | The Usage page gets slow |
| Points from a model's own complexity estimate | The tier proves too coarse to compare days |
| Reopened tasks as a quality signal | First-pass rate and review rounds miss work that comes back later |