Lesson 58.5 · 5 of 7 · 4 min read · Reviewed 24 Nov 2026
Notes files and external memory
By the end, you can
- Keep state in notes outside the context window.
- Use a progress file across long tasks and sessions.
The context windowContext window: The maximum number of tokens a model can consider at once, counting the input and the output it generates. is working memoryWorking memory: The information an agent holds in its current context window: instructions, recent turns and tool results.. For long tasks, the agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. also needs a notebook.
Structured notes
Give the agent a file, or a tool, for notes, and tell it to keep them up to date:
# Migration progress
Goal: move all modules from v2 to v3 API.
Decisions: keep old error codes; wrap new client in adapter.ts.
Done: billing, auth, search
In progress: notifications (tests failing on retry logic)
Next: reports, exports
Why it works
- It survives compactionCompaction: Summarising older conversation history so a long session fits in the context window while keeping what matters.,
/clearand new sessions. - The agent re-reads only the summary it needs, not the whole history.
- People can read it too, which helps with review and hand-off.
Tips
- Keep it short; update in place rather than appending forever.
- Put the instruction in the system promptSystem prompt: Instructions passed in the top-level system field that set the model’s role, rules and context for the whole conversation. or CLAUDE.mdCLAUDE.md: A markdown file of standing instructions that Claude Code loads automatically, at user, project or directory level.: “Update PROGRESS.md after each module.”
- Git history and test results are notes too. A coding agent can re-read
git logto see what it did.
Key points
- Agents can write notes, such as a progress file or a to-do list, and read them back later.
- Notes survive compaction and new sessions, so the agent doesn't lose track.
- Keep notes short and structured: goal, decisions, done, next.
Keep a progress file through compaction
Simulate a long migration where the context is wiped every few steps, and use a progress notes file so no module is migrated twice.
You will have: A migration loop with a NOTES dictionary that survives compaction, and a report of modules done and redone.
Steps
- Read the MODULES list and the compact() function, which empties the context every 3 steps.
- Run the starter first: without notes, the agent forgets what it did and redoes modules.
- Add a NOTES dictionary with goal, done and next, updated in place after each module.
- At every step, read NOTES (not the context) to pick the next module.
- Print the final notes and the count of redone modules.
Done when
- Every module is migrated exactly once.
- The final notes list all modules under done and nothing under next.
- The run prints 'redone: 0'.
Open in the Playground No API key needed.
Starter code (Python)
MODULES = ["billing", "auth", "search", "notifications", "reports", "exports"]
context = []
migrated = []
def compact():
context.clear()
def pick_next():
# Without notes the agent only knows what is in its context.
seen = [c for c in context if c.startswith("done ")]
for m in MODULES:
if "done " + m not in seen:
return m
return None
# TODO: create NOTES = {"goal": ..., "done": [], "next": list(MODULES)} and use it in pick_next
for step in range(1, 9):
m = pick_next()
if m is None:
break
migrated.append(m)
context.append("done " + m)
if step % 3 == 0:
compact()
print("migrated:", migrated)
print("redone:", len(migrated) - len(set(migrated)))
Show a solution
MODULES = ["billing", "auth", "search", "notifications", "reports", "exports"]
context = []
migrated = []
NOTES = {"goal": "move all modules to the v3 API", "done": [], "next": list(MODULES)}
def compact():
context.clear()
def pick_next():
return NOTES["next"][0] if NOTES["next"] else None
for step in range(1, 9):
m = pick_next()
if m is None:
break
migrated.append(m)
context.append("done " + m)
NOTES["done"].append(m)
NOTES["next"].remove(m)
if step % 3 == 0:
compact()
print("notes:", NOTES)
print("migrated:", migrated)
print("redone:", len(migrated) - len(set(migrated)))