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:

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:

  1. 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's prime_memory.
  2. Before each step, search for what that step touches. Memlo's search_memories takes the topic as query, and optionally about_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.
  3. Read only the best match with read_memory, instead of opening one file after another.
  4. After the step, save what was learned, once, as its own note. smart_add_memory checks 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.

Set it up

  1. Add Memlo to your agent: Claude Code, Codex or ChatGPT.
  2. Move the long tail of CLAUDE.md or AGENTS.md into memories with the prompt in Keep CLAUDE.md short.
  3. Add one line to the file: "Before you change code, search memlo for decisions about it."
  4. In Claude Code, run /context before 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:

Try Memlo

Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.

Join the waitlist