Skip to content
mentoor

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?

Choose one answer

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.md and a NOTES.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 /memories directory. Your own code runs those commands, so you control where the files live and what they may contain.

What a good notes file holds

  1. Goal in one or two lines.
  2. Done, with pointers: "pagination added, orders.ts:31".
  3. Next step, specific enough to start at once.
  4. Decisions and why: "kept offset paging; cursor paging breaks the mobile app".
  5. Dead ends: "tried caching totals; stale after refunds".
  6. 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 ../../etc as 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?

Choose one answer

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?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic