Ha Trong Nguyen
Available

TL;DR

  • Each new message sends the whole old conversation again. That is the main cost.
  • Twenty turns at 40,000 new tokens each use 8.4M tokens with late compacting, or 0.9M with early compacting.
  • A cheap model lowers the price per token. It does not lower the number of tokens.
  • Compact earlier, start a new session per task, and limit agents and tools running at once.

One afternoon, a developer’s agent used 196,387,999 tokens. The developer asked a few questions about a codebase. Nothing else was running.

The model was small and cheap, built for quick, repeated jobs.

The cheap rate helped a little. The amount of text sent to the model was the bigger number. Every coding agent works the same way: each new message includes the old conversation, and the model reads it again.

This post explains why that happens, shows the numbers with a small example, and lists the settings worth checking.

One rule to remember

A model request does not remember the last turn by itself. The tool you use must send the whole history again with the next request.

Some tools hide this by giving you a thread or a conversation ID. The older input still counts as input tokens.

The context window is the limit for one request. It counts input, output, and reasoning tokens together.

Compacting means replacing a long history with a short summary. That summary becomes the old text for the next turn.

Here is a tiny example.

Turn 1: “What does this function do?”

The agent sends the system message, the description of each tool, your question, the file it opens, and its answer.

Turn 2: “And the next function?”

The agent sends all of that again, plus the new file and the new question. Nothing was deleted in between. A short question can still use many tokens.

Rereading a stack of paper versus reading one compact card

Think of a book club. Someone asks a new question, and everyone rereads the whole book before answering. Twenty questions means twenty readings.

A cheap model lowers the price

Token cost has three parts:

cost = input_tokens × input_rate
+ cached_tokens × cached_rate
+ output_tokens × output_rate (including reasoning)

A cheap model lowers the three rates. It does not shorten the text you send. Send ten times more text and you pay about ten times more, even with the cheap model.

Most model guides say the same things. Higher reasoning effort uses more tokens and takes longer. A larger window lets a conversation grow before it is compacted.

Setting a window of 800,000 tokens costs nothing by itself. The cost comes when a session grows close to that limit before it gets summarized.

One example with two projects

Two projects, same model, 20 turns each. Each turn adds about 40,000 tokens from files, command output, and answers. The only change is when the history is compacted.

TurnProject A: compact at 800kProject B: compact at 100k
280,000 tokens80,000 tokens
10400,000 tokensabout 100,000 tokens
20800,000 tokensabout 100,000 tokens
Total for 20 turns8.4M tokens0.9M tokens
At $0.04 per 1M tokensabout $0.34about $0.04

The total is 40,000 × (1 + 2 + ... + 20), which is 8.4 million tokens. The 8.4 million comes from reading the same history twenty times. No single question is that long.

Late compaction versus early compaction

8.4 million tokens versus 0.9 million tokens

The money uses a round $0.04 (about 1,000đ) per million tokens. It is only a way to see the size of the number. Subscription plans usually do not send a token bill. They turn usage into limits that reset on a clock, often every few hours and once a week. You can check a prompt with a tokenizer, a tool that counts tokens.

Five things that push the number up

  1. A big window with a late trigger. If compacting happens only near the ceiling, every turn before it carries a huge block of old text. Most agents can compact automatically, and most also have a command you can run yourself. If the summary is 500 tokens, turn 11 starts with 500 old tokens instead of 400,000.
  2. One long session. Old tool output, failed attempts, and old reasoning stay in the history. A new session per task is often cheaper than one big cleanup.
  3. Subagents. Each agent has its own history. One request can turn into four token streams at the same time. Many agents expose a limit on how many can run at once.
  4. Tools and memory left on. Every request carries the description of each enabled tool, even unused ones. Memory features add extra model calls. Most configs have switches for both.
  5. Reasoning effort and keep-working modes. More reasoning uses more tokens. Some modes keep checking and continuing, which adds turns. More turns mean more rereading.

One agent fanning out into subagents with separate contexts

In my runs the order is: tokens per request, then number of turns, then agents and tools, then reasoning effort, then the model name.

What I measured

Local counters on one machine, 454 sessions:

SliceTokensAt $0.04 per 1M
All sessions8,097,416,417about $324
Small model, medium effort623,382,691about $25
Small model, low effort445,628,299about $18
252 subagent threads953,417,157about $38
One day206,250,422about $8
One codebase-reading session196,387,999about $8

Where the tokens went across measured sessions

These are token counts from one machine. They are not a price list and not a test of any product.

The local record does not store your quota, meaning the usage limit shown by the service. Logs show a limit update event with no number. The quota meter lives on the service side. The token record lives on your disk. Both are useful, and they show different things.

What to change

MechanismSetting to look forWhat it does
CompactingAuto-compact limit, compact commandMakes the old text smaller on later turns
Session boundariesNew session or new threadDrops old history completely
SubagentsMax agents at onceFewer histories at the same time
Tool catalogEnable or disable plugins and connectorsSmaller tool list on every request
MemoryMemory on or offFewer background calls
ReasoningLow, medium, highFewer reasoning tokens per turn

The names change from tool to tool. Look for context window size, auto-compact threshold, max agents at once, memory on or off, tool switches, and reasoning level. The idea is the same everywhere.

Things I would do first:

  • Compact at a fixed point, not at the ceiling. Leave at least 50,000 tokens of space.
  • Start a new session for each project or big task.
  • Keep subagents at one unless parallel work really saves time.
  • Turn off tools and memory you do not use this week.
  • Use low reasoning for lookups and small fixes.
  • Before you compact, write five short lines: goal, decisions, files touched, what is left. Paste them into the new session. Five hundred tokens of notes costs less than carrying 800,000 old tokens.

Check your counts again after a week. If the total still climbs at the same speed, the compact setting is not working. Look there before you blame the model.

References

General background, not tied to one product:

  1. Large language model, see the section on context windows.
  2. Tokenization.
  3. Prompt engineering.

The 196,387,999 token session and the 454-session totals come from a local token counter on one machine. The 8.4M versus 0.9M table is a calculation, not a measured run.