Context engineering for coding agents: search memory instead of loading CLAUDE.md
Last updated
Context engineering means choosing what goes into a model's context window at each step, because the window is limited and everything in it costs tokens and attention. For coding agents, the biggest choice is between loading knowledge up front, as CLAUDE.md and AGENTS.md do, and fetching it when a step needs it. Keep the always-loaded files to a few rules every task needs, and let the agent search a memory for the rest, just before it acts. In our own use, agents with Memlo used 22%* fewer tokens than with file-based memory, on average.
What context engineering means
Prompt engineering is about the words of one request. Context engineering is about everything the model sees on each turn: the system prompt, instruction files, tool definitions, the conversation so far, and every file and tool result the agent has pulled in. Anthropic's engineering guide on the topic treats context as a limited resource, and names keeping notes outside the context window, which it calls structured note-taking or agentic memory, as one of the core techniques for long tasks.
A coding agent fills its context in two ways:
- Up front. Instruction files such as CLAUDE.md and AGENTS.md load at the start of every session, whatever the task.
- Just in time. The agent reads files, runs commands and calls tools while it works. What it reads stays in the context for the rest of the session.
The cost of loading everything up front
An instruction file is paid for on every task. A rule about the payments code loads while the agent fixes a CSS bug. As the file grows, it also gets harder to follow: Claude Code's documentation suggests keeping each CLAUDE.md under 200 lines for that reason.
The usual fix is to split the file and load parts by path, which Claude Code supports with rules in .claude/rules/ and Codex supports with an AGENTS.md per folder. That helps when knowledge lines up with folders. A lot of it doesn't: why a vendor was chosen, how two services talk, what broke last time someone changed the retry logic.
Search what each step needs
The other approach is to keep that knowledge as many small notes and have the agent search for the ones it needs:
- At the start of a session, load one short page: what this memory is for and its key notes. In Memlo that is
get_prime_directive, which returns the space'sprime_memory. - Before each step, search for what that step touches. Memlo's
search_memoriestakes the topic asquery, and optionallyabout_to: one to five short sentences that start with "About to" and say what the agent is about to do. That finds notes about the action, not only the topic. - Read only the best match with
read_memory, instead of opening one file after another. - After the step, save what was learned, once, as its own note.
smart_add_memorychecks for a near copy first.
Each search returns a few short notes, so the context holds what this step needs and little else.
Keep the notes editable
Context engineering also means keeping what you load correct. A note that is wrong is worse than no note, because the agent trusts it.
- Edit in place.
edit_memoryreplaces exact text, so an old rule doesn't sit next to the new one. If another agent changed the note in the meantime, nothing is written and the agent is told to read it again. - Keep history. Every change is a version.
memory_historylists them, with when each was written and by whom, andrestore_memoryrolls one back. - Retire, don't pile up.
retire_memoryhides an out-of-date note from search but keeps it readable.
Set it up
- Add Memlo to your agent: Claude Code, Codex or ChatGPT.
- Move the long tail of CLAUDE.md or AGENTS.md into memories with the prompt in Keep CLAUDE.md short.
- Add one line to the file: "Before you change code, search memlo for decisions about it."
- In Claude Code, run
/contextbefore and after to see what loads at the start of a session.
Frequently asked questions
What is context engineering?
It is the practice of choosing what goes into a model's context window at each step of a task: instructions, tools, history and retrieved knowledge. The window is limited, so the aim is to give the model what this step needs and little else.
Is context engineering the same as RAG?
Retrieval is one part of it. Context engineering also covers what loads at the start, how tool results and old messages are trimmed, and where an agent keeps notes between sessions.
Should I delete CLAUDE.md?
No. Keep it for what nearly every task needs: how to build and test, the code style, where things live, and a line telling the agent to search memory. Move the rest.
Does searching cost more tokens than reading a file?
A search returns a few short notes, and the agent reads one in full. Reading several files to find the same answer usually costs more. Run /context in Claude Code to compare on your own work.
Sources
Checked on October 30, 2026:
- Effective context engineering for AI agents, Anthropic
- Claude Code memory and CLAUDE.md
- Codex AGENTS.md guide
- Memlo: the setup page and how we measured 22%
Try Memlo
Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.
Join the waitlist