densilo

Guide

How to reduce
Claude Code token usage.

Most of a long session's input is old tool output, sent again on every turn. To use fewer tokens: start a fresh session for unrelated work, compact at a natural break, keep tool output short, and avoid reading the same file twice. The same applies to Codex.

Why usage climbs

Every request an agent makes includes the whole session so far. In our longest recorded sessions, the content sent to the model added up to a median of about 340 times the largest context the session held for Claude Code, and about 170 times for Codex. Most of it was tool output: command output, file contents, and the commands the agent wrote. The full breakdown.

1. Start a fresh session for unrelated work

Everything in the context is re-sent until the session ends. When you switch to a task that doesn't need what came before, start over: /clear in Claude Code, /new in Codex. Put anything the next task needs in a short note or in CLAUDE.md / AGENTS.md instead of carrying the whole history.

2. Compact at a natural break, not at the limit

/compact replaces the history with a summary, so every later turn is cheaper. Do it after a piece of work is finished, before the context is at its largest. A summary can drop details you still need, such as exact error messages or IDs, so compact between tasks rather than in the middle of one.

3. Keep tool output short

Command output was the largest single part of the input in our sessions: 26% for Claude Code and 30% for Codex. Ask for line ranges instead of whole files, use quiet flags on builds and tests, and pipe long logs through tail or grep. A line in CLAUDE.md or AGENTS.md asking the agent to do this works for every session.

4. Don't read the same file twice

About half of all file-reading output, for both agents, was a file the session had already read. The earlier copy stays in the context and is re-sent on every turn after. Point the agent at the part of the file that changed, or at the function it needs.

5. Watch screenshots and browser pages

Browser automation was 12% of Claude Code's input in our sessions. Each screenshot stays in the context like any other tool output. Prefer reading page text over taking screenshots when the text is enough.

What about usage limits?

Subscription plans count usage against a limit, and a long conversation uses more of it with every message because the whole history is sent each time. Everything above helps for that reason. With Densilo, a Claude Pro or Max plan does 2× more work before you hit your usage limit.

Do it automatically

Densilo runs on your machine between the agent and the model. Old tool output the model has already seen is sent in short form, and the full text is kept so the model can fetch it back exactly. In our replays of long sessions, it cut input cost by up to 50% for Claude Code and up to 49% for Codex (medians 32% and 22%). How we measured, and what a replay doesn't show.

Questions

Does prompt caching make the re-sent tokens free?

No. Cache reads cost much less than new input, but they still count. In our sessions, about three quarters of Claude Code's input cost was re-reading earlier context.

Does compacting lose information?

It can. A summary keeps what the agent judged important at that moment. Densilo works differently: it shortens old tool output but keeps the full text, which the model can fetch back.

How much will I save?

It depends on how long your sessions run; short sessions save little. Try the token cost calculator, or install Densilo and run densilo benchmark to replay your own recent sessions offline.

See your own number.

Install Densilo and run densilo benchmark in a repository you work in. It replays your recent Claude Code and Codex sessions offline: no model is called and nothing leaves your machine.