How to cut the tokens your coding agent spends finding context
Last updated
A coding agent spends tokens on two kinds of context: what loads at the start of every session, and what it reads while looking for an answer. To spend fewer, keep always-loaded files short, load rules only for the files they apply to, clear the session between unrelated tasks, and let the agent search for the few notes it needs instead of reading files one after another. In our own use, agents with Memlo used 22%* fewer tokens than with file-based memory, on average.
Where the tokens go
Every message to the model sends the whole context window again: the system prompt, your instruction files, the conversation so far and every file the agent has read. Two things grow it more than people expect.
- Always-loaded files. CLAUDE.md, AGENTS.md and the start of auto memory load in every session, before the agent knows what the task is. Every line is paid for whether the task needs it or not.
- Searching by reading. To answer "how do our webhooks retry?", an agent without a better tool opens a README, then a design doc, then a runbook, then a decision record. Each file it reads stays in the context for the rest of the session.
Check what is loaded
In Claude Code, run /context to see what fills the context window, including the memory files that loaded. Start there before changing anything.
Keep always-loaded files short
Claude Code's documentation suggests keeping each CLAUDE.md under 200 lines, because longer files use more context and are followed less closely. Imports don't help with cost: an imported file loads together with the CLAUDE.md that imports it.
Keep only what applies to nearly every task: how to build and test, the style rules, where things live. Move everything else out.
Load rules only where they apply
Claude Code supports path-scoped rules in .claude/rules/: a rule file that applies to certain paths loads only when Claude works with matching files. Rules for the payments code don't need to load while you fix a CSS bug.
Codex merges AGENTS.md files from the repository root down to the folder you're in, so instructions for one part of the code can live in an AGENTS.md in that folder.
Clear between tasks
A long session carries everything it read into every later message. Start a fresh session, or use /clear in Claude Code, when you move to an unrelated task. Before you clear, have the agent save anything worth keeping, so the next session can find it.
Search instead of reading
The biggest saving on lookups comes from giving the agent something better than reading files in turn: a search that returns the few notes that answer the question.
With a memory server such as Memlo, the agent calls search_memories with a short query, gets back the matching memories, and reads one or two in full with read_memory. Memlo's search also takes an optional about_to hint, one to five short sentences that start with "About to", so it can find memories about the step the agent is taking, not only the topic.
This works best when memories are short and focused: one fact or decision per memory, with a plain title. A memory that tries to hold everything is just another long file.
How we measured 22%
Our own measurement: over the past year we compared several runs of the same coding work with and without Memlo, and 22% is the average reduction we could measure.
This is Memlo's own measurement from real use, not an outside benchmark. In daily use it often saves more, but 22% is the number we could measure.
Savings vary by project and workflow. They depend on how much context your agent looks up, and on how your notes are written.
A setup that keeps context small
- A short CLAUDE.md or AGENTS.md with the rules every task needs.
- Path-scoped rules or folder-level AGENTS.md files for the rest.
- A memory server for decisions and facts, searched when a task needs them.
- A session-start step that loads only the memory index: in Memlo, the
get_prime_directivetool returns your space'sprime_memory, with its key memories and a table of contents.
Setup for each agent: Claude Code, Codex, other MCP apps.
Frequently asked questions
Why is my Claude Code usage so high?
Usually because the context is large: a long session, many files read, or long instruction files that load every time. Run /context to see what is in it. Clearing between tasks and trimming always-loaded files are the quickest fixes.
Does a long CLAUDE.md cost tokens in every session?
Yes. It loads at the start of every session, and it is part of the context sent with each message after that.
Does a memory server use tokens too?
Yes. Tool descriptions take some context, and every search result the agent reads is context. The saving comes from reading a few matching memories instead of whole files, so it depends on how you work and how your notes are written.
How much does Memlo save?
In our own measurement over a year of real use, the same coding work used 22% fewer tokens with Memlo than without it, on average. See How we measured. Your savings depend on your project and workflow.
Does compacting a session save tokens?
Compacting replaces the conversation with a summary, so later messages are smaller. Details can drop out of the summary, so save important decisions before you compact or clear.
Try Memlo
Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.
Join the waitlist