Claude Code & Context Engineering

Agent Memory Patterns: What Coding Agents Should Persist, Where, and What to Forget

19 November 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Memory patterns for coding agents that actually work: the file-based patterns for facts, decisions and handoffs, what to persist, and why forgetting is a feature.

Template inside: Memory-file template set

Contents
  1. The layers at a glance
  2. Pattern 1: the standing file
  3. Pattern 2: the decision log
  4. Pattern 3: the rolling handoff
  5. Pattern 4: scoped memory, or, memory with an address
  6. Pattern 5: auto memory, the layer the agent writes itself
  7. What to forget, on purpose
  8. A worked example: one event, four layers
  9. Memory-file template set
  10. How we work here
  11. 2026-11-10 — [Decision in one sentence]
  12. 2026-11-18 — [Decision]
  13. Putting the patterns together

Give a coding agent a place to write notes and, left alone, it will remember everything and retrieve nothing. The transcripts pile up, last month’s workaround reads like current instructions, and the one fact that mattered sits buried under forty that did not.

This guide takes the opposite approach: memory as a small set of named patterns, each with one job, one home, and a deletion habit. It covers the standing file, the decision log, the rolling handoff, scoped topic files, and the newer agent-written layer — plus what to forget on purpose.

The mechanics below are checked against Anthropic’s Claude Code memory documentation and the agents.md format as of November 2026, because loading behaviour is exactly where memory advice goes stale.

The layers at a glance

Layer Holds Who writes it When it loads
Standing file How work is done here You Every session
Decision log What was settled, and why You, append-only When a task touches the area
Rolling handoff What is true right now You or the agent, rewritten Start of the next session
Scoped topic files One subsystem’s detail You Only when the task touches it
Auto memory The agent’s own notes The agent Every session, capped

Five layers sounds like a lot. In practice most projects need the first three, add the fourth when the standing file bloats, and get the fifth whether they asked for it or not — which is why it needs rules too.

Pattern 1: the standing file

Every agent setup already has one, whether it is called CLAUDE.md, AGENTS.md, or GEMINI.md: the file loaded at session start carrying identity, commands, conventions, and boundaries. Its memory job is procedural — how work is done here — and its cardinal rule is that everything in it must be checkable against the repo today.

The moment it records history (“we migrated to X in March”) it starts lying by omission, because the agent reads history as instruction. Keep the standing file present-tense. The format that works is in the CLAUDE.md structure that actually works, and the cross-tool version of the same pattern is mapped in the AGENTS.md field guide.

What the loading mechanics mean for you

Claude Code’s documented behaviour, checked November 2026, shapes how this file should be written:

One more fact worth internalising: Anthropic’s docs state plainly that these files are context, not enforced configuration. A standing file guides the agent; it does not guarantee compliance. Anything that must never happen belongs in a hook or a permission rule, not in prose.

Note: Block-level HTML comments in a CLAUDE.md are stripped before the file loads, so notes to human maintainers cost no context. Use them for the “why” you do not want to re-explain in reviews.

Pattern 2: the decision log

Decisions are the highest-value memory an agent can have, because re-deriving them is expensive and re-litigating them is worse. The pattern is an append-only file of dated entries — decision, one-line reason, and what would change it — that the agent reads when a task touches the area.

Append-only matters. Editing a decision’s history destroys the very thing the log exists to preserve, which is why the current state is what it is. When a decision is reversed, add a new entry that names the reversal; never quietly rewrite the old one.

Keep entries brutally short. A decision log that reads like meeting minutes will not be read; one that reads like a changelog will be. Three lines per decision is a good ceiling, enforced by the template below.

Pattern 3: the rolling handoff

Working state — what is done, what is unverified, what is next, what already failed — belongs in a handoff file that is rewritten at the end of each session and read at the start of the next.

The rewriting is the pattern. It forces a fresh judgement about what still matters, and it keeps the file at one screenful forever. A handoff that grows by appending is a transcript, and transcripts are where facts go to hide.

This is also the pattern that makes delegation safe. A handoff written for a memory-less reader is exactly the brief a subagent needs — the connection to briefing subagents so the briefs get used is direct: same document, two uses.

Pattern 4: scoped memory, or, memory with an address

Not all memory belongs to the project. Some belongs to a subsystem, a client, or a workflow, and loading it globally taxes every session for the benefit of a few.

The fix is progressive disclosure: memory files that the standing file points to by topic, loaded when the task touches that topic. Two mechanisms now do this natively in Claude Code:

If you have built skills before, you already know this shape. Advanced skill authoring applies the identical layering to instructions, and sharing skills across projects covers the same scoping problem one level up. Memory deserves the same discipline.

Pattern 5: auto memory, the layer the agent writes itself

Newer, and easy to miss: Claude Code now keeps a second memory system that the agent writes on its own. It lives outside your repo, at ~/.claude/projects/<project>/memory/, with a MEMORY.md index and one topic file per subject. At the start of every session, the first 200 lines (or 25KB, whichever comes first) of that index load into context.

Auto memory is per project and per machine. It is shared across worktrees of the same repo, but it is not committed to git and never reaches your teammates. What the agent learns on your laptop stays on your laptop.

Treat it as a draft layer, not a record:

What to forget, on purpose

