CLAUDE.md and AGENTS.md: give your coding agent a memory
What CLAUDE.md and AGENTS.md are, where they live, what to put in them (and what to leave out), and how to share one file between Claude Code, Codex and Cursor. With a real example from this site.
By Shakir Sajad & Claude (AI by Anthropic) · 3 min read · Updated 2026-11-19
Step 03 of the agentic coding learning path.
Why it matters
Every new session starts from zero. Without a memory file, you re-explain the same things: how to run the build, which folder not to touch, that you hate a certain style. A memory file says it once, for every session after.
Anthropic's memory guide gives a simple rule for when to add a line:
- Claude made the same mistake twice
- A review caught something it should have known
- You typed the same correction as last session
- A new teammate would need the same context
Where the files live
| File | Where | Who it's for |
|---|---|---|
| Global rules | ~/.claude/CLAUDE.md | You, in every project |
| Project rules | CLAUDE.md or AGENTS.md in the project folder | Everyone on the project (commit it) |
| Personal project notes | CLAUDE.local.md (add to .gitignore) | Only you, this project |
Claude Code also keeps an auto memory: notes it writes itself from your corrections. You can view and edit both with /memory.
What to put in (and leave out)
Anthropic's best practices say the file works best when it only holds what Claude couldn't work out from the code:
Put in:
- The exact commands to build, test and lint
- Places where the code is misleading
- Decisions that aren't written anywhere else
- Anything you've corrected twice
Leave out:
- Your file layout and architecture. It reads the repo itself.
- Long procedures. Those go in a skill.
- Shouting. ALL CAPS and IMPORTANT make it over-apply rules.
The memory guide recommends staying under 200 lines.
A real example: this site
This site's CLAUDE.md is one line: @AGENTS.md. That pulls in the shared file, so any agent gets the same rules. A few lines from it:
## Start here
- Read docs/README.md first. "What's pending?" → docs/PENDING.md.
- After finishing work: move the item from PENDING to DONE, and log any owner decision.
## Content rules
- Prompts always go in a boxed code block.
- Every guide ends with homework.
- Every fact needs a source. Never invent numbers or personal experiences.
## Git
- Don't push unless the owner says "push". Commit only when asked.And a few lines from my global file, which loads in every project:
- Never run heavy work in parallel. One at a time. (8 GB laptop.)
- Never add coloured glow shadows or looping bouncing animations.
- End every reply with a reminder to run /compact.None of these can be guessed from the code. That's the test.
One file for every agent
If you use more than one tool, keep the shared rules in AGENTS.md. It's an open format read by Codex, Cursor, Jules, Claude Code and others. Then make CLAUDE.md import it:
@AGENTS.md
## Claude Code
{Claude-only notes here}Claude Code can also read AGENTS.md on its own when there's no CLAUDE.md. The import works everywhere, so it's the safe choice.
Prompt: write your first one
Read this project and draft a CLAUDE.md under 60 lines. Include only what you couldn't work out from the code: the exact build, test and lint commands, misleading spots, and decisions. Then ask me 5 questions about rules and decisions only I know, and add my answers.When a line keeps getting ignored
A memory file is advice. The model reads it and usually follows it. If a rule must hold every time (never push, never read the secrets file), the docs say it belongs in a hook or a deny rule, which the tool enforces no matter what. That's the "Rules that can't break" step in the learning path.
What's next
Now brief it well: prompts for coding agents. Then plan before you code.
Do this now
- Run /init in your project Claude Code drafts a CLAUDE.md from your code. Then delete what it can work out itself. (10 min)
- Add your check commands The exact build, test and lint commands. The single most useful lines. (5 min)
- Write down three things the code doesn't show A decision, a gotcha, a rule like 'don't push without asking'. (10 min)
- Make one global rules file ~/.claude/CLAUDE.md for habits you want in every project. (10 min)
- Share it with other agents Put shared rules in AGENTS.md and import it with @AGENTS.md from CLAUDE.md. (5 min)
Frequently asked questions
What is CLAUDE.md?
A plain Markdown file of instructions that Claude Code loads at the start of every session: commands, conventions, decisions and rules the agent can't work out from your code.
What is AGENTS.md?
An open format for the same idea, read by many coding agents including Codex, Cursor, Jules and Claude Code. The AGENTS.md site says it's used by over 60,000 open-source projects and is now stewarded by the Agentic AI Foundation under the Linux Foundation.
Should I use CLAUDE.md or AGENTS.md?
If you use more than one agent, keep shared rules in AGENTS.md and put @AGENTS.md at the top of CLAUDE.md, with Claude-only notes below it. Claude Code can also read AGENTS.md directly when there's no CLAUDE.md.
How long should it be?
Short. Every line is read on every task. Anthropic's memory guide recommends staying under 200 lines and only writing what Claude can't find in the code.