Works On My Machine logo ~/works-on-my-machine

❯ Notes from inside developer platforms. IDP, CI/CD, DX, and the gaps between them.

❯ ~/blog/the-expensive-part-is-remembering

The Expensive Part Is Remembering

Part 1 of 3 in the Context Is a Budget series. Next: Three Ways to Go Broke on Context.

The number was $6.89.

That’s what /cost reported at the end of one long Claude Code conversation. I’d run my daily ritual skills back to back in the same thread: a mid-day check-in, the evening close, and a /project-status reconcile pass. Each one dragged big raw payloads into the conversation: full task-manager dumps with nested checklists, and search hits from my second-brain RAG server with the full chunk text attached.

$6.89 isn’t a scary number. The output line was what bugged me: 45.9k tokens. The model had barely written anything. The money had gone somewhere else, and I couldn’t say where.

So I had Claude break the bill down. Nothing was broken. The shape was.

In a long agent session you don’t pay for what the model writes. You pay for what it has to re-read — so the fix is architectural, not stylistic.

Here’s where that re-reading comes from, why shorter prompts barely touch it, and the one frontmatter field that changed how my daily skills run.

Two-thirds of the bill was cache reads

A session bills on four lines: input (new tokens sent), output (what the model writes), cache write (storing context for reuse) and cache read (a later turn reusing it at a discount).

Here’s my session on those four lines:

LineTokensRate (per million tokens)CostShare
Input1.4k$3.00~$0.00~0%
Output45.9k$15.00$0.6910%
Cache read15.4M$0.30$4.6267%
Cache write (1-hour)263.3k$6.00$1.5823%
Total$6.89

Two-thirds of the dollars went to cache reads. Output — the part that feels like the work — was a tenth.

By volume it’s even more lopsided. About 15.7M tokens moved through that session, and 15.4M of them were cache reads. Roughly 98%.

A note on the rates: these are Sonnet 4.x list prices from Anthropic’s pricing page. My note from that day assumed five-minute cache writes, but the line items only add up to $6.89 with one-hour writes, which bill at 2× base input. The conclusion doesn’t depend on it. Cache reads are the largest line under either assumption.

Cached tokens got re-read about 58 times on average

An agent conversation has no memory between turns. Every turn sends the whole accumulated context back to the model: tool definitions, system prompt, every earlier message, every earlier tool result.

Prompt caching makes that affordable. The prefix — the stable front of the request, in the order tools → system → messages — is stored once.

Later turns that hit the cache are billed at a tenth of the base input rate on most models, including the Sonnet 4.x I was using. Some newer models charge even less, like 0.05x on Sonnet 5.5.

A tenth is cheap per token. It isn’t cheap at volume.

Divide the two cache lines and you get the real multiplier: 15.4M tokens read ÷ 263.3k tokens written ≈ 58. On average, each token written to the cache was read back roughly 58 times before the session ended. Early-session tokens were read far more often than late ones.

That’s the compounding. A ritual skill that dumps a full project tree into the thread doesn’t pay for that dump once. The dump joins the prefix, and every later turn re-reads it — the next skill’s turns, my follow-up questions, the evening close, all of it. Every skill’s payload gets billed again on every turn that comes after it.

Cost scales with session length, not effort

Before that session my mental model was simple: cost scales with how much the model does. More output, more tool calls, more cost. A high bill meant something was wasteful.

That holds for a single API call. It breaks in a long conversation, where cost tracks how long the session runs and how much bulk it carries. A perfectly efficient turn late in the day still costs a lot, because it carries everything that came before it. (This assumes the cache stays warm. After an idle gap longer than the cache lifetime, the next turn pays a fresh cache write instead of a read.)

It also explains why the usual advice misses. “Write shorter prompts” goes after the input line, and in my session that line rounds to zero. Trimming output goes after 10% of the bill. The 67% line responds to only two things: how long the conversation runs and how much bulk sits in it.

You can attack it two ways:

  • Compress what’s already in the context. Summarize, compact, keep a rolling summary in place of raw history. My own notes on agent memory peg a summary buffer at about a 5–10× token reduction compared with keeping everything. That shrinks what gets re-read, but you still re-read it every turn.
  • Keep the bulk out of the main context entirely. Do the tool-heavy work somewhere else, and let only the result come back.

The second is the architectural option, and it’s the one I picked.

Fork the skill, keep the bulk out of the main thread

I’ve written before about subagent context isolation as a quality lever: an explorer can read a whole codebase without polluting the developer agent’s context. This is the same mechanism seen from the billing side. Tokens in a subagent’s context aren’t in your main thread’s cache prefix, so later main-thread turns don’t re-read them. Only the returned result joins the main thread.

For skills, Claude Code makes this a single frontmatter field. I converted five of my vault’s skills — ritual-morning, ritual-update, ritual-evening, project-status, and weekly-review — to run forked. Here’s the trimmed frontmatter of .claude/skills/ritual-update/SKILL.md:

