All posts

Stop paying for code your agent already read

Nov 13, 2026 3 min read Oleg Savelev
costs architecture agents

Ask your billing dashboard what an AI coding agent actually does all day, and the answer is clear: it reads. The same files, again and again: config it saw ten minutes ago, helpers it re-opens every turn, a 2,000-line module where it needed one function.

The first bill-shocking number we measured: a reference harness across 10 agent tasks burned 169,761 baseline tokens; with local slicing and dedup the same work took 8,178, a net context reduction of -95.2%, with the worst single operation (-99.4%) being a full-file read that should have been a slice.

The three kinds of re-reading

  1. Full-file reads for one symbol. The agent asks for save_event() in src/metrics.py and the tool hands back the whole file, leaving 92 lines of unrelated helpers riding along as pure cost.
  2. Cross-turn repeats. Every new turn re-opens files the session has already seen. Nothing changed; the bytes are identical; the bill charges full price.
  3. Cross-agent repeats. Your teammate's agent, in the same repo, re-reads the same files from scratch. Multiply by seats.

Each is fixable locally, without sending code anywhere:

  • AST slicing keeps the target function and its 1-hop dependencies, and folds unrelated bodies into one-line typed signatures. Type contracts stay; noise goes. Sub-30ms, standard library parser, 10+ languages.
  • Diff-aware read cache keys on the SHA-256 of raw file bytes. Same bytes across turns or subagents hit warm cache; a real edit invalidates instantly.
  • Shared team cache (L3) lets the whole team reuse warm reads across a monorepo, so the second person to touch a module does not pay full price for it.

What a sliced read looks like

$ tokensafe smart-read src/metrics.py --symbol save_event
// 92 lines folded into signatures (-87% tokens)
def save_event(event: TelemetryEvent) -> None:  # ...
def estimate_tokens(text: str) -> int:           # ...

The agent still sees every symbol and every type contract it needs to edit safely. It just stops paying for bodies it never asked about.

The honesty split

We refuse to blend these numbers, and you should ask every vendor the same question:

Label Meaning This example
Measured Bytes actually kept off the wire 92-line file folded to signatures
Modeled Counterfactual baseline, labeled as such Full-repo crawl avoided: ~18k tokens

Baselines like "what an unsliced agent would have read" are modeled, not metered. The reference run baselines and turn speedup (+30.6%) are modeled too. The sliced byte counts are measured. That distinction is in every digest we ship.

Try it on one repo

npx tokensafe@latest init

Run a week of normal work, then open the Friday digest. Combine sliced reads with KV-cache prefix locking and pre-push security guardrails. You can inspect the AST architecture in our docs or invite your team for a 7-day team trial to share an L3 monorepo cache. If the measured numbers do not move your bill, uninstall. Everything runs locally, and telemetry goes dark with TOKENSAFE_TELEMETRY_DISABLED=1.

Your agent read that file once. Paying again for the same bytes is a bug in your tooling, not a law of nature.