← All insights

KN-04 · Cache and compaction economics

The cost curve of a long session, and when to compact

When an agent session keeps adding context, each call can send more for the model to read. A prompt cache lowers the price of rereading shared content. Compaction can reduce the amount sent.

5 min readGuildBuild Team
AI agentsPrompt cachingContext engineeringAgent economics
In this article

Why session cost can accelerate

If each call adds the same amount of retained context and later calls reread it all, cumulative reads grow roughly with the square of the number of calls. Real sessions can prune content, compact it, or add uneven amounts. Cache pricing changes the cost per reread. The accumulation pattern depends on the session.

Cache rates changed

The study used these historical Claude API list rates in USD per million tokens.

API list rates used in the study
ModelInputOne-hour cache writeCache read
Opus 5$5$10$0.50
Opus 5.5$4$8$0.20

A cache read dropped from 10% to 5% of the input rate. Meanwhile, the ratio of a one-hour write to a read rose from 20 to 40. In this comparison, warm reads got cheaper, while a one-hour rewrite cost twice as much relative to a read.

The first call after compaction

The study traced 313 calls across nine sessions. In one session, compaction took the context sent per call from 382,000 tokens to 38,000. It grew back to 172,000 over the next 11 calls. The refill included 12 web fetches, two searches, one file read, and the model’s own long output sent back as input.

The app’s savings display compared the old context with the summary alone. The next request also carried a fixed prefix. In three compactions the actual drop was about 29,000 tokens smaller than the display implied. In a separate set of 196 Codex compactions, the median context reduction was 87%.

Figure 01Field measurement

Context fell, then refilled

Observed request size

tokens per call
Before compaction382,000
First call after compaction38,000
11 calls later172,000

Three observed points from one session among nine traced sessions and 313 calls. The intermediate calls are outside the chart. The next request includes both the summary and its fixed prefix.

Timing matters more than the trigger in these cases

On one agent seat, manual compactions happened earlier than automatic ones, and calls read less cached context. On a second seat, manual compactions came later and calls read more. These two cases suggest looking at timing before choosing a trigger.

Compaction also interrupted work. The waits were 9 to 57 seconds in one day of Claude Code compactions, and about one to three minutes in nine Codex compactions across three chats. Frequent compaction can interrupt an active task and remove context it still needs.

What it costs to keep a session warm

At the listed Opus 5.5 rates, reading 100,000 cached tokens once costs about US$0.02. Writing all 100,000 back into a one-hour cache costs about US$0.80. The read-only arithmetic reaches the cost of one rewrite after 40 reads.

This comparison assumes each read hits and refreshes the same cached prefix in time, with no extra input or output charged. Actual keep-alive calls can add cost. A fresh session with a short handoff can cost less to start, but the agent may need to recover missing details before it can work.

Figure 02Evidence comparison

One rewrite cost as much as 40 reads in this example

Read once

Quantity100,000 cached tokens

Estimated API costUS$0.02

Read 40 times

Quantity4 million cached tokens in total

Estimated API costUS$0.80

Write once

Quantity100,000 tokens in a one-hour cache

Estimated API costUS$0.80

Illustrative arithmetic for 100,000 tokens at the historical Opus 5.5 rates used in this study. Each read assumes a hit on the same prefix and excludes extra input and output. Subscription usage and recovery work are outside the estimate.

Use the next call as the test

  1. Compact at a task boundary when possible. Save the facts the next task needs.
  2. Read the next calls’ actual input and cache totals. Include compaction time and context recovery.
  3. Before a break, compare the expected cost of keeping the cache warm, rewriting it or starting from a short handoff.
  4. Check the applicable API prices and any workflow rules before adding periodic calls.

How we know

The nine sessions came from one seat in late September 2026. The refill example came from one session, and the trigger comparison used two seats. The team recorded the API prices in October 2026. The idle example is arithmetic on those rates. It does not show how subscriptions count cache use. We did not rerun the measurements for this publication.

Related field notes: What your agent still knows after a compaction and Where the tokens go in a real agent team.