We assumed our Claude Code sessions were expensive because of long prompts. When we looked at where the context actually went, prompts were a rounding error. A single npm test run with verbose reporters produced eleven thousand lines. A "find where checkout totals are computed" question turned into the agent reading nine files end to end. A session that started with a clean context hit auto-compaction after forty minutes, mostly full of tool output nobody needed again.

This post covers three changes that cut our usage on the same kinds of tasks: compressing command output before it reaches the model, answering structural questions from a code graph instead of raw files, and some plain context habits. We also show how we measured, because the savings depend heavily on your repository and workflow.

Measure first

Before changing anything, get a baseline on a repeatable task. Useful built-in commands:

  • /context shows how the current context window is split between system prompt, tools, memory files and messages.

  • /cost shows token usage and cost for the session when you are on API billing.

  • Session transcripts are stored locally, and community tools such as ccusage summarise them by day and project.

Our method was simple: pick three tasks we do weekly (fix a failing test, add a field end to end, explain a module to a new engineer), run each on a fresh branch with a fresh session, record the totals, then repeat after each change. Same prompts, same repository commit.

RTK: compress command output before the model reads it

RTK (Rust Token Killer) is a command-line proxy that runs common developer commands and filters their output for an LLM: it drops progress bars and boilerplate, groups repeated lines, shows only failures for test runners, and condenses diffs and listings. You can call it directly:

rtk git status
rtk test pnpm test        # failures only
rtk err cargo build       # errors and warnings only
rtk grep "computeTotal" src

The more useful setup is the hook. rtk init -g installs a Claude Code hook that rewrites supported commands transparently, so when the agent runs git status, the shell runs rtk git status. Nothing changes in your prompts or in CLAUDE.md.

brew install rtk
rtk init -g
rtk gain            # summary of tokens saved
rtk gain --history  # per-command breakdown

rtk gain keeps its own statistics, so you can see which commands save the most. In our repository the big wins were test runners, git diff, docker and kubectl output; small commands such as pwd save nothing.

The trade-off

Filtering removes information by design. Twice we hit cases where the detail the agent needed was in the part RTK summarised away: a warning printed before the first failure, and a line in the middle of a long docker build log. When debugging something unusual, run the raw command with rtk proxy <command>, which executes it without filtering, or tell the agent to. We added a line to CLAUDE.md saying exactly that.

graphify: ask the graph before reading files

The second source of waste was exploration. "Where is the discount applied?" leads an agent to grep, open a file, follow an import, open another file. Each read puts a whole file into context.

graphify builds a knowledge graph of a folder: code is parsed into functions, classes and their relationships, communities of related code are detected, and the output lands in graphify-out/ as graph.json, a plain-language GRAPH_REPORT.md and an optional wiki. The agent can then ask questions of the graph and read only the files the answer points to:

pip install graphifyy
graphify install            # registers the /graphify skill for Claude Code
# in a session: /graphify .   builds the first graph

graphify query "where are checkout totals computed"
graphify explain "DiscountService"
graphify path "CheckoutController" "LedgerEntry"
graphify update .           # re-extract changed code after edits

Two cost notes from the project's own documentation and our use:

  • The first full build uses an LLM to extract semantic relationships from documents and to name communities, so it costs tokens once. On a medium repository that was noticeably less than a single day of exploration.

  • graphify update . re-extracts code with AST parsing only, without LLM calls, so keeping the graph current after edits is cheap. We run it once at the end of each task, from a Stop hook, rather than after every edit.

We added a rule to the project CLAUDE.md: "Before opening source files for a structural question, run graphify query." The agent follows it most of the time, and when it does, it reads two files instead of nine.

When the graph is wrong

A graph is a snapshot. If it is stale, the agent can be confidently pointed at code that moved. Keep update in your workflow, and treat graph answers as directions to the right file, not as a replacement for reading the code you are about to change.

Context hygiene

These cost nothing and mattered as much as the tools:

  • /clear between unrelated tasks. A new task does not need the old task's test output.

  • /compact with an instruction when you want to continue: "compact, keep the failing test name and the current hypothesis". You choose what survives instead of the automatic summary.

  • Delegate noisy work to subagents. A subagent has its own context window; a search that reads twenty files returns a short answer to the main conversation.

  • Keep CLAUDE.md short. It is loaded every session. Move long reference material into separate files and import them only where needed, or link to them.

  • Ask for narrow reads. "Read lines 80-160 of PricingService" instead of "look at the pricing code".

  • Deny reads of generated files. Lockfiles, build output and snapshots in .claude/settings.json deny rules stop accidental large reads.

What we measured

One repository, three tasks, totals per task averaged over two runs. Your numbers will differ; the relative order is what we found useful.

Setup

Fix failing test

Add field end to end

Explain a module

Baseline

100%

100%

100%

+ context hygiene

78%

85%

90%

+ RTK hook

49%

71%

86%

+ graphify first

46%

58%

52%

RTK helped most where commands produce long output (tests, builds). graphify helped most on questions about structure. The explain task barely benefited from RTK because it runs few commands. None of the changes made the agent's answers worse on these tasks; the two RTK misses mentioned above happened on other work.

Common mistakes

Mistake

Why it hurts

Do this instead

Optimising prompts first

Prompts are a small share of tokens

Measure with /context and /cost

Trusting filtered output during odd bugs

The needed line may be filtered

rtk proxy for raw output

Building the graph once and forgetting it

Stale graph points to moved code

graphify update . regularly

One long session for a day of work

Old output crowds out new context

/clear per task, /compact with intent

Huge CLAUDE.md

Paid for in every session

Short file, imports for detail

Key takeaways

  • Command output and file reads, not prompts, dominate agent token use.

  • RTK compresses command output transparently through a hook; use rtk proxy when you need everything.

  • graphify answers structural questions from a graph so the agent reads fewer files; keep it updated with the AST-only update.

  • Clearing, intentional compaction, subagents and a short CLAUDE.md are free wins.

  • Measure on repeatable tasks before and after each change.

References