# How I cut token usage in Kage, my always-on AI agent

> An always-on AI agent pays every time it wakes up and for everything it reads. How Kage wakes less and reads less: tripwires, thread deltas, long-output cuts and shadow twins, each checked against the same 20 real tasks.

URL: https://alokranjan.me/blog/always-on-ai-agent-token-usage/
Author: Alok Ranjan
Date: 2026-11-23
Tags: AI agents, LLM, context engineering, prompt caching, Kage

<div class="tldr">
<p><strong>TL;DR</strong></p>
<ul>
<li>Kage wakes the AI only when something changed. Its <strong>tripwires</strong> check first with no AI: a new post, a webhook, or a <strong>probe</strong> script on a timer. A quiet job costs close to nothing.</li>
<li>In a long chat, Kage sends only the <strong>thread delta</strong>: the messages the session hasn't seen. Long command output keeps only its start and end, so a task with long test output reads 36% fewer tokens per turn.</li>
<li>A teammate's quick question loads only what it needs, not the owner's full setup.</li>
<li>A cheaper job replaces an old one only after its <strong>shadow twin</strong> has agreed with it.</li>
</ul>
</div>

## Meet Kage

<div class="kage-mark" role="img" aria-label="Kage, your shadow, at work"><span class="kage-cast" aria-hidden="true">kage<span class="shadow">kage</span></span><span class="kage-tag" aria-hidden="true">your shadow, at work</span></div>

