Skip to content
mentoor

Topic 2 of 5 · 4 min read

What to keep out of memory files

Goal: Find the lines in a memory file that waste context, leak secrets or will go stale, and say where each should live instead.

Every line in a memory file is read on every run, so keep out anything that is secret, duplicated, enforced by a tool, or likely to go stale. A line that does not change the agent's behaviour still costs context and dilutes the lines that do.

Check yourself · 1 of 3

Which of these should never be written into a committed memory file?

Choose one answer

Why it matters

Memory files are committed, shared with the team and sent to a model provider with each request. A mistake here is repeated in every session. The Claude Code docs warn that contradictory instructions may be resolved arbitrarily, and that longer files reduce adherence. A bloated, out-of-date file is worse than no file, because the agent follows it with confidence.

Five things to cut

  1. Secrets. API keys, tokens, passwords, connection strings with credentials. The file is in git and in the prompt. Name the variable instead: "the key is in STRIPE_KEY, loaded from .env."
  2. Copies of other docs. Pasted README sections, API references and architecture essays. Link or point to the file ("see docs/architecture.md for the queue design") so there is one source and the agent reads it only when needed.
  3. Style rules a tool enforces. "Use 2-space indent, single quotes, sorted imports" belongs in the formatter and linter config. The agent runs the tool and gets exact feedback. A prose rule is slower and less reliable.
  4. Facts that rot. Counts, version numbers, a list of every file, "currently we are migrating X". If a line will be false in a month and nobody will notice, delete it or point to where the truth lives (package.json, a task file).
  5. Wishes and filler. "Be careful", "think step by step", "write high-quality code". They add no information.

A useful test for any line: "If I delete this, would the agent make a mistake it would not otherwise make?" If not, delete it.

Before and after

 # Shop API
-Use 2 spaces, single quotes, no semicolons, sorted imports.
-The database password is hunter2-prod; connect to db.internal:5432.
-We have 41 endpoints. The first is GET /users, the second is ...
-(full copy of the README setup section, 80 lines)
+Formatting is enforced by `pnpm lint --fix`. Run it before finishing.
+DB credentials come from `DATABASE_URL` in `.env` (never commit it).
+Endpoints are listed in `openapi.yaml`. Setup steps: `README.md`.

The result is shorter, has no secret, and every fact has one home.

What goes wrong

  • A leaked credential. Once pushed, treat it as exposed: rotate it, not just delete the line.
  • Stale rules. The file says "tests use Jest" after the move to Vitest, and the agent writes Jest tests.
  • Copy drift. The pasted README and the real README disagree, and the agent trusts whichever it read last.
  • Personal preferences in the team file. Your editor habits belong in your user-level file, not the shared repo.

Examples

The pasted API key

A file contains OPENAI_API_KEY=sk-...redacted so the agent can run the demo. The file is committed. Fix: remove the line, rotate the key, and write "Set OPENAI_API_KEY in .env (see .env.example)."

A rule the linter already owns

The file says "Always add a trailing comma in multi-line objects." The project has a Prettier config that does this on save. Delete the line. If the agent forgets, pnpm lint --fix corrects it, with no context spent.

Key points

  • Never put secrets in a memory file; name the environment variable and where it is loaded from instead.
  • Point to existing docs rather than pasting copies, so there is one source of truth.
  • Leave style rules to the formatter and linter, which give the agent exact feedback.
  • Delete facts that will go stale, such as counts, version lists and "currently migrating" notes.
  • Test each line by asking whether removing it would cause a mistake the agent would not otherwise make.

Common mistakes

  • Pasting the whole README into the memory file "to be safe".
  • Keeping a line because it was true once, with no one responsible for checking it.
  • Encoding formatting rules in prose when a config file would enforce them.
  • Deleting a leaked secret from the file but not rotating it.

Check yourself · 2 of 3

The memory file says 'Use single quotes and 2-space indent', and the repo has a Prettier config. What should you do?

Choose one answer

Check yourself · 3 of 3

A memory file says 'We currently have 41 endpoints'. What is the main problem?

Choose one answer

Practice items, not counted towards your mastery.

Start here