Skip to content
PathGuided

The 98 Percent Token Tax

Profiling 850 million tokens of local coding-agent telemetry reveals why compressing assistant prose barely moves costs, how naive context pruning breaks the KV cache, and what actually cuts spend without losing accuracy.

3 min read
Email

When teams try to reduce the cost of AI coding agents, they almost always start by telling the model to talk less. Strip out pleasantries, demand terse bullet points, compress the visible prose. The intuition feels sound, and it is almost entirely aimed at the wrong variable.

Before designing any cost-reduction interventions for our own agent runtime, we profiled seven days of local session telemetry: 145 sessions, 5,663 model calls, and roughly 850 million tokens. The breakdown immediately invalidated the prose-compression instinct.

MetricSharePrimary Driver
cacheRead98.04%Round-trip turns multiplied by prefix size
Uncached input1.48%New tool results and KV cache invalidations
output0.48%Internal reasoning tokens (50% to 67% of output)

Looking at transcript characters tells the same story. Tool outputs (read, bash, grep, find) accounted for 64.9% of all characters, internal reasoning for 16.3%, and structured tool calls for 15.8%. Visible assistant prose was just 2.5%. Even if you deleted every word the agent wrote to the user, you would barely dent the bill.

The real tax is structural: 98.04% of total token volume is the model re-reading its own growing conversation prefix on every turn.

The KV Cache Trap

Once you see that tool results drive context growth, the next instinct is to prune old tool outputs from the message history. We tested that directly in a controlled benchmark (spec-step-run, three dev scenarios on deepseek-flash under Seatbelt sandboxing).

It backfired decisively.

We implemented a careful watermark-masking strategy (S4) that only batched stale tool results once 24,000 characters accumulated, leaving recent results intact. Even with batching, mutating earlier messages triggered five KV cache breaks across three runs—compared to zero in the baseline. Because cached reads are roughly ten times cheaper than uncached input, every prefix mutation converted tens of thousands of cheap cached tokens into expensive uncached re-prefills. Uncached input jumped 83.3%, net cost rose 15.1%, and mean accuracy fell 18.9 percentage points (from 76.7% to 57.8%) because the model lost earlier file context.

Mutate prior messages (S4) Shrink file read cap 52 to 24 KiB (S5) Batch tools + concise first-pass reasoning (S1 v2 + S2) Growing Agent Transcript (98.04% cacheRead) Intervention Type KV Cache Prefix Invalidated Uncached Input +83.3% / Cost +15.1% Mid-file Truncation and Re-reads Reasoning +22.2% / Cost +7.5% 0 KV Cache Breaks / Fewer Turns Total Tokens -17.8% / Cost -9.8% / Parity Accuracy

A second intuitive fix failed for a subtler reason. Shrinking ingestion-time file-read caps from 52 KiB to 24 KiB (S5) preserved zero cache breaks, because it never altered past messages. Yet truncating large source and test files mid-read forced the agent into extra follow-up reads and reasoning confusion. Reasoning tokens rose 22.2%, cost increased 7.5%, and wall time climbed 13.0%.

What Actually Reduces Cost

The interventions that worked respected two constraints: never break the KV cache prefix on short-to-medium sessions, and never starve the model of contiguous file reads.

Instead, we combined two additive changes:

  1. Concise first-pass reasoning (S1 v2): A prompt directive bounding internal reasoning on initial implementation passes and tier-1 reviews, while leaving repairs, escalations, and final reviews completely unrestricted.
  2. Parallel tool batching and zero narration (S2): Instructing workers to batch independent read, grep, find, and stat calls into a single turn, omit pre-call narration, and stop speculative discovery once the target contract is found.
Engine reports view showing telemetry and cost metrics
Engine reports view showing telemetry and cost metrics

Evaluated across matched two-run averages against our two-run baseline, the composite branch delivered exact quality parity (76.7% mean accuracy, 1.5/3 scenario pass rate) while cutting total tokens by 17.8%, cacheRead by 18.2%, uncached input by 12.8%, model calls by 12.7%, reasoning tokens by 8.3%, total cost by 9.8%, and wall time by 8.3%—with zero cache breaks.

The lesson is straightforward. In agentic workflows, token economics are governed by round-trip turns and cache stability, not prose style. Cut the number of trips to the model, keep the prefix immutable, and save aggressive context rewriting for true long-context cliffs.

Join the PathGuided Closed Beta

Onboard your repositories with local-to-cloud spec execution, split-tier model routing, and commit-bound Work Tours.

Request beta access