How to Control AI Coding Costs: Look at Where the Tokens Go First

The biggest line on an AI coding bill is the model rereading the whole conversation on every turn. The code it writes is the small part. So before you switch to a cheaper model, shrink the context each session carries around. If you pay per token, you see this as a dollar amount. If you pay a flat monthly fee, you see it as a weekly quota that runs out too fast. The cause is the same, and the steps below apply to both.

Split the bill into its parts

Every time you send a message, an AI coding tool sends back everything before it: the conversation, the files it has read, the output of every command it has run. Tools cache this, and reading from cache costs roughly a tenth of normal input, so it looks cheap. But a session that has been running for hours can grow to several hundred thousand tokens of context, and that gets multiplied by every single turn. That multiplication becomes the largest charge.

Most tools keep a local usage log for every turn, split into four categories: input, cache writes, cache reads, and output. Adding up those four is far more useful than looking at the total.

We got this wrong once

At first we assumed the money was going to expensive models picked for subtasks. We had counted how many times each model tier was used across the subtasks we dispatched, and concluded that the cheap tier was barely used and we should use it more.

Later we counted differently. We took 14 days of usage, turn by turn, and summed the four categories. The result was completely different. Rereading and writing context made up over 80% of the spend, and model output was about 10%. The main session took nearly 80% of the total, and all subtasks together took 20%. The cheapest tier cost less than 1% of the total, so moving every subtask onto it would have saved almost nothing.

Counting calls does not show where the money went. That was the biggest lesson. One number stood out too: on average, each turn reread close to 500,000 tokens of context.

Three things that actually save money

Start a new session when a task is done. The test is whether the next task needs anything from the conversation you just had. If it does not, write the conclusions into a file, open a new session, and have it read only that file. A new session pays a cache write at the start, which costs more than ten times a cache read. So switching is not worth it when only one or two turns of wrap-up remain. It pays off when there are more than six round trips ahead. Do not switch in the middle of debugging either. What you tried and what you ruled out lives in the conversation, and losing it means starting over.

Wrap up before you walk away. Cache has a lifetime, anywhere from a few minutes to an hour depending on the tool and plan. If you leave a huge session open and go to a meeting, the first thing you say when you come back forces the whole context to be written to cache again. Over our 14 days, this full rewrite happened at least 800 times and accounted for more than 10% of the total spend.

Use the most expensive model only for judgment. The top tier costs twice as much per token as the one below it. If it stays with you through builds and log reading, about 90% of what you pay goes to rereading old content at double price. Keep it for planning, hard problems, and final review. Builds, test runs, and log digging are jobs where a mistake is easy to catch, so hand them to subtasks on a cheaper model and have the main session take only the conclusion. We compared the same wrap-up work once, and a mid-tier subtask cost about one fifth of what the top model cost doing it directly.

Do not overcorrect, though. We once forced every subtask onto the cheap model, and the tasks that needed judgment got pushed down and caused more rework. That story is in which rules belong in a rules file and which in a check script. Subtasks have their own overhead too, since each one reads the rules and background first, so a small job that takes two or three steps is cheaper to do yourself.

Let the numbers come to you

Cost creeps up slowly and you will not notice it by feel. We run a usage report once a week and look at two numbers: the top model's share of the total, and whether any single session was unusually expensive. If either crosses a line we set in advance, a notification goes to my phone. The report runs as a scheduled task, so I do not have to remember to look.

What to do

  1. Find your tool's usage log and add up the last two weeks by input, cache write, cache read, and output.
  2. Check how much context each turn carries on average. That number tells you more than the total cost.
  3. Keep a progress file for each project. A new session starts by reading it, so you do not depend on an old session's memory.
  4. When a task is done and the conclusions are in a file, switch to a new session. Do not switch in the middle of debugging, or when only one or two turns remain.
  5. Before you leave the computer for longer than the cache lifetime, finish the turn you are on.
  6. Default to the tier below the most expensive one, and use the top tier for planning, hard problems, and review.
  7. Send mechanical work to subtasks on a cheaper model, and state the tier every time.
  8. Once a week, look at the top model's share and the most expensive session. Set a line and investigate when it is crossed.

Sources

  • Per-category usage breakdown for 14 consecutive days of AI coding, 2026-07-10
  • Side-by-side cost test of new sessions versus old sessions, September to October 2026
  • Notes on how we adjusted model assignments, October to November 2026

Related

One email on Sundays with what I wrote that week: how I build and ship apps with AI, what it costs, and what went wrong. Unsubscribe any time.

RSS

I'm Jiang. I build apps with AI after my day job and write down how it goes. Four of the apps are free and open source on GitHub.