Everything in this post was built and measured in [Kage](https://github.com/aloki-alok/kage), an always-on AI agent I built. It isn't just mine anymore: my whole team works with it every day. Last week it handled about 2,400 tasks and job runs, around 350 a day. Think of it as a teammate who never logs off. You reach it wherever you already work: Slack, WhatsApp, email, a phone call or a GitHub issue, and it joins your calls and meetings as a guest. It does the work with your tools and your access: it uses your browser, works in your code, runs scheduled jobs and acts on alerts.

<figure>
<div class="kthread" role="img" aria-label="A Slack thread: you ask Kage to watch the deploys channel. Kage replies that each new post wakes it, so nothing checks in between.">
  <div class="kchan">#deploys ▸ thread</div>
  <div class="kmsg"><b>you</b><span>@kage watch this channel and tell me if a deploy fails</span></div>
  <div class="kmsg kbot"><b>kage 🥷</b><span>Watching #deploys. Each new post wakes me up, so I'm not checking every few minutes. I'll reply here when a deploy fails.</span></div>
  <div class="kmsg"><b>you</b><span>@kage what did yesterday's failed deploy change?</span></div>
  <div class="kmsg kbot"><b>kage 🥷</b><span>It renamed <code>order.total</code> to <code>order.amount</code>. Three places still read the old name. The fix is on branch <code>fix/order-amount</code>.</span></div>
</div>
<figcaption>what working with kage looks like. a made-up thread, not real data</figcaption>
</figure>

On a normal day Kage:

- answers in Slack and WhatsApp threads, knowing our code and our tools,
- runs scheduled jobs and **kagelets**, small standing agents that each own one recurring job, and keeps an eye on channels and alerts,
- takes tasks from teammates, with their limits instead of mine,
- joins calls and meetings as a guest.

A whole team leaning on one agent all day is the best test it can get. It's also where the bill shows up: an always-on AI agent has an always-on bill. The rest of this post is how Kage keeps its own small. You can see what Kage does at [github.com/aloki-alok/kage](https://github.com/aloki-alok/kage).

## Words in this post

<div class="tldr words">
<p><strong>Token</strong>: the unit a model bills by, about three quarters of a word. You pay for tokens in and tokens out.</p>
<p><strong>Context</strong>: everything the model reads on one call: the system prompt, the tools, the conversation so far. The <strong>context window</strong> is the cap.</p>
<p><strong>Session</strong>: one running conversation. Every call in it reads the whole history again.</p>
<p><strong>Turn</strong>: one task, from the message in to the answer out. One turn can be many model calls.</p>
<p><strong>Prompt caching</strong>: the provider reuses text it has already seen, at about a tenth of the price. Cheaper, not free.</p>
</div>

## Two questions decide the bill

A chatbot costs money only while you talk to it. An always-on agent is different. It wakes up on its own to check things, and every time it wakes up, it reads before it acts.

So leave aside the real work the agent does. That part you want to pay for. The waste hides in two questions:

<figure>
<svg class="chart" viewBox="0 0 680 190" role="img" aria-label="How often it wakes up, times how much it reads each time, equals the bill. Kage's fix for the first: wake only when something changed. For the second: send only what's new, and keep long output out of the chat.">
  <g font-size="14">
    <rect x="10" y="20" width="230" height="64" rx="8" fill="#181825" stroke="#cba6f7"/>
    <text x="125" y="47" text-anchor="middle" fill="#cdd6f4">how often it</text>
    <text x="125" y="67" text-anchor="middle" fill="#cdd6f4">wakes up</text>
    <text x="268" y="60" text-anchor="middle" fill="#f5c2e7" font-size="26">×</text>
    <rect x="296" y="20" width="230" height="64" rx="8" fill="#181825" stroke="#cba6f7"/>
    <text x="411" y="47" text-anchor="middle" fill="#cdd6f4">how much it reads</text>
    <text x="411" y="67" text-anchor="middle" fill="#cdd6f4">each time</text>
    <text x="554" y="60" text-anchor="middle" fill="#f5c2e7" font-size="26">=</text>
    <rect x="582" y="20" width="88" height="64" rx="8" fill="#cba6f7"/>
    <text x="626" y="57" text-anchor="middle" fill="#1e1e2e" font-weight="600">waste</text>
  </g>
  <g stroke="#45475a" stroke-dasharray="3 4"><line x1="125" y1="88" x2="125" y2="118"/><line x1="411" y1="88" x2="411" y2="118"/></g>
  <g font-size="12" fill="#a6e3a1" text-anchor="middle">
    <text x="125" y="138">wake only when</text>
    <text x="125" y="156">something changed</text>
    <text x="411" y="138">send only what's new,</text>
    <text x="411" y="156">keep long output out of the chat</text>
  </g>
</svg>
<figcaption>two questions, one bill. green is what kage changed for each</figcaption>
</figure>

The two multiply. An agent that wakes up 96 times a day and reads a long chat each time pays for both, 96 times over. Cut either one in half and the waste halves. Cut both and it drops to a quarter. You don't need a cheaper model for any of this.

## Measure before you cut

Before changing any code, I gave Kage a way to measure itself. `kage stats` now shows tokens per turn, split by kind of chat ([PR #512](https://github.com/aloki-alok/kage/pull/512)). Then I split two weeks of Kage's LLM token usage by chat and by scheduled job. For each group I compared two numbers: its share of all turns, and its share of all tokens. When the two match, the group costs what its work is worth. When the token share is far higher, each turn is doing extra reading, and that's where to look.

<figure>
<svg class="chart" viewBox="0 0 680 250" role="img" aria-label="Share of turns versus share of tokens. Everyday work: 69.7% of turns, 64.4% of tokens. Four timer jobs: 24.7% of turns, 9.3% of tokens. Two long chats: 5.6% of turns, 26.3% of tokens.">
  <g font-size="12" fill="#bac2de">
    <rect x="170" y="14" width="12" height="12" rx="2" fill="#6c7086"/><text x="188" y="24">share of turns</text>
    <rect x="320" y="14" width="12" height="12" rx="2" fill="#cba6f7"/><text x="338" y="24">share of tokens</text>
  </g>
  <g stroke="#45475a" stroke-width="1"><line x1="170" y1="44" x2="170" y2="232"/></g>
  <g font-size="13" fill="#cdd6f4" text-anchor="end">
    <text x="158" y="80">everyday work</text>
    <text x="158" y="146">4 timer jobs</text>
    <text x="158" y="212">2 long chats</text>
  </g>
  <g>
    <rect x="170" y="58" width="335" height="18" rx="3" fill="#6c7086"/>
    <rect x="170" y="80" width="309" height="18" rx="3" fill="#cba6f7"/>
    <rect x="170" y="124" width="119" height="18" rx="3" fill="#6c7086"/>
    <rect x="170" y="146" width="45" height="18" rx="3" fill="#cba6f7"/>
    <rect x="170" y="190" width="27" height="18" rx="3" fill="#6c7086"/>
    <rect x="170" y="212" width="126" height="18" rx="3" fill="#cba6f7"/>
  </g>
  <g font-size="12" fill="#cdd6f4">
    <text x="512" y="72">69.7%</text>
    <text x="486" y="94">64.4%</text>
    <text x="296" y="138">24.7%</text>
    <text x="222" y="160">9.3%</text>
    <text x="204" y="204">5.6%</text>
    <text x="303" y="226" fill="#f5c2e7">26.3%  ← 4.7× the cost per turn</text>
  </g>
</svg>
<figcaption>two weeks of turns vs tokens. everyday work costs its share. the long chats are the outlier</figcaption>
</figure>

The good news came first: the everyday work, about 70% of all turns, cost almost exactly its share. The extra reading sat in two corners. A couple of very long chats, where each answer cost about 4.7 times an average one, because Kage read the whole chat again every time. And four jobs that ran on a timer, a quarter of all turns, where most runs found nothing to do. Both are fixable, and neither needs a different model.

## Don't wake the model to find nothing

Say you ask an agent to check a dashboard four times an hour. Each check is a full AI run: it reads its instructions, opens the dashboard, thinks, and concludes "nothing new". You pay for all of that even when the answer is no. One Kage job had done this 277 times. It found nothing every single time.

<figure>
<svg class="chart" viewBox="0 0 680 136" role="img" aria-label="277 runs shown as dots. None found anything to report.">
  <g fill="none" stroke="#6c7086" stroke-width="1.5"><circle cx="48" cy="12" r="4.5"/><circle cx="63" cy="12" r="4.5"/><circle cx="78" cy="12" r="4.5"/><circle cx="93" cy="12" r="4.5"/><circle cx="108" cy="12" r="4.5"/><circle cx="123" cy="12" r="4.5"/><circle cx="138" cy="12" r="4.5"/><circle cx="153" cy="12" r="4.5"/><circle cx="168" cy="12" r="4.5"/><circle cx="183" cy="12" r="4.5"/><circle cx="198" cy="12" r="4.5"/><circle cx="213" cy="12" r="4.5"/><circle cx="228" cy="12" r="4.5"/><circle cx="243" cy="12" r="4.5"/><circle cx="258" cy="12" r="4.5"/><circle cx="273" cy="12" r="4.5"/><circle cx="288" cy="12" r="4.5"/><circle cx="303" cy="12" r="4.5"/><circle cx="318" cy="12" r="4.5"/><circle cx="333" cy="12" r="4.5"/><circle cx="348" cy="12" r="4.5"/><circle cx="363" cy="12" r="4.5"/><circle cx="378" cy="12" r="4.5"/><circle cx="393" cy="12" r="4.5"/><circle cx="408" cy="12" r="4.5"/><circle cx="423" cy="12" r="4.5"/><circle cx="438" cy="12" r="4.5"/><circle cx="453" cy="12" r="4.5"/><circle cx="468" cy="12" r="4.5"/><circle cx="483" cy="12" r="4.5"/><circle cx="498" cy="12" r="4.5"/><circle cx="513" cy="12" r="4.5"/><circle cx="528" cy="12" r="4.5"/><circle cx="543" cy="12" r="4.5"/><circle cx="558" cy="12" r="4.5"/><circle cx="573" cy="12" r="4.5"/><circle cx="588" cy="12" r="4.5"/><circle cx="603" cy="12" r="4.5"/><circle cx="618" cy="12" r="4.5"/><circle cx="633" cy="12" r="4.5"/><circle cx="48" cy="27" r="4.5"/><circle cx="63" cy="27" r="4.5"/><circle cx="78" cy="27" r="4.5"/><circle cx="93" cy="27" r="4.5"/><circle cx="108" cy="27" r="4.5"/><circle cx="123" cy="27" r="4.5"/><circle cx="138" cy="27" r="4.5"/><circle cx="153" cy="27" r="4.5"/><circle cx="168" cy="27" r="4.5"/><circle cx="183" cy="27" r="4.5"/><circle cx="198" cy="27" r="4.5"/><circle cx="213" cy="27" r="4.5"/><circle cx="228" cy="27" r="4.5"/><circle cx="243" cy="27" r="4.5"/><circle cx="258" cy="27" r="4.5"/><circle cx="273" cy="27" r="4.5"/><circle cx="288" cy="27" r="4.5"/><circle cx="303" cy="27" r="4.5"/><circle cx="318" cy="27" r="4.5"/><circle cx="333" cy="27" r="4.5"/><circle cx="348" cy="27" r="4.5"/><circle cx="363" cy="27" r="4.5"/><circle cx="378" cy="27" r="4.5"/><circle cx="393" cy="27" r="4.5"/><circle cx="408" cy="27" r="4.5"/><circle cx="423" cy="27" r="4.5"/><circle cx="438" cy="27" r="4.5"/><circle cx="453" cy="27" r="4.5"/><circle cx="468" cy="27" r="4.5"/><circle cx="483" cy="27" r="4.5"/><circle cx="498" cy="27" r="4.5"/><circle cx="513" cy="27" r="4.5"/><circle cx="528" cy="27" r="4.5"/><circle cx="543" cy="27" r="4.5"/><circle cx="558" cy="27" r="4.5"/><circle cx="573" cy="27" r="4.5"/><circle cx="588" cy="27" r="4.5"/><circle cx="603" cy="27" r="4.5"/><circle cx="618" cy="27" r="4.5"/><circle cx="633" cy="27" r="4.5"/><circle cx="48" cy="42" r="4.5"/><circle cx="63" cy="42" r="4.5"/><circle cx="78" cy="42" r="4.5"/><circle cx="93" cy="42" r="4.5"/><circle cx="108" cy="42" r="4.5"/><circle cx="123" cy="42" r="4.5"/><circle cx="138" cy="42" r="4.5"/><circle cx="153" cy="42" r="4.5"/><circle cx="168" cy="42" r="4.5"/><circle cx="183" cy="42" r="4.5"/><circle cx="198" cy="42" r="4.5"/><circle cx="213" cy="42" r="4.5"/><circle cx="228" cy="42" r="4.5"/><circle cx="243" cy="42" r="4.5"/><circle cx="258" cy="42" r="4.5"/><circle cx="273" cy="42" r="4.5"/><circle cx="288" cy="42" r="4.5"/><circle cx="303" cy="42" r="4.5"/><circle cx="318" cy="42" r="4.5"/><circle cx="333" cy="42" r="4.5"/><circle cx="348" cy="42" r="4.5"/><circle cx="363" cy="42" r="4.5"/><circle cx="378" cy="42" r="4.5"/><circle cx="393" cy="42" r="4.5"/><circle cx="408" cy="42" r="4.5"/><circle cx="423" cy="42" r="4.5"/><circle cx="438" cy="42" r="4.5"/><circle cx="453" cy="42" r="4.5"/><circle cx="468" cy="42" r="4.5"/><circle cx="483" cy="42" r="4.5"/><circle cx="498" cy="42" r="4.5"/><circle cx="513" cy="42" r="4.5"/><circle cx="528" cy="42" r="4.5"/><circle cx="543" cy="42" r="4.5"/><circle cx="558" cy="42" r="4.5"/><circle cx="573" cy="42" r="4.5"/><circle cx="588" cy="42" r="4.5"/><circle cx="603" cy="42" r="4.5"/><circle cx="618" cy="42" r="4.5"/><circle cx="633" cy="42" r="4.5"/><circle cx="48" cy="57" r="4.5"/><circle cx="63" cy="57" r="4.5"/><circle cx="78" cy="57" r="4.5"/><circle cx="93" cy="57" r="4.5"/><circle cx="108" cy="57" r="4.5"/><circle cx="123" cy="57" r="4.5"/><circle cx="138" cy="57" r="4.5"/><circle cx="153" cy="57" r="4.5"/><circle cx="168" cy="57" r="4.5"/><circle cx="183" cy="57" r="4.5"/><circle cx="198" cy="57" r="4.5"/><circle cx="213" cy="57" r="4.5"/><circle cx="228" cy="57" r="4.5"/><circle cx="243" cy="57" r="4.5"/><circle cx="258" cy="57" r="4.5"/><circle cx="273" cy="57" r="4.5"/><circle cx="288" cy="57" r="4.5"/><circle cx="303" cy="57" r="4.5"/><circle cx="318" cy="57" r="4.5"/><circle cx="333" cy="57" r="4.5"/><circle cx="348" cy="57" r="4.5"/><circle cx="363" cy="57" r="4.5"/><circle cx="378" cy="57" r="4.5"/><circle cx="393" cy="57" r="4.5"/><circle cx="408" cy="57" r="4.5"/><circle cx="423" cy="57" r="4.5"/><circle cx="438" cy="57" r="4.5"/><circle cx="453" cy="57" r="4.5"/><circle cx="468" cy="57" r="4.5"/><circle cx="483" cy="57" r="4.5"/><circle cx="498" cy="57" r="4.5"/><circle cx="513" cy="57" r="4.5"/><circle cx="528" cy="57" r="4.5"/><circle cx="543" cy="57" r="4.5"/><circle cx="558" cy="57" r="4.5"/><circle cx="573" cy="57" r="4.5"/><circle cx="588" cy="57" r="4.5"/><circle cx="603" cy="57" r="4.5"/><circle cx="618" cy="57" r="4.5"/><circle cx="633" cy="57" r="4.5"/><circle cx="48" cy="72" r="4.5"/><circle cx="63" cy="72" r="4.5"/><circle cx="78" cy="72" r="4.5"/><circle cx="93" cy="72" r="4.5"/><circle cx="108" cy="72" r="4.5"/><circle cx="123" cy="72" r="4.5"/><circle cx="138" cy="72" r="4.5"/><circle cx="153" cy="72" r="4.5"/><circle cx="168" cy="72" r="4.5"/><circle cx="183" cy="72" r="4.5"/><circle cx="198" cy="72" r="4.5"/><circle cx="213" cy="72" r="4.5"/><circle cx="228" cy="72" r="4.5"/><circle cx="243" cy="72" r="4.5"/><circle cx="258" cy="72" r="4.5"/><circle cx="273" cy="72" r="4.5"/><circle cx="288" cy="72" r="4.5"/><circle cx="303" cy="72" r="4.5"/><circle cx="318" cy="72" r="4.5"/><circle cx="333" cy="72" r="4.5"/><circle cx="348" cy="72" r="4.5"/><circle cx="363" cy="72" r="4.5"/><circle cx="378" cy="72" r="4.5"/><circle cx="393" cy="72" r="4.5"/><circle cx="408" cy="72" r="4.5"/><circle cx="423" cy="72" r="4.5"/><circle cx="438" cy="72" r="4.5"/><circle cx="453" cy="72" r="4.5"/><circle cx="468" cy="72" r="4.5"/><circle cx="483" cy="72" r="4.5"/><circle cx="498" cy="72" r="4.5"/><circle cx="513" cy="72" r="4.5"/><circle cx="528" cy="72" r="4.5"/><circle cx="543" cy="72" r="4.5"/><circle cx="558" cy="72" r="4.5"/><circle cx="573" cy="72" r="4.5"/><circle cx="588" cy="72" r="4.5"/><circle cx="603" cy="72" r="4.5"/><circle cx="618" cy="72" r="4.5"/><circle cx="633" cy="72" r="4.5"/><circle cx="48" cy="87" r="4.5"/><circle cx="63" cy="87" r="4.5"/><circle cx="78" cy="87" r="4.5"/><circle cx="93" cy="87" r="4.5"/><circle cx="108" cy="87" r="4.5"/><circle cx="123" cy="87" r="4.5"/><circle cx="138" cy="87" r="4.5"/><circle cx="153" cy="87" r="4.5"/><circle cx="168" cy="87" r="4.5"/><circle cx="183" cy="87" r="4.5"/><circle cx="198" cy="87" r="4.5"/><circle cx="213" cy="87" r="4.5"/><circle cx="228" cy="87" r="4.5"/><circle cx="243" cy="87" r="4.5"/><circle cx="258" cy="87" r="4.5"/><circle cx="273" cy="87" r="4.5"/><circle cx="288" cy="87" r="4.5"/><circle cx="303" cy="87" r="4.5"/><circle cx="318" cy="87" r="4.5"/><circle cx="333" cy="87" r="4.5"/><circle cx="348" cy="87" r="4.5"/><circle cx="363" cy="87" r="4.5"/><circle cx="378" cy="87" r="4.5"/><circle cx="393" cy="87" r="4.5"/><circle cx="408" cy="87" r="4.5"/><circle cx="423" cy="87" r="4.5"/><circle cx="438" cy="87" r="4.5"/><circle cx="453" cy="87" r="4.5"/><circle cx="468" cy="87" r="4.5"/><circle cx="483" cy="87" r="4.5"/><circle cx="498" cy="87" r="4.5"/><circle cx="513" cy="87" r="4.5"/><circle cx="528" cy="87" r="4.5"/><circle cx="543" cy="87" r="4.5"/><circle cx="558" cy="87" r="4.5"/><circle cx="573" cy="87" r="4.5"/><circle cx="588" cy="87" r="4.5"/><circle cx="603" cy="87" r="4.5"/><circle cx="618" cy="87" r="4.5"/><circle cx="633" cy="87" r="4.5"/><circle cx="48" cy="102" r="4.5"/><circle cx="63" cy="102" r="4.5"/><circle cx="78" cy="102" r="4.5"/><circle cx="93" cy="102" r="4.5"/><circle cx="108" cy="102" r="4.5"/><circle cx="123" cy="102" r="4.5"/><circle cx="138" cy="102" r="4.5"/><circle cx="153" cy="102" r="4.5"/><circle cx="168" cy="102" r="4.5"/><circle cx="183" cy="102" r="4.5"/><circle cx="198" cy="102" r="4.5"/><circle cx="213" cy="102" r="4.5"/><circle cx="228" cy="102" r="4.5"/><circle cx="243" cy="102" r="4.5"/><circle cx="258" cy="102" r="4.5"/><circle cx="273" cy="102" r="4.5"/><circle cx="288" cy="102" r="4.5"/><circle cx="303" cy="102" r="4.5"/><circle cx="318" cy="102" r="4.5"/><circle cx="333" cy="102" r="4.5"/><circle cx="348" cy="102" r="4.5"/><circle cx="363" cy="102" r="4.5"/><circle cx="378" cy="102" r="4.5"/><circle cx="393" cy="102" r="4.5"/><circle cx="408" cy="102" r="4.5"/><circle cx="423" cy="102" r="4.5"/><circle cx="438" cy="102" r="4.5"/><circle cx="453" cy="102" r="4.5"/><circle cx="468" cy="102" r="4.5"/><circle cx="483" cy="102" r="4.5"/><circle cx="498" cy="102" r="4.5"/><circle cx="513" cy="102" r="4.5"/><circle cx="528" cy="102" r="4.5"/><circle cx="543" cy="102" r="4.5"/><circle cx="558" cy="102" r="4.5"/><circle cx="573" cy="102" r="4.5"/><circle cx="588" cy="102" r="4.5"/></g>
  <text x="340" y="128" text-anchor="middle" font-size="13" fill="#f5c2e7">0 of 277 runs found anything</text>
</svg>
<figcaption>each dot is one full model run. none of them had news</figcaption>
</figure>

So now, when you ask Kage to watch something, it picks the cheapest way to wake up that still catches every change. There are four, cheapest first:

<figure>
<svg class="chart" viewBox="0 0 680 236" role="img" aria-label="Four ways to wake a job, from cheapest to most expensive: a new post, a webhook, a probe script, an AI check on a timer.">
  <g font-size="13">
    <rect x="20" y="16" width="120" height="44" rx="6" fill="#181825" stroke="#a6e3a1"/>
    <text x="80" y="43" text-anchor="middle" fill="#a6e3a1">new post</text>
    <text x="160" y="35" fill="#cdd6f4">a post lands in the channel it watches</text>
    <text x="160" y="53" fill="#7f849c" font-size="12">nothing checks in between. free until it happens</text>
    <rect x="20" y="70" width="120" height="44" rx="6" fill="#181825" stroke="#a6e3a1"/>
    <text x="80" y="97" text-anchor="middle" fill="#a6e3a1">webhook</text>
    <text x="160" y="89" fill="#cdd6f4">the other app calls Kage when something happens</text>
    <text x="160" y="107" fill="#7f849c" font-size="12">free until it happens</text>
    <rect x="20" y="124" width="120" height="44" rx="6" fill="#181825" stroke="#f9e2af"/>
    <text x="80" y="151" text-anchor="middle" fill="#f9e2af">probe</text>
    <text x="160" y="143" fill="#cdd6f4">a small script checks on a timer, no AI</text>
    <text x="160" y="161" fill="#7f849c" font-size="12">the AI wakes only when the result changes</text>
    <rect x="20" y="178" width="120" height="44" rx="6" fill="#181825" stroke="#f38ba8"/>
    <text x="80" y="205" text-anchor="middle" fill="#f38ba8">AI on a timer</text>
    <text x="160" y="197" fill="#cdd6f4">the AI runs every time the timer fires</text>
    <text x="160" y="215" fill="#7f849c" font-size="12">a full run each time. only when it needs real judgment</text>
  </g>
</svg>
<figcaption>four ways to wake a job. pick the cheapest one that still catches every change</figcaption>
</figure>

The **probe** does most of the work. Think of it as a watchman. The job's check becomes one small script that only reads. Kage runs the script on the timer, with no AI involved, and compares the result with last time. It ignores lines that change on every run anyway, like timestamps. Same result: nothing happens and no tokens are spent. Different result: the AI wakes up, and it already knows exactly what changed.

A probe can also decide for itself. If its last line says "wake" or "quiet", with a reason, Kage follows that instead of comparing output. That helps when the output changes all the time but only some changes matter, like a queue length that moves every minute but only matters past a limit.

<div class="note"><p><strong>One safety detail for engineers.</strong> When a probe is approved, Kage pins every script it names by its <code>sha256</code>. If anyone edits one of those scripts, even the agent itself, the probe stops until a person approves it again.</p></div>

## Let the cheap job shadow first

Swapping a live alarm for a cheaper version is the scary part. If the cheap version misses the one alert that mattered, the savings are worth nothing.

So Kage treats it like a new hire. The cheaper job starts as a **shadow twin**: it sits next to the old job, does nothing, and only notes what it would have done. "I would have raised the alarm" or "I would have stayed quiet".

<figure>
<svg class="chart" viewBox="0 0 680 210" role="img" aria-label="Kage pairs the old job's actions with what the twin said it would do. Three matches swap the twin in. One miss stops the swap and asks a person.">
  <g font-size="12" fill="#7f849c">
    <text x="20" y="44">old job</text>
    <text x="20" y="84">twin</text>
    <text x="20" y="154">old job</text>
    <text x="20" y="194">twin</text>
  </g>
  <g stroke="#45475a"><line x1="90" y1="40" x2="470" y2="40"/><line x1="90" y1="80" x2="470" y2="80"/><line x1="90" y1="150" x2="470" y2="150"/><line x1="90" y1="190" x2="470" y2="190"/></g>
  <g font-size="12">
    <circle cx="150" cy="40" r="7" fill="#cba6f7"/><circle cx="150" cy="80" r="7" fill="none" stroke="#cba6f7" stroke-width="2"/><text x="150" y="64" text-anchor="middle" fill="#a6e3a1">✓</text>
    <circle cx="270" cy="40" r="7" fill="#cba6f7"/><circle cx="270" cy="80" r="7" fill="none" stroke="#cba6f7" stroke-width="2"/><text x="270" y="64" text-anchor="middle" fill="#a6e3a1">✓</text>
    <circle cx="390" cy="40" r="7" fill="#cba6f7"/><circle cx="390" cy="80" r="7" fill="none" stroke="#cba6f7" stroke-width="2"/><text x="390" y="64" text-anchor="middle" fill="#a6e3a1">✓</text>
    <circle cx="150" cy="150" r="7" fill="#cba6f7"/><circle cx="150" cy="190" r="7" fill="none" stroke="#cba6f7" stroke-width="2"/><text x="150" y="174" text-anchor="middle" fill="#a6e3a1">✓</text>
    <circle cx="270" cy="150" r="7" fill="#cba6f7"/><circle cx="270" cy="190" r="7" fill="none" stroke="#45475a" stroke-width="2"/><text x="270" y="174" text-anchor="middle" fill="#f38ba8">✗</text>
  </g>
  <g font-size="13">
    <rect x="496" y="40" width="164" height="40" rx="6" fill="#181825" stroke="#a6e3a1"/><text x="578" y="65" text-anchor="middle" fill="#a6e3a1">3 matches: swap</text>
    <rect x="496" y="150" width="164" height="40" rx="6" fill="#181825" stroke="#f38ba8"/><text x="578" y="175" text-anchor="middle" fill="#f38ba8">1 miss: stop, ask</text>
  </g>
  <g font-size="11" fill="#7f849c"><text x="90" y="16">filled = old job acted · ring = twin would act · grey ring = twin would stay quiet</text></g>
</svg>
<figcaption>what the old job did, next to what the twin said it would do</figcaption>
</figure>

Kage pairs each thing the old job did with what the twin said it would do. Three matches in a row, and the twin takes over. One miss, and the swap stops and a person decides. This has already happened: on a live-call alarm, the twin missed one real alert, so the old job kept running. That's the system working, not failing.

Where this doesn't work: a job that never does anything gives the twin nothing to agree with. For the job with 277 empty runs, the proof has to come another way: running the new script against the job's past data.

## Stop reading the whole chat again

This was the big one. Picture an assistant who, before answering your latest email, reads your entire email history with them from the first day. That's what an AI agent does in a long chat. A Slack thread with a hundred replies means a hundred replies to read before every answer. Two changes fixed it.

**1. Send only what's new.** If Kage is still in the middle of a session for that thread, it already remembers the earlier replies. So Kage now sends it only the replies it hasn't seen yet (we call this the **thread delta**). Kage marks replies as "seen" only after they reach the session, so if something crashes on the way, the replies are sent again instead of lost.

<figure>
<svg class="chart" viewBox="0 0 680 120" role="img" aria-label="Before: every turn sends all 40 replies. After: a turn sends only the 3 new ones.">
  <g font-size="12" fill="#7f849c"><text x="20" y="38">before</text><text x="20" y="92">after</text></g>
  <rect x="80.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="92.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="105.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="117.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="130.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="142.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="155.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="167.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="180.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="192.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="205.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="217.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="230.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="242.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="255.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="267.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="280.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="292.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="305.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="317.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="330.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="342.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="355.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="367.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="380.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="392.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="405.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="417.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="430.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="442.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="455.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="467.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="480.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="492.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="505.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="517.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="530.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="542.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="555.0" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="567.5" y="26" width="10" height="16" rx="2" fill="#cba6f7"/><rect x="80.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="92.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="105.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="117.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="130.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="142.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="155.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="167.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="180.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="192.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="205.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="217.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="230.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="242.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="255.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="267.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="280.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="292.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="305.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="317.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="330.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="342.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="355.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="367.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="380.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="392.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="405.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="417.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="430.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="442.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="455.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="467.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="480.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="492.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="505.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="517.5" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="530.0" y="80" width="10" height="16" rx="2" fill="#313244"/><rect x="542.5" y="80" width="10" height="16" rx="2" fill="#f5c2e7"/><rect x="555.0" y="80" width="10" height="16" rx="2" fill="#f5c2e7"/><rect x="567.5" y="80" width="10" height="16" rx="2" fill="#f5c2e7"/>
  <g font-size="12"><text x="600" y="38" fill="#cdd6f4">40 sent</text><text x="600" y="92" fill="#f5c2e7">3 sent</text></g>
</svg>
<figcaption>one new message in a 40-reply thread. lit squares are what the AI reads</figcaption>
</figure>

**2. Keep long output out of the chat.** Sending only the new replies keeps each message small. But the work inside a turn adds up too. When Kage runs a command, like a test suite or a database query, everything the command prints lands in the chat. Then the AI reads it again on every later step of that turn. Over one week, command output was about 70% of all the tool text Kage read, and the biggest 3% of outputs carried about 40% of it.

Now a long output keeps only its first and last 3,000 characters in the chat. The rest goes to a file, and the chat says where. The end matters most, because that's where a failed test or a crash prints its error. If the AI needs the middle, it opens the file.

<figure>
<svg class="chart" viewBox="0 0 680 120" role="img" aria-label="Tokens read per turn on a task with long test output: 259k before the output cut, 167k after.">
  <g font-size="12" fill="#7f849c"><text x="20" y="40">before</text><text x="20" y="86">after</text></g>
  <rect x="80" y="26" width="480" height="18" rx="3" fill="#6c7086"/>
  <rect x="80" y="72" width="309.5" height="18" rx="3" fill="#cba6f7"/>
  <g font-size="12"><text x="570" y="40" fill="#bac2de">259k</text><text x="399.5" y="86" fill="#cba6f7">167k (36% less)</text></g>
</svg>
<figcaption>measured: tokens read per turn on our task with long test output, median of 3 runs. all 20 tasks passed before and after</figcaption>
</figure>

On that task, each turn now reads 36% fewer tokens (259k down to 167k), and the work takes 5 steps instead of 8. The other 19 tasks passed as before.

**Doesn't prompt caching already fix this?** It hides it. 95% of what Kage reads already comes from the cache, and [cached tokens bill at a tenth of the normal price](https://docs.claude.com/en/docs/build-with-claude/prompt-caching). But a tenth of 400k is still 40k tokens on every answer, and saving text to the cache costs extra. Caching makes each re-read cheaper. Reading less removes it.

## The quality check that stopped a bad cut

Cutting tokens is easy. Cutting them without making the agent worse is the hard part. So before any saving ships, Kage runs the same 20 real tasks 3 times on the old code and 3 times on the new code: rename a function, read long test output, answer a teammate, and more. If a task fails more often after the change, the change doesn't ship.

The first try of the output cut failed 4 of the 20 tasks. The cut was meant only for the agent's shell commands. But the same setting also starts the agent's helper tools, and cutting their output broke them. The unit tests passed, because each piece worked alone. The 20-task check caught it. After the fix, all 20 passed again.

The rule I took from it: **measure quality before and after, not only tokens.** A saving that makes the agent worse isn't a saving.

The habit comes from how Kage itself is built. Coding agents write most of its code, and they follow [kagestack](https://github.com/aloki-alok/kagestack), my checks and playbooks for coding agents: every change ends in proof, and `ks check` fails a pull request that adds a code comment or a skipped test, or pushes a function past 60 lines. The 20-task check applies the same rule to the agent's behavior.

## Load only what the chat needs

Once the whole team used Kage, a third cost showed up. Every chat started by loading my full setup: my personal instructions, my tools, my notes. A teammate asking "what changed in yesterday's deploy?" paid to read all of it, and needed none of it.

Now only my own chats, and chats I mark as trusted, load that setup. A teammate's chat starts lean, with just what its task needs. Every teammate turn reads less, and my private setup stays private. Cost and privacy turned out to be the same fix.

## What Kage does, with the code

Here is each problem, what Kage does about it, and the pull request with the code and its tests.

<table>
<thead><tr><th>Problem</th><th>What Kage does now</th><th>Code</th></tr></thead>
<tbody>
<tr><td>Hard to see where tokens go</td><td><code>kage stats</code> shows tokens per turn, by kind of chat</td><td><a href="https://github.com/aloki-alok/kage/pull/512" target="_blank" rel="noopener noreferrer">#512</a></td></tr>
<tr><td>Jobs wake the AI on a timer</td><td>Jobs wake on a new post or a webhook, with no timer</td><td><a href="https://github.com/aloki-alok/kage/pull/292" target="_blank" rel="noopener noreferrer">#292</a></td></tr>
<tr><td>Timer jobs that find nothing</td><td>A probe script checks with no AI, and wakes it only on a change</td><td><a href="https://github.com/aloki-alok/kage/pull/290" target="_blank" rel="noopener noreferrer">#290</a></td></tr>
<tr><td>Not every change matters</td><td>A probe can say "wake" or "quiet" itself, with a reason</td><td><a href="https://github.com/aloki-alok/kage/pull/520" target="_blank" rel="noopener noreferrer">#520</a></td></tr>
<tr><td>A cheaper job can miss an alert</td><td>It shadows the old job and takes over only after it matches</td><td><a href="https://github.com/aloki-alok/kage/pull/299" target="_blank" rel="noopener noreferrer">#299</a></td></tr>
<tr><td>Each message re-sends the chat</td><td>Only the replies the session hasn't seen are sent</td><td><a href="https://github.com/aloki-alok/kage/pull/524" target="_blank" rel="noopener noreferrer">#524</a></td></tr>
<tr><td>Long command output is re-read on every step</td><td>Only its start and end stay in the chat. The rest goes to a file</td><td><a href="https://github.com/aloki-alok/kage/pull/591" target="_blank" rel="noopener noreferrer">#591</a></td></tr>
<tr><td>Every chat loads the full setup</td><td>A teammate's chat loads only what it needs</td><td><a href="https://github.com/aloki-alok/kage/pull/513" target="_blank" rel="noopener noreferrer">#513</a></td></tr>
</tbody>
</table>
<p>Next on the list: shorter tool descriptions on every turn, and sending simple work to a smaller, cheaper model.</p>

## A checklist for your agent

1. Before you change anything, split token usage by chat and by job. Look for groups whose share of tokens is far above their share of turns.
2. Wake the AI on events, like a new post or a webhook. If something must run on a timer, let a script check first, and wake the AI only when the result changes.
3. Replace a job only after its cheaper twin has shadowed it and agreed every time. Stop at the first miss.
4. Send only the new messages, not the whole chat. Mark them seen only after they arrive.
5. Keep long tool output out of the chat: its start and end stay, and the rest goes to a file. Treat prompt caching as a discount, not a fix.
6. Put what a step depends on into the message itself.
7. Load only what each chat needs. A quick question doesn't need your whole setup.
8. Run the same real tasks before and after every cut. Ship it only if no task gets worse.

You can build all eight into your own agent. Or use [Kage](https://github.com/aloki-alok/kage), the always-on AI agent where they already run. For the bigger picture, [Anthropic's piece on context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) is the best place to start.

## The one-line version

An always-on AI agent should wake up only when something changed, and read only what it hasn't seen.

## FAQ

**What is Kage?** Kage is an always-on AI agent. You reach it on Slack, WhatsApp, email, phone calls or GitHub, and it joins calls and meetings as a guest. It does the work with your tools and your access. It also uses your browser, runs scheduled jobs and acts on alerts. My whole team uses it every day. More at [github.com/aloki-alok/kage](https://github.com/aloki-alok/kage).

**Why does an always-on AI agent use so many tokens?** It pays every time it wakes up, and for everything it reads when it does. Most waste comes from two places: jobs that wake the AI to find nothing new, and long chats that it reads again from the start before every answer.

**Doesn't prompt caching already fix long chats?** It makes each re-read cheaper, not free. A 400k-token chat still costs about 40k tokens on every answer. Reading less removes it: Kage sends only the new messages, and keeps only the start and end of long output.

**How do I replace an AI job with a cheaper one safely?** Run the cheaper version as a shadow twin that does nothing and only notes what it would have done. Swap it in after it agrees with the old job several times in a row, and stop at the first miss.

**What is kagestack?** A set of checks and playbooks that keep coding agents writing clean, proven code. Kage is built with it. More at [github.com/aloki-alok/kagestack](https://github.com/aloki-alok/kagestack).

<div class="tldr tldr-end"><p><strong>Meet Kage</strong></p><p>An always-on AI agent that works from Slack, WhatsApp, email, phone calls, GitHub and your browser, and joins meetings as a guest. It wakes up only when something changed, and reads only what it hasn't seen.</p><p><a href="https://github.com/aloki-alok/kage" target="_blank" rel="noopener noreferrer">See Kage on GitHub</a> · built with <a href="https://github.com/aloki-alok/kagestack" target="_blank" rel="noopener noreferrer">kagestack</a></p></div>

<script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is Kage?","acceptedAnswer":{"@type":"Answer","text":"Kage is an always-on AI agent. You reach it on Slack, WhatsApp, email, phone calls or GitHub, and it joins calls and meetings as a guest. It does the work with your tools and your access. It also uses your browser, runs scheduled jobs and acts on alerts."}},{"@type":"Question","name":"Why does an always-on AI agent use so many tokens?","acceptedAnswer":{"@type":"Answer","text":"It pays every time it wakes up and for everything it reads when it does. Most waste comes from two places: jobs that wake the model to find nothing new, and long chats that the agent reads again from the start before every answer."}},{"@type":"Question","name":"Doesn't prompt caching already fix long chats?","acceptedAnswer":{"@type":"Answer","text":"It makes each re-read cheaper, not free. Cached tokens bill at a tenth of normal input, so a 400k-token chat still costs about 40k tokens on every answer. Reading less removes it: Kage sends only the new messages, and keeps only the start and end of long output."}},{"@type":"Question","name":"How do you replace an AI job with a cheaper one safely?","acceptedAnswer":{"@type":"Answer","text":"Run the cheaper version as a shadow twin. It acts on nothing and only notes what it would have done. Swap it in after it agrees with the old job several times in a row, and stop at the first miss."}},{"@type":"Question","name":"What is kagestack?","acceptedAnswer":{"@type":"Answer","text":"A set of checks and playbooks that keep coding agents writing clean, proven code. Kage is built with it."}}]}</script>
