Topic 2 of 5 · 4 min read
Content that bloats or endangers a memory file
Goal: Find the lines in a memory file that are secrets, duplicated docs, stale or unenforceable, and replace each with a pointer, a tool check or nothing.
Every line in a memory file is read on every session, so a line that is secret, copied, stale or unenforceable is not neutral: it costs tokens, can leak data and can mislead the agent.
Check yourself · 1 of 3
A teammate wants to paste the staging API key into the memory file so the agent can deploy. What is the best response?
Why it matters
Memory files are committed to git, shared with teammates and sent to a model provider on every run. They also compete for the agent's attention. A long file of mixed value makes the important rules harder to follow. A wrong line is worse than a missing one, because the agent trusts it.
Four kinds of line to remove
- Secrets. API keys, passwords, tokens, connection strings with credentials, private URLs. The file is in version control and in prompts. Write "credentials come from
.env; never print or commit them" and keep the values out. - Copied documentation. A pasted API reference, a full style guide, a README section. It goes stale the day the original changes. Replace it with a pointer: "Auth flow: see
docs/auth.md". The agent can open the file when it needs it. - Stale or guessed facts. Old commands, renamed folders, "we use library X" after you removed it. Check each command by running it.
- Unenforceable style advice. "Keep functions short", "use meaningful names", "format code nicely". A formatter and a linter enforce this exactly and for free. Put the command in the file ("run
eslint --fix") and let the tool judge. Better still, run it automatically with a hook or in CI.
A fifth, softer kind is the long tutorial: step-by-step guides to a rarely used task. Move it to a separate document or a skill that loads only when needed, and leave one line in the memory file saying it exists.
Before and after
Before:
## Deploy
Our staging key is sk_test_51Hxxxx. Use it when deploying.
## Style
Write clean code. Use good variable names. Keep functions small.
## Payments API
(300 lines pasted from the vendor docs)
After:
## Deploy
- Staging deploy: `make deploy-staging`. Keys are read from `.env`; never print them.
## Style
- Run `pnpm lint --fix` before finishing; CI enforces it.
## Payments API
- Vendor reference: see `docs/payments-api.md`.
The key is gone (and must also be rotated, since it was committed). Style is a tool check. The long paste is a pointer.
What goes wrong
- Leaked credentials. A key pasted "just so the agent can test" ends up in history, in a pull request and in a prompt log.
- Silent drift. A pasted section no longer matches the real API, and the agent writes code against the old version.
- Dead weight. A 600-line file where 40 lines matter. The rules that matter get diluted.
- Rules nobody can check. "Be careful with performance" cannot be verified, so no one ever knows whether it was followed.
Read your file once a quarter with one question per line: is this a secret, a copy, out of date, or something a tool already enforces?
Examples
Triage of a messy file
Four lines, four decisions:
DB_URL=postgres://admin:hunter2@db.internal/app: remove, rotate the password, point to.env.example.Always write meaningful names: delete; the model already tries, and review catches the rest.(pasted OpenAPI spec): replace withAPI spec: openapi.yaml.Run tests with npm testin a pnpm repo : correct topnpm test, after running it.
Turning prose into a check
Instead of "keep imports sorted", add pnpm lint --fix to the file and enable the import-order rule in the linter. If the agent forgets, a hook or CI step fails loudly. A rule in prose fails silently.
Key points
- Never put secrets in a memory file: it is committed, shared and sent to a model provider.
- Replace copied documentation with a pointer to the source, so it cannot go stale.
- Check every command and path by running it; a wrong line is worse than a missing one.
- Style advice a linter or formatter can enforce belongs in a tool check, not in prose.
- Move rarely needed tutorials to a separate doc or skill and leave a one-line pointer.
Common mistakes
- Pasting a credential so the agent can run something, then forgetting it is now in git history.
- Copying vendor docs into the file instead of linking to them.
- Keeping a rule that a linter already enforces, which doubles the maintenance.
- Never re-running the listed commands, so stale ones stay for months.
Check yourself · 2 of 3
A memory file has 300 lines copied from a vendor's API docs. What should replace them?
Check yourself · 3 of 3
Which line is best handled by a tool check instead of a memory-file sentence?
Practice items, not counted towards your mastery.
Start here
- AGENTS.md (opens in a new tab)DocsFree
The open format, what to put in the file and which agents read it.
- How Claude remembers your project (Claude Code docs) (opens in a new tab)DocsFree
How CLAUDE.md, AGENTS.md, imports and path-scoped rules load, and how to troubleshoot ignored files.
- Custom instructions with AGENTS.md (OpenAI Codex docs) (opens in a new tab)DocsFree
How Codex discovers AGENTS.md files from global to nested, and its 32 KiB default size limit.
More for this topic
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
Advice on what to put in CLAUDE.md, keeping it short and giving the agent ways to verify its work.