Agent Memory vs Context Files
Should you let your coding agent remember things for itself, or write them down in a context file?

Notes the agent writes for itself as it works, usually after you correct it.
Files like AGENTS.md and CLAUDE.md that you write and commit, loaded at the start of every session.
Context files and memory do different jobs, so chances are you'll want both. I'd start with a short AGENTS.md or CLAUDE.md for the things every agent on the repo needs to know and can't work out from the code. Then leave memory on for your own preferences and whatever you're working on, and every now and then move anything your team needs over to the file.
Who writes it, where it lives and when it loads
Context files and memory both end up as text in your agent's context window. What's different is who writes that text, where it's stored and when the agent reads it. Claude Code supports both, so let's use it for the examples below (pick a question to compare them).
# AGENTS.md ## Commands - Install: pnpm install - Test: pnpm test ## Rules - Don't edit src/generated/. Run pnpm codegen instead.Then you commit it
$ git add AGENTS.md $ git commit -m "Add test and codegen commands"
⏺ Bash(npm install) added 812 packages, created package-lock.json › we use pnpm here, not npm. delete that lockfileIt saves a note for itself
--- name: use-pnpm description: This project uses pnpm, not npm type: feedback modified: 2026-10-13T09:42:00Z --- Use pnpm for installs and scripts. Why: I ran npm install and was corrected.
With a context file, you decide what the agent should know and write it down before it's needed. Memory works the other way round. The agent decides what's worth keeping, usually after something's gone wrong.
In Claude Code, asking the agent to "remember" something saves it to memory. If you want it in CLAUDE.md or AGENTS.md, ask for that file by name.
The repo, paths and file contents are examples. Loading rules and limits are from Claude Code's memory docs; other agents load their files differently.
Which agents can see your notes?
Memory in Claude Code stays on the machine it was saved on, so it's only ever helping you. Let's say you've spent a week in a repo and ended up with two notes in AGENTS.md and three more in your agent's memory. Pick who starts the next session to see what their agent knows, and then have a go at moving a note into AGENTS.md.
On your own machine, your agent knows everything, so it's easy to think memory has it all covered. Choose A teammate or A cloud or CI agent to see what's missing.
This is a simulation of local memory in Claude Code, where memory files are not shared across machines or cloud environments
. Codex also stores memory locally. Copilot Memory is stored by GitHub and shared per repository, so a teammate with Copilot Memory on would get repository facts too.
Where would you put it?
Let's put this into practice with a short test. Here are seven things you might want an agent to know, so pick a context file, memory or neither for each one. Once you've answered, I'll show you where I'd put it and why (a few don't belong in either).
0 of 7 answered
Use pnpm, not npm.
Keep explanations short. I don't need a summary at the end.
The API tests need a local Redis instance.
Never commit .env files.
src/ has the app code and tests/ has the tests.
New endpoints go in tRPC. We're moving away from REST.
I'm working on the invoice export this week. The PR is #482.
Side by side
| Criterion | Agent Memory | Context Files |
|---|---|---|
| Who writes it | The agent, often after you correct it | You and your team |
| Where it lives | Your machine in Claude Code and Codex; GitHub, per repository, in Copilot | In the repo, in git |
| Who it reaches | You, on that machine, in Claude Code and Codex | Anyone who clones the repo, and agents running in the cloud or CI |
| What loads at the start | The MEMORY.md index in Claude Code, up to 200 lines or 25KB; notes are read when needed | The whole file |
| Reviewed | Only if you open the memory folder yourself | In pull requests, like code |
| Clean-up | Claude Code keeps notes until they're deleted; Copilot deletes unused facts after 28 days | Someone has to remove old lines |
| Works across tools | No, each tool keeps its own | AGENTS.md is read by Codex, Cursor, Copilot and Claude Code |
| On by default | Yes in Claude Code and on Copilot's individual plans; no in Codex | Works as soon as you write one |
When to pick which
- It's about how you like to work
- It's about what you're working on right now
- You'd rather not edit a file every time you correct the agent
- You're happy to check what it's saved now and then
- Everyone working in the repo needs to know it
- The agent can't work it out from the code
- You want changes to it reviewed in a pull request
- You run agents in the cloud or CI, or use more than one tool
How we tested
- Task
- Compared how Claude Code, Codex and GitHub Copilot store and load memory with how they read AGENTS.md and CLAUDE.md, using each tool's docs as of 13 October 2026.
- Evidence
- The docs, and ETH Zurich's Evaluating AGENTS.md study. The repo and notes in the demos are made up, and the demos don't run an agent.
- With
- Claude Code docs, Codex docs, GitHub Copilot docs, Evaluating AGENTS.md, ETH Zurich