Cost engineering

How to reduce AI agent token costs: a mental model for the recurring bill

Where tokens actually go on a recurring agent job, the formula behind the bill, and the one lever that takes the deterministic core to zero — the hub for Reelier's cost series.

The short version
  • 01An agent's token bill is calls/month × tokens/call × price/token — and on a recurring job all three are set by the schedule, not the work.
  • 02Most of what a recurring job spends re-derives a plan it already got right: a vendor benchmark restructured one workflow from ~150,000 tokens to ~2,000, mostly plumbing.
  • 03Record the deterministic core once, replay it at Level 0 for 0 tokens, and pay the model only for the judgment that actually changes run to run.

Every guide to cutting agent token costs eventually reaches for the same tactics: shrink the prompt, trim tool outputs, warm the cache, pick a cheaper model. Those work. They also optimize a number that, for one specific and common kind of work, could be zero.

This is the durable mental model for where agent tokens go, and the one lever that removes them from the part of a recurring job that never changes. It's the hub for a growing set of cost posts; the worked, priced-out tables live in the linked posts below, and this page is the map you read first.

The bill is a formula, and the schedule sets it

An agent's monthly token bill is not mysterious. It's arithmetic:

Fig. 1The same recurring job, re-run vs. replayed, over one month
$0$864$1,728LLM re-reasoningReelier replay · $01 self-heal ≈ $0.001, then $002,880 heartbeats / month

Cost is calls × 120k tokens × price on Opus 4.8 at a 15-minute cadence. Level-0 replay re-executes the recorded tool calls: 0 tokens by construction. Source: the tables above and the reelier benchmark.

calls per month × tokens per call × price per token.

Each factor traces to a real input, not a vibe. Calls per month is the schedule you chose. Price per token is published: Claude Opus 4.8 is $5.00 per million input tokens, Sonnet 5 is $2.00 (introductory, through Aug 31 2026; $3.00 thereafter), Haiku 4.5 is $1.00, from the Anthropic pricing page (retrieved 2026-07-21). Tokens per call is the one people misread — they assume it tracks the difficulty of the task, when on a recurring job it mostly tracks the context the session drags along.

The trap is that on a schedule, you don't set any of these to match the work. You set them to match the timer. A job runs every 15 minutes because you want freshness, not because the underlying task got 96-times harder per day. The bill scales with the schedule while the work stays the same size.

Most of what you pay for is re-derivation

Here's the uncomfortable part, and it's the vendor's own finding. Anthropic's engineering post Code execution with MCP walks through one tool-heavy workflow whose tool definitions and intermediate results moved about 150,000 tokens through context, restructured down to roughly 2,000 — a 98.7% reduction. The point was about how tool results flow through context. The admission underneath it is larger: on tool-heavy work, the overwhelming majority of what the model processes is plumbing, not judgment.

A recurring agent job re-derives the same plan on every run. It re-reads its instructions, reasons its way to the same sequence of tool calls it made yesterday, re-executes them, re-summarizes, exits. Tomorrow, the same trip. The output of all that reasoning is a tool-call sequence, and a tool-call sequence is data — the model paid full price to regenerate something that was identical the run before.

We measured a clean version of this. In the published benchmark, a live agent doing a small two-step npm-metadata lookup averaged 18,390 input tokens per run at $0.019068 per run. The task never changed between runs. That's a tiny task carrying a small context; a real cron job carries far more. OpenClaw heartbeats, documented at roughly 120,000 tokens of context per request, sit at the other end of the same axis. Either way the shape holds: the bill grows with context and schedule, both of which are about how the job is wired, not what it decides.

Split the job before you optimize it

The mental model that makes the bill fall is a split, and it's worth being precise because the fix only applies to one side.

Judgment work needs a model on every run: triaging an anomaly, writing prose for a human, deciding what a genuinely new input means, solving a workflow for the first time. If the right response changes run to run, that's what the model is for. Keep paying for it.

