Build your own agentic layer, part 7: memory, and teaching it what I like

Part 7 of a series on building your own agentic layer. Part 6 covers running a lot of agents at once.
An agent's memory is its context window, and the context window doesn't last. Close the session and it's gone. Even inside a long session, when the window fills up, Claude Code compacts it: it summarizes the older part of the conversation and throws the original away. Summaries lose detail. The why behind a decision is usually the first thing to go.
So anything worth keeping has to end up in a file.

Kinds of memory
I think about it in three layers.
Facts about me and my projects. Claude Code has a built-in memory: small markdown files it can write and read back in later sessions, like which branch a repo deploys from. Good for facts, not for rules.
Rules. Anything that should change behavior everywhere goes into Trillian's AGENTS.md, which is in git and syncs to every machine. Covered in part 2.
Work in progress. What we decided, why, and what's left. That's the rest of this post.
Receipts: a running decision log
Trillian has a skill called receipts that's on by default in every session. When the agent makes a real decision (picked one library over another, chose a design, changed course), it adds an entry to a DECISIONS.md file in the repo: what was chosen, why, and what got rejected.
A few rules make it useful instead of noisy:
- Only real forks. No file at all for a session that just edited a typo.
- Real timestamps. Each entry's heading comes from running
date, not from the model guessing the time. A guessed time can't be lined up against a commit later, which is the whole point. - Never delete a wrong entry. Mark it. When later work proves an entry wrong, it gets a
SUPERSEDEDflag in place, pointing to the new one.
That last one earns its keep. Here's a real one from Trillian's own log. The September audit in part 2 found skills copied six times (the copies all had random names starting with Cu), and the cause got guessed wrong twice before it was pinned down:
### 2026-09-28 10:40 — Cu* skill copies: NOT made by trillian-link (measured), left in place
**⚠️ SUPERSEDED 2026-09-29 07:52** — wrong: trillian-link IS the producer.
The scratch-HOME test made zero copies only because scratch had no
pre-existing native symlinks to collide with. See the 2026-09-29 07:52 entry.
A wrong reason that still looks current is worse than no reason, because the next reader (often the next agent) will follow it.
It's also there for when I have to explain my work to someone. "Why did you do it this way?" has an answer with a date on it.
Hand-offs
Two smaller habits:
- Steps for me go in a file. If a turn ends with commands I have to run myself, they go in a
*-HANDOFF.mdor*-CHECKLIST.md, not just the chat. A hook enforces it (part 4). /handoffsnapshots the branch, the diff, the current task, and next steps into a file so I can pick the work up on another machine.
Tasks that follow me around
Trillian is also a to-do list. Saying "Trillian, add this to my list" in any session creates a GitHub issue in the Trillian repo, tagged with the project I was in. "Trillian, what's on my list?" reads them back. Because it's GitHub, the list is the same on every machine and in every session, and the session-start brief shows the open ones.
Teaching it what I like
This is the newest piece.
Every time I correct Claude ("no, don't do that", "always use X", hitting Escape to interrupt), that's a preference I've expressed once and will probably express again. Claude Code keeps transcripts of every session. So Trillian mines them.

It's two stages on purpose:
trillian-prefs scanruns in the background when a session starts or ends. It's plain Python pattern matching, no AI. It reads only the new part of each transcript and saves signals: my turns that correct, refuse, interrupt, or say "always" or "never", with the bit of Claude's turn I was reacting to./trillian-learnruns when I ask for it, inside a normal session. Claude reads the signals, throws out one-off task feedback ("no, the other file"), and groups the rest into proposed rules with the evidence and dates. I accept, edit, or reject each one.
Some choices that came out of designing it:
- Never write a rule on its own. Most corrections are about the task in front of me, not a lasting preference. And a rule loads into every session forever, so a bad one costs a lot. A proposal needs signals from at least two sessions, or one explicit "always/never".
- Rejections are remembered. A rejected proposal goes in a ledger so it doesn't get proposed again next week.
- No AI in the background step. Running Claude from the session-end hook would spend tokens unattended, and it would write its own transcript, which the next scan would then mine. That's a loop nobody wants.
- It stays on this machine. Signals hold my actual words, so they live in a local folder, never in git, never synced.
- Keep the evidence. Claude Code deletes old transcripts after 30 days, so a full rebuild keeps the signals from transcripts that no longer exist.
As I write this, it's sitting on 85 signals I haven't reviewed yet.
Back up the stuff that's only on one machine
A lot of this memory is deliberately not in git: Claude's memory files, per-repo settings, decision logs and hand-offs, local-only rules. So Trillian has trillian-backup, which copies all of it to a dated folder in OneDrive once a day and keeps the last 30. It skips anything that looks like a secret. On a new laptop, a restore puts it all back.
Links
- Claude Code memory and CLAUDE.md
- Effective context engineering for AI agents, including compaction and note-taking
- Claude Code hooks, for the session start and end events the scan runs from
Drafted with an assistant, edited by @wintaru
0 comments