Skip to main content

What the Agent Remembers

Share

Share this page

Pass it to someone who needs it.

Star on GitHub

Key takeaway: Give the agent a memory file it always reads

Agents are brilliant and amnesiac. Close one and reopen it, and your project, your rules, your whole world are gone. A memory file fixes that: one file the agent reads automatically at the start of every session, so it walks in already knowing the room instead of asking you again.

9.6.1The file your agent reads first

You met this idea as your rules file. The memory file is that file, made real for each tool. It holds what is always true: who you are, how you work, what must never happen. A few lines, read before the agent does anything.

# Project: my-app - Stack: Next.js + Postgres. One language, TypeScript. - New code goes under src/, one folder per feature. - Never commit secrets. Read them from .env. - Run the app and confirm it works before saying done.

Keep it the constitution, not the encyclopedia: the standing law, not every detail.

9.6.2Find your tool's file

Every serious agent tool auto-reads one file. Same idea, different name:

ToolFile it reads
Claude CodeCLAUDE.md at the repo root
CodexAGENTS.md at the repo root
Cursor and most editorsa rules file or .cursor/rules/ folder

Find yours and treat it as the first thing you set up, not an afterthought. Any equivalent works; the file changes, the idea does not.

There is now a shared convention for this, AGENTS.md, a single file over 30 tools read the same way. If your tool supports it, one file covers most of them at once.

9.6.3No built-in file? Inject it yourself

If your agent has no native memory file, you build the behavior. Keep one canonical file, context.md, and paste it (or have a tiny wrapper prepend it) at the start of each session.

The mechanism does not matter. The principle does: the standing truth of your project reaches the agent before it does anything else.

9.6.4Keep it short, or it rots

Every line of a memory file is re-sent on every turn, so bloat is a tax you pay forever, on requests that never even touch the topic. Keep it brutally short: only what must be true always. Push topical detail into skills the agent loads on demand.

Treat a couple hundred lines as a rough ceiling. Past that, every extra line taxes every request whether or not it is relevant. If yours is longer it is doing too much, so move the topical detail into a skill.

One question sorts anything you are about to add. Would this need to fire on a turn that does not touch its topic? If yes, it belongs here. If no, it belongs in a skill that loads when the topic comes up.

For facts that pile up, keep an index instead of a wall:

# MEMORY.md - Auth: we use email + magic link. Details in auth/notes.md. - Billing: Stripe, test mode until launch. See money/stripe.md.

One line per durable fact, the detail in a linked file. Fix any line the day the fact changes; a short current file beats a long stale one every time.

9.6.5Let the agent write it, but verify what it recalls

You do not maintain this by hand. When you correct the agent, tell it to save the correction, and the file grows itself. Session 1 you fix a mistake. Session 40 it never repeats, because the note loads every time.

Two disciplines keep it from rotting. The first: one fact per line, deduped. The second: a recalled line that names a file or a setting is a hint to check, never a fact to trust.

A note written months ago can point at something since renamed. Treat old memory like old documentation, and verify against reality before acting on it.

You correct once and the agent saves it; a recalled line naming a file is a hint to verify, not a fact.

9.6.6Set up your memory file

This prompt has your agent create the right file for your tool:

Ready prompt
Act as a senior engineer setting up my agent's memory. Find the memory file my tool auto-reads (CLAUDE.md, AGENTS.md, or a rules file), create it at the right place, and seed it from what I already have: my rules file, my conventions, my architecture map, and my module boundaries. Do not write a second version of any of them. Keep it short, only what must be true every session. For anything topical, write one line pointing at the file that holds it: my spec, my project docs, my decision log. If two of those already contradict each other, tell me which to fix rather than copying both in. If you need the full reasoning behind this step, read https://zalt.me/guides/vibe-coding/ai-os/agent-memory My tool and project:

Do this now: paste the prompt so your agent writes its own memory file, then read it and cut any line that is not true on every single session.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Star on GitHubContribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license