Re-derivation is everything else: the same sequence of tool calls, the same shapes, the same kind of answer, every time. Status checks. Metrics pulls. Feed diffs. Report scaffolding. CRUD sequences. Your agent already worked out these mechanics correctly once. Every later run pays it to re-derive them, with some probability of deriving them slightly differently — the drift problem wearing the cost problem's clothes.

Most useful recurring jobs are a thin layer of judgment on a thick layer of re-derivation. The economical shape is to make the re-derivation cost zero and spend tokens only on the layer that thinks.

The lever: record once, replay the part that never changes

The loop is record → compile → replay → diff.

Fig. 2Record once, replay the part that never changes
recordtool calls capturedcompileSKILL.md + assertionsreplayLevel 0 · 0 tokensdiffSAME / DRIFTED0 tokens✓ SAMEelse DRIFTED → exit 1

Record captures the real tool calls once. Every subsequent run replays them at Level 0 (0 tokens), emits a receipt, and diffs the result. Drift fails loudly. Source: the reelier benchmark.

  1. Record a run that worked. Where the platform keeps a scannable history, reelier scan reads it directly — Claude Code's ~/.claude/projects transcripts are the native format. Where there's no scannable history — Cursor keeps its history in a SQLite database, so there's no history scan for it — the recording proxy reelier mcp --wrap fronts the MCP server and captures every call losslessly while the job runs once as usual.
  2. Compile the trace into a SKILL.md: typed JSON in, typed JSON out, an assertion on every step it can check. Steps whose recorded result is clean get an assertion; steps that failed or returned nothing stay assertion-less and replay as unchecked — surfaced as open questions, never silently marked passed. It's reviewed like code, because it is code you commit to git.
  3. Replay with reelier run my-job.skill.md. At Level 0, the default, no LLM client is ever constructed: 0 tokens by construction, not by optimization. The skill re-executes the recorded tool calls against the live systems and checks each assertion.
  4. Diff with reelier diff my-job: SAME or DRIFTED, per step, exit 1 on drift with the failing assertion printed.

Three boundaries, stated before you ask, because they are the design:

Replay covers the deterministic core, not the judgment. Fetch-extract-assert work replays for free; triage, synthesis, and prose need a model every run and replay is the wrong tool for them. Model help during replay is opt-in, BYOK, and laddered: Level 0 never calls a model, --max-level 1 lets one re-read an already-captured observation to heal a stale assertion, --max-level 2 lets it re-execute a single read or idempotent-write step. A destructive step is never auto-escalated at any level. The aim of the ladder is to return the job to Level 0.

Replay is read-only by default, and the write gate is most of the safety story. An idempotent-write step re-fires only when you pass --allow-writes; a destructive step is stricter still and never re-fires without an explicit --yes. This matters more than it looks: in the measured corpus behind Reelier's launch writing, only 1.1% of scanned sessions were read-only end to end. Nearly every real job writes somewhere, so the write policy is not a footnote.

Drift fails loudly. That is the feature. When an upstream API changes shape, the replay doesn't improvise around it the way an agent quietly would. The assertion fails, diff names the step, the job exits 1. A scheduled agent that silently adapts to a changed API is a schedule you can't audit; a replay that goes red with a named failing assertion is a regression test.

The measured numbers

From the published head-to-head benchmark — same task, same live data, full method and raw tables:

Agent re-run Reelier replay
Tokens per run 18,390 in / 136 out (avg) 0 / 0 — verified from the run record, not assumed
Cost per run $0.019068 (avg) $0.000000
Latency per run 2,842 ms (avg) 48 ms (avg)
Output stability no structural guarantee 1,000 / 1,000 byte-identical (N=1000 tail-variance test)

Two honest notes, because "measured" has to mean something. The 0-token claim is asserted from each replay's run record (llmInputTokens === 0 && llmOutputTokens === 0) on every one of the 1,000 replays, checked programmatically. And in that N=1000 sample the agent arm produced no wrong outputs on this task — the claim here is cost, speed, and a byte-identical guarantee by construction, not an observed model-drift rate. We report what we measured.