Forgetting is the pattern nobody implements, and its absence is why agent memory degrades.

Stale memory is not neutral. An agent that trusts an outdated note is worse off than one with no note at all — the failure mode behind sessions that loop on false premises is usually a memory problem wearing a reasoning costume.

A worked example: one event, four layers

Say your project moves its staging deploy from a manual script to CI. That single event produces four different memory writes — and one deliberate non-write.

Standing file. The deploy command changes, present tense: “Deploy staging: push to the staging branch; CI runs the deploy.” The old script’s name disappears entirely. The standing file describes how work is done now; it keeps no trace that anything was ever different.

Decision log. A new dated entry: “Deploy moved to CI. Reason: two manual deploys shipped stale builds in October. Revisit if: CI queue times pass ten minutes.” Six months later, when someone asks why the script is gone, this entry is the answer — and its revisit condition is the only sanctioned way back.

Handoff. Until the first CI deploy is watched end to end, the handoff carries it as unverified: “CI deploy configured; not yet seen green. Next: trigger a staging push and watch the run.” The moment it goes green, the line moves to verified — or the whole entry vanishes at the next rewrite, because a finished migration is no longer working state.

Auto memory. The agent may note “deploys go through CI now” in its own MEMORY.md. Fine as a draft. It becomes team memory only when a human promotes it — and the promotion already happened, in the standing file, so the auto-memory note is harmless duplication rather than the record.

Nowhere. The afternoon spent debugging the old script’s path bug gets no entry anywhere. The script is gone; the trap died with it. If the bug’s lesson generalises — say, “relative paths in deploy scripts break under cron” — it earns one line in the handoff’s traps while the script still exists, and is deleted with the script.

That sorting instinct — present-tense fact, dated decision, current state, or nothing — is the entire skill. The templates below just give each sort a fixed address.

Memory-file template set

# 1) STANDING FILE — excerpt (present tense, checkable)
## How we work here
- [procedural rules only; no history, no narrative]

# 2) DECISIONS.md — append-only, 3 lines per entry
## 2026-11-10 — [Decision in one sentence]
Reason: [one line]. Revisit if: [condition that would change it].

## 2026-11-18 — [Decision]
Reason: [one line]. Revisit if: [condition].
(Supersedes 2026-11-10 entry on [topic], if applicable.)

# 3) HANDOFF.md — rewritten each session, one screen maximum
State: [one line — where the work stands]
Verified: [what is proven, and how]
Unverified: [what is claimed but not yet checked]
Next: [ordered, with starting files/commands]
Traps: [one line per dead end — approach + reason]

# 4) MEMORY HYGIENE — monthly, 15 minutes
[ ] Standing file: every line still true of the repo today?
[ ] Decisions: any reversed without a superseding entry?
[ ] Handoff: still one screen? Still rewritten, not appended?
[ ] Topic files: any unreferenced for a month? Demote or delete.
[ ] Auto memory: anything in MEMORY.md the team needs? Promote it.
[ ] Anything here that the code now states better? Delete it.

Putting the patterns together

Start with patterns one and three — a standing file and a handoff — because they cover the two questions every new session asks: how do we work here, and where did we leave off. If the standing file does not exist yet, your first CLAUDE.md is the fifteen-minute version of pattern one. Add the decision log the first time you catch an agent re-arguing a settled question. Add scoped memory the first time your standing file grows a section only one task in five needs. And put auto memory under the same hygiene pass as everything else, because it writes itself whether you supervise it or not.

The week-to-week budgeting system that runs on top of these patterns — how much context each layer should cost — lives in context budgets for long projects. Start there once the files exist.

An agent with good memory does not remember everything. It remembers the few things that change what it does next — and can show you exactly where each of them is written, who wrote them, and when they were last checked against reality.

FAQ

Where should a coding agent’s memory live: files or a database? For most individual and small-team work, plain files in the repo win: they are versioned, reviewable in pull requests, readable by every agent tool, and deletable without tooling. Reach for anything heavier only when you have a concrete failure that files demonstrably caused.

How often should agent memory be cleaned up? Monthly is a workable rhythm for active projects, plus an immediate pass whenever you catch the agent acting on a stale note — that incident means the stale item outranks the schedule.

Should the agent write its own memory files? It should draft them; you should correct them, especially the handoff’s verified/unverified split. An agent grading its own work into memory is how unverified claims harden into facts the next session will trust. Claude Code’s auto memory makes this a live question rather than a hypothetical one — read its MEMORY.md the way you would read a junior colleague’s notes.

How big should each memory file be? Small enough to be read in full, every time. Anthropic’s own guidance for CLAUDE.md files is under 200 lines each; a handoff should fit on one screen; a decision entry should fit in three lines. If a file needs a table of contents, it is two files.

Category: Claude Code & Context Engineering · Tags: #claude-code #context-engineering #ai-agents

Next step: this article is part of Claude Code guides, which covers the full topic from first setup to advanced use.

Related guides

Claude Code & Context Engineering

How to Point Claude Code at a Free Gemini API Key (and What You Lose)

Claude Code has no official Gemini mode — but a local router can translate its requests to a free Gemini API key. The exact setup from Anthropic's env-var docs and the router's repo, what breaks in translation, and when the trade is worth it.

11 min read