Qalarc / Answers

How do I reduce AI coding agent token costs?

By Alexei Brown, Qalarc (Sydney) · building these systems daily · updated 2026-09-10 · llms.txt
Instrument a real session and you'll find what we did: most token spend is tool output — file dumps, command logs, test results — landing verbatim in context. Compress that boundary and every model, every session gets cheaper at once. We built an open-source plugin that does exactly this (QTK, on npm).

Where the tokens actually go

SourceTypical shareFixable by
Tool output in context60-80% (our instrumented sessions)Compression at the tool-to-context boundary
System prompt + rules5-15%Trim once, applies every turn
Conversation itself10-25%History truncation, summarization

Most cost advice targets the smallest slice. The lever is the boundary.

The three levers that work

1. Boundary compression. Rewrite tool output before it enters context: long file interiors become elision markers (…[217 lines omitted]…) that keep the model informed about what it ISN'T seeing, so it can re-request precisely.

2. Context budgeting. Cap retained output per tool call; let the agent re-run cheaply rather than carrying everything.

3. History hygiene. Summarize old turns instead of keeping them verbatim; agents rarely need the full transcript after a few turns.

Verify it yourself

QTK (open source, npm: @qalarc/qtk-plugin) implements boundary compression — per-session savings are charted on its project page. Run your own A/B: same task with and without compression, compare context usage, confirm task completion on YOUR workload. That last part is the only test that matters.

QTK — how it works npm package

When NOT to compress

Tasks needing exact output verbatim — precise diff application, tiny-file work, anything where an omitted line breaks correctness. Compression is for exploratory agent sessions, not surgical ones.