Plug this back into the formula: the middle factor, tokens per call, goes to zero for the deterministic core. The schedule can fire as often as you like; zero times any call count is still zero.

This is the hub for the cost series

The mental model is the same across substrates; the priced-out arithmetic differs by how the job is triggered. The worked tables live in these posts, not duplicated here.

Priced out per runtime — the same formula, with each platform's real rate card and history-capture path:

  • What a scheduled Claude Code agent actually costs — why a recurring Claude Code job re-reads and re-derives every run, priced per model, and how reelier scan replays the deterministic core straight from ~/.claude/projects at 0 tokens.
  • Cursor background agents on a schedule — the $20 Pro plan plus overage billed in arrears at model API rates; because Cursor's history is a SQLite DB (no scan), capture goes through the reelier mcp --wrap proxy.
  • OpenAI Codex automations — scheduled tasks start a fresh chat every run, re-billing the whole job from cold; the rate-card math and how to replay the deterministic half off the model.
  • Windsurf Cascade workflows on repeat — the daily/weekly quota that replaced credits, overage at API pricing, and replaying a repeated Cascade workflow's deterministic core off-quota.
  • What OpenClaw heartbeats actually cost — the heartbeat version: a documented ~120k-token context, the per-model monthly table, and the caching caveat spelled out.

The cross-cutting cost posts — the formula, the calculator, and the regression it catches:

  • Heartbeat economics — why the bill of any poll or heartbeat is set by the schedule, not the work: calls/month × tokens/call × price, worked from cited inputs.
  • Scheduled agents at zero tokens — the cron-first version: Claude Code Routines, GitHub Actions crons, and a copy-paste workflow that gates on drift with exit 1.
  • The model update broke my agent — when a provider bumps the model underneath you, price and behavior both move silently; freeze the run, replay, and diff the drift into a red CI check.
  • A field guide to the agent cost calculator — what each of the calculator's three inputs means, how to estimate them from a real job, and why the replay column reads $0.00.

For the concepts underneath: Level-0 (zero-token) replay is where the zero comes from, deterministic replay is the umbrella practice, and headless agent is the unattended run this makes affordable. More cost posts hang off this page as the series grows.

Run your own numbers

Your schedule, your context size, your token prices: the agent cost calculator does the re-run vs. record-once-replay-forever arithmetic on your own inputs, with the replay column pinned at $0.

Or skip the arithmetic and check a receipt. Reelier's install demo closes with this, verbatim from the project README:

Reelier · replay receipt
Your receipt:
  skill:        reelier-init-demo
  steps:        2 total, 2 passed, 0 unchecked, 0 failed
  replay time:  44ms  [measured]
  LLM tokens:   0     [measured]

  An agent doing a comparable task re-reasons every run (~2.8s, ~18k tokens on
  our benchmark). Your replay: 44ms, 0 tokens.
* * * end of receipt * * *

Record the job once. Replay the part that never changes. Pay for judgment, not re-derivation.

sh
npm i -g reelier && reelier init

Sources

  1. Anthropic — Code execution with MCP — one workflow restructured from ~150,000 tokens to ~2,000 (98.7% reduction); plumbing dominates tool-heavy runs.
  2. Anthropic — pricing (retrieved 2026-07-21) — Opus 4.8 $5.00, Sonnet 5 $2.00 (introductory, through Aug 31 2026; $3.00 thereafter), Haiku 4.5 $1.00 per million input tokens.
  3. Reelier benchmark results — 18,390 input tokens/run (agent arm) vs. 0/0 verified on every one of 1,000 replays; $0.019068 vs. $0.000000; 2,842 ms vs. 48 ms; 1,000/1,000 byte-identical.
  4. NotebookCheck — OpenClaw token use (Feb 2026) — heartbeat checks documented at roughly 120,000 tokens of context per request.
  5. seldonframe/reelier — the open-source (AGPL-3.0) implementation; the Level-0 rule and write gates live in src/runner.ts and src/cli.ts.
code