ASADULELAHBOOK A CALL →

Home / Learn

Learn with Asadulelah · Lesson 2

How do I make Claude Code remember context between sessions?

By Asadulelah, a Kerala-based builder of custom software and AI systems for businesses. I build by directing a fleet of AI agents, and this is how I actually do it.

WHO THIS IS FORPeople who use Claude Code (or any agent) every day and are tired of re-explaining their project, their rules and yesterday's decisions in every new session.

WHAT YOU'LL HAVE AT THE ENDA layered memory (core facts, single-fact memories, a past-session index, handoffs) that a fresh session loads in seconds, with rules that stop it from rotting.

Claude Code forgets everything when a session ends, so you have to build memory as files it reads at the start of every session: a short project instructions file, a small capped file of current facts, and single-fact memory notes. Then add a searchable index of past sessions and a handoff note between sessions, and you have an assistant that picks up where it stopped.

The trap is making memory one big file. Mine grew to about 150 KB before I rebuilt it, and a memory nobody can read at boot is the same as no memory.

What failed before

My first memory file was one long markdown page. Every week I stacked a new "active priorities" block on top, until there were 34 of them and nobody, human or AI, could tell which was current. I also ran a plugin that summarised sessions in the background; it made its own model calls, queued hundreds of observations and quietly stopped working. And I found that Claude Code deletes old session transcripts after 30 days by default, so my history was disappearing.

In October I rebuilt it. The prompt was simple: I'd seen one of the best persistent memories I'd ever used in another agent, and I told Ziggy, "Whatever Hermes is good at, just make our stuff better." Most of what follows was built that afternoon.

The steps

1. Write a boot order in CLAUDE.md

CLAUDE.md loads automatically, so use it as a table of contents, not a dump. Mine starts with a numbered "First thing every session" list: which machine am I on, who am I, who is the user, what is currently true, the writing rules, and any open handoffs. Each step points to a file. The session reads small things first and opens big things only when needed.

2. Keep a capped core file of current truth

My CORE.md holds what is true right now, capped at 6,000 characters. Each entry is one fact, starts with §, and must end with a source tag (asad-stated, observed, or inferred with a review-by date):

§ Weekly usage stop for background work is 90%. (asad-stated 2026-12-02)
§ The VPS owns the nightly maintenance run. (observed 2026-09-24)
§ He prefers a fresh session plus a handoff over /compact. (asad-stated 2026-10-18)

A hook checks every write to that file. It refuses the write if the file goes over the cap, if an entry has no tag, or if the text looks like an injected instruction, and it prints the current entries so the session merges or retires one in the same turn. The cap is the feature: it forces the memory to stay current instead of growing forever. One honest gap: a write done through a shell command skips the hook.

3. Store everything else as one fact per file

Corrections, preferences and project facts each get their own small file with frontmatter: a name, a one-line description, and a type. The body is the rule, then Why, then How to apply. A one-line-per-file index is loaded at boot; the full file is read only when it's relevant. I have over 400 of these now, most of them feedback I gave my own assistant.

---
name: feedback-reply-before-long-work
description: Answer the user in a short turn first; long work after
type: feedback
---
Reply first, then start the long task.
**Why:** a turn went silent for about 15 minutes while it launched work; he read it as "it stopped".
**How to apply:** any task over a few minutes gets a one-line reply first.

4. Index every past session

ziggy_recall.py builds a SQLite full-text index of every Claude Code session on the machine: only what I typed and what the assistant answered, no tool output. Results are ranked by relevance with a recency weight (a match from a year ago counts half). It reindexes every hour, keeps the text after Claude Code deletes the transcripts, and I raised the transcript retention from 30 to 90 days on top of that. The first build turned 1.9 GB of transcripts into a 9.3 MB index in six minutes.

python3 ziggy_recall.py search "decision on the gateway pacing"
python3 ziggy_recall.py read <session-id> --around "pacing"

5. Recall pages by name, automatically

A second hook runs on every message I send. If my message names a person or project that has a page in my vault, it injects the summary part of that page (at most three pages, about 1,600 characters in total, never the same page twice in a session). So when I mention a project, the assistant already has its current state without searching.

6. Hand off between sessions and machines

I run my assistant on two machines: my PC and an always-on server. When work moves, the session writes a handoff file with status: open, who it's for, and a "Remind Asad" list. A startup hook on the other machine prints open handoffs, and the new session opens its first reply with that list. My Discord bot does the same thing automatically: when a session passes 250k of context, the old one writes a handoff of up to 700 words and a fresh session starts from it.

7. Let the user's own words outrank the summary

This one came from a failure. A handoff said I "hadn't confirmed" something I had answered the day before, so the next session asked me again. Summaries of summaries drift. Now my exact messages beat any summary: project pages keep a "vision, in his own words" section, and the assistant checks the saved chat before ever saying I haven't replied.

Mistakes I made

What I'd do next

If you are starting: write the boot order in CLAUDE.md, make one capped facts file with source tags, and save each correction you give as its own file. That alone fixes most "it forgot again" pain. Add the session index once you catch yourself asking "what did we decide about X?". The piece I still haven't built is a nightly reviewer that saves facts without being asked; it's on hold because of what it would cost in tokens.