Chapter 6: Memory
Chapter 5 ended with the river: every read, every grep, every test run landing in the array and staying. This chapter teaches the machine to forget. It gains three plain operations, trim, compact, wipe, and with them the last missing part of the machine on the cover.
One long session carries the chapter. It is the lockout afternoon, continued: the bug fixed, the rate limiter from chapter 2 added, a password reset flow started, a dependency bumped along the way. By late afternoon the transcript holds every file the agent read, every command it ran, every edit, every failure, every retry. Nothing has been removed. Nothing ever is.
Compaction
Between requests, the conversation lives in exactly one place: the array, inside your host, and nowhere else. The model holds nothing. Readers of the first book met the context window in chapter 6: the array has a hard ceiling, and everything in it is paid for on every turn. A session like this afternoon's fills the ceiling on its own.
The first two operations are surgical. Trim drops the oldest messages from the top of the array. Compact goes further: it asks the model to summarize a stretch of messages, keeps the summary as one new message, and drops everything the summary covers. Together they answer the problem chapter 2 filed away. The loop only appends, so someone has to subtract, and that someone is your code.
Watch the afternoon hit the wall. The host has been watching the array grow all day, and when it decides the memory is too heavy, it acts. The morning's lockout work, forty messages of reads and edits and test output, goes to the model with one instruction: summarize what matters for the work that remains. The summary comes back as one message. The forty are dropped. The array loses an afternoon and keeps going.
The machine gains its last part:
Compaction loses by design. The summary says the lockout constant was fixed from five to three, and drops the forty messages around it, including which file the constant lives in. When a later question needs that file, the model has two options: read its way back, a small tax, or guess, a small disaster. The fix is focus. Summarize what the loop still needs, the decisions, the open questions, the file paths, and let the rest go. A summary is not a shorter transcript. It is a handoff note to a colleague who was not there.
Sessions
The third operation is the bluntest one. Wipe: empty the array, keep nothing, start again. A session is the unit of that forgetting. One array, born at the first message, thrown away when the work is done.
Wiping sounds like loss, and it is often the feature. A fresh session is controllable: the same starting array produces the same behavior, which is the only reason agents can be tested at all. It is walled off: the morning's confusion stays in the morning, and a wrong theory picked up at 10 a.m. does not steer the 3 p.m. work. And it carries nothing forward: a bad first hour does not poison a good second one. Readers of the first book met this as the first mental model of all: the model is stateless. The array was the only memory from the beginning. Wipe the array, and the mind is gone, and sometimes that is exactly what you want.
The afternoon needs exactly that. The morning's lockout hunt left three wrong theories in the array, and the model keeps circling the third even though the bug is long fixed. So you wipe. A new session opens with one message, written by you: the lockout bug is fixed, the constant was five and is now three, the rate limiter is done, the password reset flow is next. The new session starts clean, and it starts fast, because a summary travels well and a transcript does not. Switching sessions is nothing deeper than swapping arrays.
The wipe's failure mode is its own nature: it loses the context you still needed. The handoff message mentioned the password reset flow, but not the API rate limit the flow keeps tripping over, and the fresh session rediscovers it the hard way. The fix is the same as compaction's, pointed the other way: carry forward a summary, not the history, and write the summary about what comes next.
Try it
- Find the compaction note. Open a long coding agent session, one that has been compacted, and scroll until you find a block summarizing everything before it. You are looking at the machine forgetting on purpose, and leaving itself a note.
- Watch the meter. Most coding agents show a context indicator. Work one long session and watch it climb with every file read and every command run. When it falls without the conversation ending, compaction just happened.
- Fresh arrays, fresh starts. When a session has gone down a wrong path, open a new one and paste a short summary of where things stand: what is fixed, what is decided, what is next. The new session cannot remember the wrong path, because the wrong path is not in its array. Statelessness, working for you.
The machine, assembled
Look at it one last time, with nothing dimmed:
Every part has a chapter. The loop and the array are chapter 2. The documents arriving from above are chapter 3. The contract in the middle is chapter 4. The bench is chapter 5. The dashed box at the bottom is this one. Nothing in the diagram is a metaphor, and nothing is missing. This is the coding agent you use every day.
Claude Code is chapter 2's loop with chapter 5's toolbox attached. Every coding agent you have used is a version of the same machine: an array, a loop, a contract, a bench, and a way to forget, running in that order, all day, on your laptop or someone else's.
Chapter 1 made a promise: the machine is one loop, and you could write it in an afternoon. Look at the diagram one more time. That is the loop. Every box on it is a chapter you have read, and the knowledge it adds up to is the power level chapter 1 promised. There is no magic left in this machine. There is only code, and you have read it.