Topic 3 of 5 · 5 min read
File-based memory and agent notes
Goal: Design a notes file an agent maintains so a fresh session can resume the task without the old history.
The simplest durable memory for an agent is a file it writes and reads itself, so a new session can pick up the work from the file instead of from a long history. Files are easy to inspect, diff, edit by hand and keep in git.
Check yourself · 1 of 3
Why does a notes file help an agent that works over several sessions?
Why it matters
Long tasks outlive one context window. A migration, a refactor or a research job may take many sessions. Each new session starts empty. If the agent left good notes, it resumes in minutes. If it did not, it re-explores the repo, repeats failed attempts and may undo finished work. Anthropic's write-up on long-running agents describes this pattern: a progress file and git history act as the bridge between sessions.
Two common forms
- Project files the agent reads at start. Examples are
CLAUDE.md,AGENTS.mdand aNOTES.md. Humans and the agent both edit them. - A memory directory behind a tool. The Claude API memory tool, for instance, gives the model commands to view, create and edit files under a
/memoriesdirectory. Your own code runs those commands, so you control where the files live and what they may contain.
What a good notes file holds
- Goal in one or two lines.
- Done, with pointers: "pagination added,
orders.ts:31". - Next step, specific enough to start at once.
- Decisions and why: "kept offset paging; cursor paging breaks the mobile app".
- Dead ends: "tried caching totals; stale after refunds".
- How to verify: the command that runs the relevant tests.
Keep it short. A notes file that grows to thousands of lines becomes a second context problem.
Before and after
Before:
Worked on the migration. Made good progress. Some tests fail.
After:
Goal: move users table to new schema.
Done: columns renamed (migration 0042). Backfill script written, not run.
Next: run backfill on staging, then fix 3 failing tests in auth/.
Dead end: renaming in one step locked the table for 40 s; use two steps.
Verify: pnpm test auth
What goes wrong
- Notes written only at the end. If the session is cut off, nothing was saved. Update at each milestone.
- Unchecked claims. "Backfill done" written before it ran. The next session trusts it. Write results, not intentions, and re-verify cheaply.
- Unsafe paths. A memory tool that accepts
../../etcas a path can read or write outside its directory. Validate paths in your code.
Examples
Resuming from a notes file
A new session opens with one instruction: "Read NOTES.md, then continue." The agent reads the Next line, runs the verify command, sees 3 failures in auth/, and starts there. It does not re-read the 60-file diff history, and it does not retry the two-step rename that already failed.
A path check for a memory tool
import path from "node:path";
const ROOT = "/srv/agent/memories";
export function safePath(requested: string): string {
const full = path.resolve(ROOT, "." + path.sep + requested);
if (!full.startsWith(ROOT + path.sep)) {
throw new Error("Path outside the memory directory");
}
return full;
}
Without this check, a model (or a prompt injection) can ask for a path that leaves the memory directory.
Key points
- A notes or progress file lets a fresh session resume without the old conversation.
- Good notes hold the goal, what is done, the next step, decisions with reasons, dead ends and how to verify.
- Update the file at each milestone, not only at the end of a session.
- Write results that were observed, not plans, because the next session will trust the file.
- A directory-backed memory tool runs through your own code, so you must validate paths and limit what it can touch.
Common mistakes
- Writing notes only when the task is finished, so an interrupted session leaves nothing.
- Recording what the agent intended to do instead of what actually ran and passed.
- Letting the notes file grow without pruning until reading it fills the window.
- Giving a memory tool raw file paths from the model without checking them against the memory directory.
Check yourself · 2 of 3
Which line is the most useful to put in a progress file for the next session?
Check yourself · 3 of 3
A memory tool lets the model pass any file path to read or write. What should the harness code do first?
Practice items, not counted towards your mastery.
Start here
- MemGPT: Towards LLMs as Operating Systems (opens in a new tab)PaperFree
The paper that frames context as fast memory and external stores as slow memory the model pages in and out.
- Memory tool (Claude API docs) (opens in a new tab)DocsFree
How a directory-backed memory tool works: view, create and edit commands, and security notes on path handling.
- Memory overview (LangChain docs) (opens in a new tab)DocsFree
Short-term versus long-term memory, and semantic, episodic and procedural memory types, with write timing.
More for this topic
- Effective harnesses for long-running agents (Anthropic) (opens in a new tab)ArticleFree
A worked case of progress files and git history carrying work across fresh agent sessions.