A tool result has a position
Agent context is ordered. OpenAI documents prompt caching as prefix reuse. Stable instructions and earlier conversation turns can be reused when the prefix stays the same. Anthropic documents the same basic ordering across tools, system instructions, and messages, with cache reads and writes reported separately.[2][3]
That gives every test log, file dump, and search result two dimensions. Size matters. Entry time matters too. A six-thousand-token log added near the start of a twenty-call run can remain in the input for fifteen later calls unless compaction or another context policy removes it.
The expensive log is the one that enters early and stays hot.
Tokenleak turns the idea into suspects
Tokenleak is a new MIT-licensed Python project for Claude Code and Codex transcripts. Its audit labels large reads, noisy shell output, repeated reads, broad searches, and other patterns. The implementation estimates tool-result tokens at four characters each. It then estimates avoidable cost with provider-specific cache weights and the number of later calls in the same pre-compaction segment.[1]
The project calls these findings estimates, not verdicts. That boundary is correct. A large compiler error can be necessary. A short tail can omit the first failing assertion. Transcript formats change. Cache behavior and prices vary by provider and model.
We exercised the fixture, not the sales pitch
We inspected revision c88e195, release 1.5.1. The audit is one standard-library Python file. Its tests build synthetic Claude Code and Codex transcripts with large reads, repeated reads, noisy commands, compaction boundaries, and malformed inputs. The repository's documented command ran 25 tests on Python 3.11 and returned OK.
That result proves only that the included synthetic cases matched the checker at the inspected revision. We did not install the plugin, attach its hooks to an agent, read private transcripts, or reproduce the project's benchmark. Its reported cost reductions remain author-run results.
Keep the failure outside the model copy
A bounded command should preserve three things. Keep the command's exit status. Keep the complete output at a named path. Print a small tail or focused match into model context. Do not pipe the only run into tail and lose the real status.
run_id=$(date -u +%Y%m%dT%H%M%SZ) log=".agent-logs/test-$run_id.log" mkdir -p .agent-logs set +e npm test --silent >"$log" 2>&1 status=$? set -e printf 'exit=%s full_log=%s\n' "$status" "$log" tail -n 80 "$log" exit "$status"
The model sees the status, path, and recent output. A reviewer can open the full log if the tail is ambiguous. Put the log directory in the project's ignore file if it is local evidence. Set a retention rule if the output can contain secrets or user data.
Measure before and after
- Choose representative work, not one polished demo.
- Record input, cached input, cache writes, output, calls, wall time, and task result.
- Change one output rule at a time.
- Replay the same acceptance check.
- Inspect misses. A cheaper wrong answer is still wrong.
- Keep the rule only when repeated runs preserve the result.
The dyno below models repeated input volume. It does not calculate a bill. Provider caching, compaction, hidden instructions, and model pricing remain outside the fixture.