ComparisonNew

Agent Memory vs Context Files

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

Alex Garrett-SmithOct 145 minAgents and context
Agent Memory vs Context Files
Agent Memory

Notes the agent writes for itself as it works, usually after you correct it.

Context Files

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.

How it works

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).

Context FilesYou write it
# 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"
Agent MemoryYou correct the agent
⏺ Bash(npm install)
  added 812 packages, created package-lock.json

› we use pnpm here, not npm. delete that lockfile
It 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.

Who it reaches

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.

You, tomorrow · same laptop, same repo
knows 5 of 5
Use pnpm, not npm in AGENTS.md
✓ knows it
Don't edit src/generated/; run pnpm codegen in AGENTS.md
✓ knows it
Billing tests need the Stripe mock running on port 12111 in your agent's memory
✓ knows it
I prefer one-line commit messages in your agent's memory
✓ knows it
Checkout code is frozen until the 20 October release in your agent's memory
✓ knows it

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.

Test yourself

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

Question 1 of 7Use pnpm, not npm.
Question 2 of 7Keep explanations short. I don't need a summary at the end.
Question 3 of 7The API tests need a local Redis instance.
Question 4 of 7Never commit .env files.
Question 5 of 7src/ has the app code and tests/ has the tests.
Question 6 of 7New endpoints go in tRPC. We're moving away from REST.
Question 7 of 7I'm working on the invoice export this week. The PR is #482.

Side by side

CriterionAgent MemoryContext Files
Who writes itThe agent, often after you correct itYou and your team
Where it livesYour machine in Claude Code and Codex; GitHub, per repository, in CopilotIn the repo, in git
Who it reachesYou, on that machine, in Claude Code and CodexAnyone who clones the repo, and agents running in the cloud or CI
What loads at the startThe MEMORY.md index in Claude Code, up to 200 lines or 25KB; notes are read when neededThe whole file
ReviewedOnly if you open the memory folder yourselfIn pull requests, like code
Clean-upClaude Code keeps notes until they're deleted; Copilot deletes unused facts after 28 daysSomeone has to remove old lines
Works across toolsNo, each tool keeps its ownAGENTS.md is read by Codex, Cursor, Copilot and Claude Code
On by defaultYes in Claude Code and on Copilot's individual plans; no in CodexWorks as soon as you write one

When to pick which

Pick Agent Memory if
  • 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
Pick Context Files if
  • 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