How to give AI coding agents persistent memory

Quick answer

AI coding agents forget everything when a session ends or the context window fills. The fix is to write state to disk with a simple three-file pattern: state.json (current snapshot), an append-only daily log, and a context-recovery briefing. On startup the agent reloads those files and resumes with full context — no re-explaining.

The most frustrating thing about working with an AI agent over days is the cold start: it does not remember yesterday. It re-asks decisions you already made, re-does work that is already done, or contradicts an earlier choice. None of that is a model limitation you cannot route around — it is a memory-architecture problem, and the architecture is files on disk.

The three files

state.jsonCurrent snapshot

A machine-readable picture of right now: what is running, what is deployed, pending tasks, and goals. The agent overwrites it after every meaningful action so a fresh session can read exactly where things stand.

log-YYYY-MM-DD.mdAppend-only daily log

One line per action: time, what was done, the result, and the next step. Append-only means history is never lost. On startup the agent reads today and yesterday to reconstruct the recent thread of work.

context-recovery.mdStartup briefing

A short hand-written summary that restores full context after a long gap or a context-window reset — the "here is what you need to know to continue" note an agent writes to its future self.

The one rule that makes it work

Write to disk after every meaningful action — never rely on conversation memory alone. The moment an agent treats the files as the source of truth (not the chat history), restarts stop being destructive. A crashed session, a new machine, or a fresh context window all become "read the files and continue".

With several agents working in parallel, give each its own set of files. Shared state plus a structured memo convention for hand-offs is what keeps a multi-agent workforce from overwriting each other.

FAQ

Why do AI coding agents lose context?

Agents have a finite context window and no memory between sessions. When a session ends, or the window fills and older messages drop out, anything not written to disk is gone. Persistent memory means writing state to files the agent reloads on the next run.

What is the three-file memory pattern?

A lightweight convention: state.json holds the current snapshot, a dated append-only log records every action and its result, and context-recovery.md is a short startup briefing. Together they let an agent resume work after a restart without you re-explaining anything.

Why not just use a longer context window?

A bigger window delays the problem but does not solve it — sessions still end, machines still restart, and long contexts get expensive and lossy. Writing state to disk is durable, cheap, auditable, and survives across tools and sessions.

Where should these memory files live?

Keep them in the repo (or a dedicated agent-logs directory) so they are versioned alongside the code and readable by every agent. Treat the files as the source of truth — the rule is "write to disk after every meaningful action; never rely on conversation memory alone".

Keep reading

Get the full memory schema

SoloStack ships the complete three-file memory schema with worked examples, plus the MEMO_INBOX discipline for multi-agent hand-offs — the same system used to run 35 live products with one human.

Get SoloStack — £99