Starts Nov 23Live Cohort 3 of Vibe Coding & AI Agents (Nov 23, 18:30 MSK): 3 weeks, 9 live hands-on sessionsCohort 3 (Nov 23) →
ReleaseInsight · On RadarHabr AI→ original

7% of AI agent sessions in a code editor burned 74% of tokens over 90 days

Over 90 days, the author tracked an AI agent's usage in a code editor. The 38 long sessions out of 518 (7%) consumed 74% of input tokens: 7,371 million out of 10,026 million. The reason is that on every step the model rereads the entire history, like a colleague who scrolls back through the whole chat from day one before each reply. That is why, after 100–150 steps, it is cheaper to save a summary and open a new session.

AI-processed from Habr AI; edited by Hamidun News
7% of AI agent sessions in a code editor burned 74% of tokens over 90 days
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1On the worst day, usage hit 417 million tokens against a limit of 165 million
That day, 36% of messages were repeats160 million tokens wasted
Key metric #3The rule "three empty calls in a row — stop" halted the "carousel"

Tokens are the chunks of text you pay for when working with a neural network, and input tokens are everything the model reads before producing its next reply. The author delegated routine work to Kilo Code, an AI agent that lives inside the code editor (IDE), and for 90 days tracked its usage: 518 working sessions, about 35,000 steps, 10,026 million input tokens. It turned out that the 38 longest sessions (that is, 7% of 518) consumed 7,371 million tokens, or 74% of all usage. The remaining 93% of sessions fit into the other quarter of the budget.

Where the problem came from

The agent drafts technical specs from meeting notes for the author, parses logs, fixes scripts, converts spreadsheets and prepares minutes. Evening work started taking an hour. But at the end of October, the counter showed 417 million input tokens in a single day against a daily limit of 165 million, which is 2.5 times over. An hourly breakdown revealed the cause: 36% of that day's messages were repeats of work already done, and 160 million tokens were spent for nothing. After that, the author set up a local service on top of the log that Kilo Code writes to SQLite.

Why long sessions get expensive

From the outside, the agent looks like a chat, but internally on every turn the model receives the entire history: files it has read, command output, its own previous replies. It is like a colleague who rereads the whole correspondence from the first day before every message, while you pay for it. In a simplified model, a session of n steps costs roughly n²/2. In reality, growth happens in steps and is smoothed by caching, and fitting the medians gives an exponent of 1.44, which is gentler than a square. The principle is the same: the tail of a session is more expensive than its beginning.

Numbers from the log:

  • 449 sessions of up to 150 steps (87% of all) consumed only 14% of tokens, 1,382 million.
  • 69 sessions longer than 150 steps consumed 86%, or 8,644 million.
  • Each block of 10 steps in the 101–150 range costs 1.5 times more than in the first hundred.
  • For the giants with 251+ steps, each block of 10 steps costs 4.3 times more than in the first fifty.

There is a nuance about money: 95% of the volume came from cache reads, which are billed more cheaply than new input. That means the millions of tokens in the log cannot simply be multiplied by the standard price; the limit has to be recalculated using the provider's price list. Even with the discount, rereading a bloated context consumes most of the budget.

The longest session reached 595 turns on a fast, budget model. By the end, the model had lost the constraints set at the start, and the result had to be redone. A long session hits the budget first and then quality.

Rules that worked

  • A step counter instead of a timer. The author broke the "check once an hour" rule three times, so control was tied to every tenth step.
  • 100 steps is a checkpoint, 150 is a stop. At turn 100, the task state is recorded in project memory; at step 150, the session is closed and a short summary ("what's done, what's left, the next step") goes into a new window.
  • Three empty or repeated calls in a row means a full stop. This cures the "carousel," where the agent reverts an edit and repeats nearly the same thing. Afterward, the approach must change: move the search into a subagent or start with a clean context.
  • Search instead of reading whole files, and a 45% cut to the system prompt: startup instructions are paid for on every step of every session.
  • Budget models only for short tasks: format conversion, text summarization, running a finished script.

Ceiling estimate: if all 69 long sessions had been cut off at step 150, they would have consumed 2,124 million instead of 8,644 million. Savings of up to 6,521 million, or 65% of the whole window. In practice, it is less, because a new session needs starting context (the "handoff cost"). Cutting too early, say every 20 steps, is also not profitable.

How to check your own usage

The method works for any tool that stores tokens and message timestamps. For Kilo Code, this is the local file kilo.db. Claude Code, Cursor, or Codex keep their logs differently: some offer an export, others show only total billing. Without access to a log, controlling usage is nearly impossible.

Two SQL queries are enough: total usage for a period and the top 10 heaviest sessions. If the 5–10% longest sessions account for more than half of the tokens, you have the same bloated tail.

The limitation is obvious: this is data from one person, one agent, and one type of task. The thresholds of 100 and 150 steps were tuned to his workflow, so teams should find their own numbers. The pattern itself follows from how context works and should reproduce for most users.

Story

Key Questions Answered

Where the problem came from?

The agent drafts technical specs from meeting notes for the author, parses logs, fixes scripts, converts spreadsheets and prepares minutes. Evening work started taking an hour. But at the end of October, the counter showed 417 million input tokens in a single day against a daily limit of 165 million, which is 2.5 times over. An hourly breakdown revealed the cause: 36% of that day's messages were repeats of work already done, and 160 million tokens were spent for nothing.

Why long sessions get expensive?

From the outside, the agent looks like a chat, but internally on every turn the model receives the entire history: files it has read, command output, its own previous replies. It is like a colleague who rereads the whole correspondence from the first day before every message, while you pay for it. In a simplified model, a session of n steps costs roughly n²/2. In reality, growth happens in steps and is smoothed by caching, and fitting the medians gives an exponent of 1.44, which is gentler than a square.

What are the key details on Rules that worked?

A step counter instead of a timer. The author broke the "check once an hour" rule three times, so control was tied to every tenth step. 100 steps is a checkpoint, 150 is a stop. At turn 100, the task state is recorded in project memory; at step 150, the session is closed and a short summary ("what's done, what's left, the next step") goes into a new window. Three empty or repeated calls in a row means a full stop. This cures the "carousel," where the agent reverts an edit and repeats nearly the same thing.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…