Markdown version of https://extraheadroom.com/reduce-claude-code-costs

# How to reduce Claude Code costs

Most of the tokens in a Claude Code session are machine-generated context rather than your prompts: files it reads, terminal output, logs, and history sent again on every turn. On a Pro or Max plan those tokens drain your 5-hour and weekly windows; on the API they are the bill. Five levers cut them, roughly in order of effect.

## 1. Compress the context before the model sees it

The largest share of spend is bulky, repetitive context: build logs, test output, JSON fixtures, and file content carried from turn to turn. [Headroom](https://github.com/headroomlabs-ai/headroom) sits between Claude Code and the API and compresses that content locally before forwarding it: about 50% fewer tokens on the noisy items it compresses, typically 25-50% across a session. The compression is reversible, so the model can pull back the original whenever it needs the detail. It works alongside Anthropic's prompt cache rather than against it: a smaller conversation prefix is cheaper to carry whether or not it is cached.

## 2. Make terminal output quieter

Every command Claude Code runs sends its full output back to the model, and a failing build can add thousands of lines that every later turn carries. [RTK](https://github.com/rtk-ai/rtk) rewrites common commands into token-lean equivalents, so Claude Code reads a summary of `git status` or a test run instead of the raw dump. Quieter test reporters and keeping generated files out of the working tree help the same way.

## 3. Stop re-reading the repository and documents

Exploring a codebase by grepping and opening files pulls in far more than the answer needs, and [sub-agents](/blog/claude-code-subagents-token-costs) each pay for their own copy. [Graphify](https://github.com/safishamsi/graphify) builds a queryable graph of the project so Claude Code can look things up instead of reading files whole, and [Engram](https://github.com/Gentleman-Programming/engram) keeps useful context across sessions, including through compaction. For PDFs and Office files, [MarkItDown](https://github.com/microsoft/markitdown) converts them to plain Markdown before Claude Code reads them.

## 4. Make the agent write less

Output tokens count too, and on the API they are priced several times higher than input. [Ponytail](/ponytail-claude-code) is a plugin that pushes Claude Code toward the smallest change that solves the problem, which means shorter diffs and less to review. [Caveman](https://github.com/JuliusBrussee/caveman) shortens its prose replies. Both work on the response side, which the tools above leave alone.

## 5. Watch the windows instead of upgrading

Before moving up a plan, check where the tokens went. The [Claude Code usage limits guide](/claude-code-usage-limits) explains the 5-hour and weekly windows, and [why Claude Code is so expensive](/why-is-claude-code-expensive) covers the patterns that drain them. If you pay per token on the API, [reducing Claude API costs](/reduce-claude-api-costs) adds caching, model choice, and batching.

## What to expect

Short, focused prompts will not get much cheaper. Noisy work will: debugging from logs, shell-heavy tasks, and codebase exploration are where these tools remove the most. Headroom alone typically removes 25-50% of a session's tokens, so noise-heavy work can stretch the same plan up to twice as far; the other tools add to it on the sources they target. The [benchmarks](/#benchmarks) show savings by workload type. Judge them on a real task you already do rather than a toy prompt, and compare the token count before and after. Fewer tokens per task also means less electricity per task; see [how Headroom makes AI coding more sustainable](/blog/sustainable-ai-coding).

The [Headroom app](/) runs Headroom for you and turns on RTK, MarkItDown, Ponytail, and Caveman as one-click [add-ons](/docs/add-ons), so you do not have to install and update each tool yourself.
