PTENES
Skip to content
MODULE 3.1

⚖️ Cache vs. Compaction

Caching and compaction seem to compete, but they optimize different things: one changes the price per token, the other in how many tokens you carry. Whoever understands both axes makes the right call — and stops paying for huge context turn after turn.

6
Topics
~40
Minutes
Advanced
Level
Decision
Type
1

↔️ Two different axes

Cache optimizes the price per token of the context. Compact optimizes how many tokens you carry. These are two axes that don’t compete in the same place — and that’s why you want both.

Compact = summarize the history into a shorter version; in Claude Code, the command is /compact. It doesn't change the price per token; it changes the size of what you resend.

price/token (cache ↓) token count (compact ←) full context many tokens · 1× cache cache only many tokens · 0.1× compact cache + compact few tokens · 0.1×

Legend: the cache only goes down (price); compaction only moves left (quantity). One doesn't do the other's job.

Cache

Changes the price per token

Compact

Changes the number of tokens

/compact

Summarize the history in Claude Code

Both

Orthogonal axes, not rivals

2

💰 A large cached context is still expensive

The cache discount is misleading. The cache makes per token, but 400k tokens read at 0,1× still equal ~40k of full input per turn — and that every turn, while the context remains this large.

The calculation that scares you

400,000 tokens × 0.1× = 40,000 full-input-equivalent tokens, paid for every message. A high hit rate (99%) doesn’t change that: the volume is large.

400k read @ 0.1× ≈ 40k-equiv / turn
× every turn of the conversation = a sum that keeps growing
400k @ 1× (without cache) 400,000 equivalent tokens × 0.1 (cache) 400k @ 0.1× (with cache) ≈ 40,000 token-equivalents / turn — still large

Legend: one tenth of a lot is still a lot. Caching lowers the cost; it doesn't shrink the context.

Read the total, not the field

If input_tokens shows little, but the bill is high; most of it is in cache_read_input_tokens at 0.1×. It’s cheap per token, but the total prompt cost is the sum of the three fields.

0,1×

The cache read factor

40k-equiv

400k read every turn

Every turn

The cost repeats; it doesn’t disappear

Volume

Cheap ≠ small

3

🧱 The context limit (1M)

Here the cache doesn’t help. It leaves 900k tokens cheap, but they still take up 900k of 1M. Eventually, you can't continue the conversation without compact or /clear. The limit is about quantity — and only compacting/clearing frees up space.

Context window = 1,000,000 tokens cached context (cheap, but large) 900k occupied @ 0.1× 100k after compaction 20k · window almost entirely free

Legend: cheap ≠ small. The 1M limit counts occupied slots, not the price—only compact creates room.

The common mistake

Rely on the cache to “handle” a context that only keeps growing. It holds down the cost, not the size. Near the limit, the conversation gets stuck—and then it’s /compact or /clear, no more caching.

1M

Maximum slots in the window

Cheap ≠ small

Caching doesn’t create space

/compact

Reduces occupancy

/clear

Resets when you don’t need the history

4

📉 Compaction numbers

Compacting replaces a single cold write with much lighter turns. Without compacting, you pay for the large context every message. By compacting, you pay for just one write, and all subsequent turns are cheap. See the side-by-side breakdown.

ScenarioInitial cost (one time)Cost per turnPayback
Without compacting
400k in context
— 400k @ 0,1× ≈ 40k-equiv · forever never improves
Compacting
for 20k
1 cold write 20k @ 1.25× ≈ 25k 20k @ 0,1× ≈ 2k-equiv · per turn ~1 turn
Cost per turn (token-equivalents) 0 40k Without compaction · ~40k/turn forever 25k Compacting · 1 cold write, then ~2k/turn

Legend: the only cyan spike (turn 0) is the cold write from compaction; after that, each turn is ~20× lighter than the purple bar.

Practical tip

Think in terms of turns ahead: if many messages are still coming, the 25k cold write gets diluted to nothing compared with saving 38k per turn. If the conversation is ending now, the cold write isn't worth it.

1 cold write

20k @ 1.25× ≈ 25k, once

~2k/turn

After compacting

~1 turn

Payback

~20×

Lighter per turn

5

🧠 Quality and latency

Compaction isn’t just about cost. Bloated context scatters attention of the model (the "context rot") — it makes more mistakes and rambles more. And even when read from the cache, 400k take longer than 20k for the first token (higher TTFT). Compacting improves accuracy e speed.

400k — attention spread thin more errors · higher TTFT 20k — focused attention gets more right · responds sooner

Legend: fewer tokens = concentrated attention + faster first token. Compression is a quality improvement, not just a cost saving.

✓ Compact context

  • ✓Focused attention on what matters
  • ✓Less "context rot," fewer errors
  • ✓Faster first token (lower TTFT)

✗ Bloated context

  • ✗Diluted attention, rambling responses
  • ✗Errors from losing sight of what matters
  • ✗Slower even when read from cache
Context rot

Excessively scattered attention

TTFT

Time to first token

Caching ≠ fast

Read, but still large

Two benefits

Precision + speed

6

🎯 When to compact / when NOT to

The guideline is simple. Short conversation → DO NOT compact: you only lose the warm cache without any benefit (that intuition is right). Large context, near the limit, or quality declining → compact: you trade one cold write for much lighter turns.

How’s the context? size · ceiling · quality small conversation DO NOT compact preserves the warm cache large / at the limit / dropping COMPACT 1 cold write → light turns

Legend: the branch green preserves the cache; the branch purple accepts 1 cold write to save on every subsequent turn.

✓ Compact when

  • ✓The context is large, and many turns are still ahead
  • ✓You’re close to the 1M limit
  • ✓Quality has dropped / the model is stalling

✗ Don’t compact when

  • ✗The conversation is short and the cache is already warm
  • ✗Will end soon (there aren’t enough turns left to pay for the cold write)
  • ✗By habit, without checking size or quality

Rule of thumb

Compact with the state (size, limit, quality), not by a clock. And remember: caching and compaction work together — after compaction, the new smaller context is also cached and becomes warm again.

Small → no

Preserves the warm cache

Large → yes

Much lighter turns

Based on state

Not out of habit

Together

Compact is cached too

Module summary

✓
Two axes — caching affects price/token usage; compaction affects the number of tokens.
✓
Cached tokens are still expensive — 400k @ 0.1× ≈ 40k-equivalent per turn, every turn.
✓
The 1M limit is a quantity — only compact//clear frees up space.
✓
Compacting pays off fast — 1 cold write (~25k), payback in ~1 turn, then ~2k/turn.
✓
Improves quality and latency — less context rot, lower TTFT.
✓
The guideline — small, no; large/at the limit/falling, yes.

Next module

3.2 — Cache-friendly architecture and auditing: design the prefix so it never invalidates by accident.