Codebase Cognitive Memory
Your coding agent already finds where code lives — grep does that in one
turn. It cannot recover why the code is the way it is: what the obvious
implementation broke, what was tried and reverted, which invariant a strange
early-return protects. That reasoning exists in commit messages and in what an
agent works out while reading your repo, and it is thrown away at the end of
every session.
This tool mines it into a SQLite file and hands it back on the next task.
Measured against an agent that had full git log / git blame / git grep
access to the same history: 6.5 → 1.8 turns and −43% cost per question
(details in Does it work).
Status: early (0.1). Published to npm as
claude-notebook
— one CLI, claude-notebook. It works on any repository in any language;
nothing here parses source code. The API is not stable yet.
Install
Node ≥ 20. No database server, no Docker, no connection string.
npx claude-notebook sync # in the repo you want to remember
# or
npm i -g claude-notebook && claude-notebook sync
The store is one SQLite file, created on first write:
<your-repo>/.claude/memory.db (MEMORY_DB overrides it). The repo is the
current directory; REPO_DIR=/other/repo points elsewhere.
From a clone of this repository, node scripts/self-memory.mjs <cmd> is the
same CLI pointed at this repo (needs pnpm install && pnpm build).
Claude Code plugin
One install wires the memory into every session of a repo: sync at session
start, relevant memories injected into each substantial prompt, and the
session's scout report recorded on stop. Adds /claude-notebook:notebook and
/claude-notebook:refine-memory.
/plugin marketplace add cuonghuunguyen/claude-notebook
/plugin install claude-notebook@claude-notebook
The plugin shells out to npx -y claude-notebook; Node ≥ 20 is the only
requirement. Source: plugin/.
Turn your codebase into memory
cd /path/to/your/repo && claude-notebook sync
{ "repoId": "your-repo", "explanatoryCommits": 177, "experiencesAdded": 177,
"knowledgeMs": 283, "staleness": { "candidates": 177, "markedSuspect": 164 } }
sync walks your git history and keeps the commits that explain themselves:
a body of at least 200 characters that says why — because, instead,
revert, decided, chose, rather than, trade-off, deliberately. A bare
fix typo is skipped, because its knowledge is re-derivable from the diff. Each
kept commit becomes a memory anchored to the files that commit touched.
sync can also distill each memory, and this is off by default. With
CLAUDE_NOTEBOOK_DISTILL=1, one claude -p --model haiku call per memory
rewrites the raw commit body into a ≤120-word What: / Why: / Where:
summary, stored alongside the body in a digest column; retrieval then searches
the digest and ask prints it. The original body is never modified and stays
one claude-notebook show <id> away, so UPDATE experiences SET digest = NULL
undoes the whole thing.
It is off by default because it was measured and did not pay: on the corpus it
was tested against it bought a 19% smaller injection but halved how often the
context was actually cited, added 38% wall time, and still cost more than plain
grep+git — see spec.md §26.6 and BENCHMARKS.md. It is the only part of the
system that costs money (once per memory for its life, at most 200 memories per
sync), and it is kept because that verdict is corpus-shaped: a history of long
commit bodies has far more to win than the short ones it was tried on. Without
the variable, or without claude on PATH, sync prints distill: skipped and
retrieval uses the raw bodies.
Re-run it after every merge. It is idempotent — already-recorded commits are
skipped, already-distilled memories are not re-distilled — and it also re-flags
memories that newer commits have overtaken.
What you get depends on your commit messages. A history of wip and
fix stuff produces almost nothing. Run sync first and read
explanatoryCommits: that number is your corpus.
Ask it
claude-notebook ask "why was the base64 change reverted?"
## Why / prior knowledge (3)
### Revert "fix(v4): reject whitespace in z.base64() to close atob bypass"
_commit 23edf484 · 2026-04-28 · hybrid_match (text+trigram+vector), score 0.0325_
> **possibly-stale — verify before trusting** (modified packages/zod/src/v4/core/schemas.ts in 24cdb7fd (+49 more))
> run the `refine-memory` skill to repair it — `/refine-memory 052b791f-…`
That commit landed on main accidentally — it was meant to be pushed to a
new branch but the worktree's upstream tracking pointed at main …