agd-memory

Per-project persistent memory for Claude Code,
stored in AGD format with selective
retrieval and graph traversal.
Each project gets its own memory file. The session never loads it whole:
it scans a Table of Contents, picks the relevant blocks, and fetches
them in a single batched call. Typical access costs 6-15x fewer
tokens than loading the whole memory file.
What you get
-
SessionStart hook — at session start, injects the TOC of the
project memory into the system context. If the project has no
memory, the hook is a silent no-op.
-
UserPromptSubmit hook (auto-recall) — on every prompt, scores
every block by keyword overlap with what the user just typed and
injects the top few full block bodies. Skips silently on empty/short
prompts, pasted code, or when nothing clears the relevance floor. TOC
and auto-recall are complementary: the TOC tells the model what
exists, recall surfaces what's relevant right now.
-
SessionEnd hook (auto-capture) — after a substantial session, a
headless claude -p pass reads the transcript and persists what was
durable: decisions with their rationale, root causes, preferences.
Trivial sessions are gated out before any LLM call is spent, and
transient API failures are retried instead of losing the session's
knowledge. This is what makes memory accumulate without the user
having to say /remember.
Upgrading from a hand-installed distiller? Remove the old
SessionEnd/SessionStart entries pointing at ~/.claude/hooks/
from ~/.claude/settings.json — but only after the installed
plugin actually carries this version. Claude Code loads the plugin
from ~/.claude/plugins/, which is a clone of the published
remote, not your working checkout: an older installed copy registers
only SessionStart, so removing the local hook first turns
distillation off entirely. Check with
python3 -c "import json;print(list(json.load(open('$HOME/.claude/plugins/marketplaces/agd-memory/hooks/hooks.json'))['hooks']))".
While developing against a checkout that is ahead of the published
plugin, point a local SessionEnd entry at your checkout's
hooks/agd-memory-distill.sh. The hook locks on the resolved memory
file, so a local hook and a plugin hook cannot both distil the same
memory — including the case where two checkouts of one repo map onto
one memory file through the git-remote index. A copy that cannot
resolve the memory file (no lib/ alongside it) skips rather than
guessing a key, so it can never diverge into a second run. The lock
lives under $CLAUDE_PLUGIN_DATA, so this holds as long as both
copies see the same value for it — give one a different
CLAUDE_PLUGIN_DATA and they lock in separate directories.
That lock covers distillers only: a live session writing memory at
the same time is serialised by the writer's own flock, which prevents
a corrupt file but not two independent decisions about what to record.
| Var | Default | Purpose |
|---|
AGD_DISTILL_DISABLED | unset | hard kill switch |
AGD_DISTILL_MODEL | claude-sonnet-4-6 | model for the headless pass |
AGD_DISTILL_RETRIES | 3 | attempts before giving up on a transient failure |
AGD_DISTILL_BACKOFF_S | 30 | backoff base, grows linearly per attempt |
AGD_DISTILL_LOCK_STALE_S | 1800 | age at which a held lock is treated as abandoned |
-
Skill (/agd-memory:memory) — when the user asks "ricordi…",
"what do you remember…", or you need project context, the skill
documents how to read and write the memory.
-
Skill (/agd-memory:recall-lang) — triggered by "enable italian
recall", "abilita italiano", "which languages for recall", etc.
Manages stopword languages for the auto-recall hook.
-
MCP server — exposes four tools (agd_memory_toc,
agd_memory_search, agd_memory_get, agd_memory_save) so the
model can interact with memory through structured calls instead of
shelling out.
All four components are backed by the same agd CLI binary. No
daemon, no broker, no embeddings — a single line-oriented file on
disk.
Auto-recall configuration
The recall hook reads optional environment variables; all defaults are
chosen so the total auto-injected memory budget stays under ~2k tokens
per session (SessionStart TOC ~750 + recall ~1.2k).