---
name: ritual-update
description: Use when user invokes /ritual update or needs a recalibration break
  during the day. Reads today's daily note, surfaces a time balance card,
  recommends Continue/Pivot/Rest, and updates the note.  # description trimmed
context: fork
argument-hint: "[optional: what you've been working on and for how long, if already known]"
---

With context: fork, Claude Code starts a fresh subagent (general-purpose unless you set the agent field) and hands it the skill body as its prompt. The raw task-manager dumps and full RAG chunks live and die inside that subagent. Only the final artifact comes back to the main conversation: the updated note, the time-balance card, the recommendation.

The main thread carries accumulated context on later turns. A fork keeps the raw payload in its own context and returns only the useful result.
Each main-thread turn carries accumulated context again. A fork holds the raw payload and returns only the task result.

Gotcha: since v2.1.218, forked skills run in the background by default, with the narrower tool set background subagents get. If the skill needs tools outside that set, set background: false.

This matters most for the skills that run often. ritual-update is the check-in I use to interrupt a hyperfocus stretch, and it can run several times a day. Before the change, each run left another layer of payload in the main thread for every later turn to re-read. Now each run costs what it costs and then leaves.

A fork starts with zero continuity

I got this wrong twice before I got it right.

First mistake: I assumed I had to wire it up myself. My first instinct was to rewrite each skill so it called the Agent tool to spawn a subagent by hand. That works, but it’s plumbing I didn’t need. The skills documentation lists context: fork as a first-class field. I checked the docs before writing any plumbing, which is the only reason I didn’t build it.

Second mistake, and the important one: I assumed “fork” meant continuity. I pictured the forked skill seeing everything I’d already said and simply keeping its tool noise to itself. Wrong. Per the docs, “The subagent doesn’t see your conversation history.” Its whole world is the skill body, the project’s CLAUDE.md, and whatever its tools can reach. Despite the name, this is not a fork of the current conversation — if a task needs the history, you fork the conversation instead.

So isolation here doesn’t mean “keep continuity, hide the noise.” It means zero continuity, driven entirely by files and tools. That’s stricter than I’d planned for, and it changed the skills in two ways.

Pass forward what you already know. Every forked skill now carries a hand-off note telling the caller to put any context from the current turn into the argument text, where it arrives as $ARGUMENTS. From the same SKILL.md:

> Runs as a forked subagent (defaults to `general-purpose`) so its
> TickTick/second-brain tool calls stay off the main conversation's cache.
> When invoking this skill, pass along anything already known from this turn
> — what the user's been working on, how long, session details already
> mentioned — as the argument text; it arrives here as `$ARGUMENTS`.

The skill reads $ARGUMENTS so it doesn’t re-ask questions I’ve already answered. The argument-hint in the frontmatter tells the caller what’s worth passing.

Keep the interactive part in the main thread. reconcile is my heaviest skill — a single run can pull dozens of full nested project and checklist dumps. It’s also interactive: it asks me about low-confidence matches and confirms backfills before writing them. A forked subagent can’t hold a back-and-forth with me, so the skill tells the main thread to own the conversation while the fork does the heavy pulling.

Forks aren’t free. They’re billed once.

Don’t read this as “subagents are cheaper.” They aren’t. Anthropic’s write-up on their multi-agent research system reports that agents use about 4× the tokens of a chat interaction, and multi-agent systems about 15×. A fork pays its own setup and does its own reading.

The win isn’t fewer tokens. It’s where the tokens land:

  • In the main thread, a payload costs roughly its size × every remaining turn in the session. It keeps charging for the life of the session.
  • In a fork, a payload costs its size × the fork’s own turns, and then it’s gone. What comes back is the distilled result — Anthropic’s context engineering post says subagents often return summaries of 1,000–2,000 tokens.

Spent once beats re-billed on every later turn, and the gap widens the longer the main session runs.

The “after” number doesn’t exist yet

I logged that $6.89 session as a benchmark and set myself a task to compare a forked day against it. I expect the main thread’s cache-read line to grow much more slowly across a day of check-ins, since each ritual no longer leaves its payload behind. That’s an expectation, not a result. To check it, I’ll run the same sequence of skills in one conversation and compare two things: total cache-read tokens, and how much the cache-read line jumps after each skill. If isolation works, the jumps should mostly disappear, and only the returned artifacts should add up.

Look at the cache-read line first

If you run long agent sessions, check the cache-read line before you touch your prompts. It grows fastest, and most of it is stuff you stopped looking at hours ago.

Context is a budget, and the line item that grows fastest is the one you never see generated.

That’s the dollar side of the ledger. Next up is the failure side: the three kinds of missing context, why the obvious fix overspends, and why the fix for one of them is a tool that can never be deferred.

Further reading