Published on , Aurélien Vandaële

How to reduce Claude Code token usage: what I measured on my agent chain

In Claude Code, most of the cost comes from what the session rereads, not from what it writes: every request sends the whole conversation, tool results included. Reducing usage therefore means keeping the main session's context small: one task per fresh session, command output filtered before it enters the context, and verbose work handed to subagents that return only a few lines. I measured 630,000 tokens of context at the end of a single orchestration session: that is where the bill was decided.

The problem: the session rereads everything, every turn

The Claude Code documentation is clear about it: the whole conversation goes out with every request, and every tool use sends a new request carrying its results. Prompt caching makes that rereading cheaper, not free. A one-line question asked in a session open since the morning still costs the whole conversation before it.

With an agent chain, the effect multiplies. One run of my chain, on six tasks, launched 41 agents. And the session that orchestrates them accumulates everything they send back: reports, log excerpts, diffs read along the way. In my runs, that session, not the agents, is what costs the most.

Measure before you cut

Two commands are enough to see where the tokens go:

/usage     # the session's usage (and, on a subscription, the share of skills, subagents, plugins and MCP servers)
/context   # what is filling the context right now

For my agent chain, I also keep a ledger: one line per agent and per step, with the number of tool calls and their breakdown, for example tools:33 (Bash×22,Read×4,Edit×6,SubagentHandback×1). Read after a few runs, that breakdown tells why a step is expensive: many Read calls mean a brief too thin, forcing the agent to dig; many Bash calls mean a check loop going round.

My five rules

  • One task, one fresh session. I run a plan only in a session started for it. At the end it stops; if another plan follows, it gives me the prompt to paste into a new session. In an interactive session, /clear between unrelated topics: the documentation states it costs nothing, while /compact rereads the whole conversation to summarise it. What compaction keeps and what it loses is covered in a separate article.
  • The orchestrator reads contracts, not files. Each agent returns a contract of under twelve lines: its status, the commit, the result of the checks, its concerns. During the tasks, the main session opens no brief, no log, no diff. It reads the code once, at the end of the plan.
  • A script prepares what each agent reads. A small program splits the plan and writes one brief per task: the plan header, the task's section, the interfaces of the tasks it depends on, and only the catalogue rows it cites. The plan itself is capped at 40 KB.
  • Output is filtered before it enters the context. My check script prints only CHECKS: PASS, or the failure and its error lines, plus a HUNG: line when a test runs past its deadline. Never the hundreds of lines of a passing test run.
  • No subagent for what fits in a few calls. It is written in my global instructions. A subagent makes its own requests on top of the main session's: it only pays off when the work is large, verbose, and summarises well.

The model given to each agent matters too, but less than these rules. I explain it in the article on choosing each subagent's model.

A real example: filtering commands with a hook

The documentation suggests preprocessing output with a PreToolUse hook: before each Bash command, a script can rewrite it, for example to keep only the end of a test run. That is exactly the mechanism I use, with a third-party tool, RTK, plugged into all my sessions:

"hooks": {
  "PreToolUse": [
    { "matcher": "Bash",
      "hooks": [{ "type": "command", "command": "rtk hook claude" }] }
  ]
}

The hook replaces git status, grep or a lint run with a version that compresses the output. I have nothing to ask of the model: the rule applies to every command, in every session. Other uses of hooks are in the article dedicated to them.

What went wrong

  • Agents waiting in the background. Several subagents started a command in the background, then ended their turn saying they were waiting for the result. For a subagent, ending its turn means being done: nothing had been produced. About 600,000 tokens lost across four occurrences. Since then, every agent file opens with the same rule: everything in the foreground, never wait.
  • A saving that never kicked in. The check script computes a hash of the working tree so it does not rerun checks on code already validated. But the hash included files git does not track: it never matched, and the full checks ran again for nothing. The postmortem is written, the fix is still to do.
  • A smaller gain than advertised. RTK's description promises 60 to 90% savings on development commands. Its own counter shows 18% for me, across more than 65,000 commands. Useful, but it is not what makes the difference: most of the context comes from what the session reads and keeps, not from single commands.
  • No clean before/after measurement yet for the new version of my chain, the one applying these rules. I measure tool calls per agent, not yet tokens per plan end to end.

How to start

  • Run /usage and /context on a long session, to see what really weighs.
  • Get into the habit of /clear at every change of topic, rather than letting a session live all day.
  • Write a check script that prints only the verdict and the errors, and ask Claude to go through it.
  • Keep your CLAUDE.md short: the documentation recommends under 200 lines, and moving detailed procedures into skills, loaded only when they are needed. My method is in the article on CLAUDE.md.
  • Hand verbose operations (tests, logs, documentation) to a subagent, and require a report of a few lines.

Article written with the help of AI, from my daily practice and my projects.

The whole notebook