SLOPSHOPPER

project-memory

A repo's memory/ folder, shared through git: notes grouped in hubs, file-tied notes that load on touch, a pre-commit check, and a Haiku agent that keeps it in…

promptprocessagents
★ 3v0.3.1MITupdated 2026-10-25noash-xrc/claude-tools/project-memory
A shopper browsing a rack in a slop shop
README

Project memory

A Claude Code mod for a repo that keeps shared memory in memory/, committed with the code. Notes are grouped into hubs by theme, so a session starts with a short hub list and opens only the hubs and notes a task needs. Notes about specific files load by themselves when Claude touches those files, and a pre-commit check keeps the links, hubs and sizes in order and flags memories a commit may have made stale.

The mod switches on in a repo that has memory/MEMORY.md and stays out of the way everywhere else.

Layout

memory/
  MEMORY.md          one line per hub: - [Theme](hubs/<theme>.md) — hook   (2KB max)
  hubs/<theme>.md    one line per note: - [[slug]] — hook                  (4KB max)
  <slug>.md          a note: name / description frontmatter, the fact, a **Why:** line
  lint.sh            the pre-commit check
.claude/rules/memory/
  <slug>.md          a note with paths: globs, loaded when Claude reads or edits a match (1KB max)
.githooks/
  pre-commit         runs sh memory/lint.sh

A note can sit in every hub it fits, and [[slug]] links reach notes in either folder. A rejected approach is its own note with status: rejected. The skill has the full format.

What's in it

PartWhat it does
HookFinds the nearest memory/MEMORY.md at or above the working directory and puts it in the system prompt with the reading rules. Claude saves only when you ask it to remember something, and offers once, in a line, after you correct it. In a hub layout it also keeps memory/lint.sh in step with the mod's copy and wires it into pre-commit (below). Without a memory folder it hides the keeper
memory-keeper agent (Haiku)Fixes structure itself: hubs, index lines, links, duplicates, globs after a rename. Checks memories the lint flagged against the staged diff. What a note says is yours, so changes to it come back as proposals. Also runs the migration from a flat folder
project-memory skillThe layout, the note format and the saving steps
lint.shPOSIX sh and git, so it runs wherever git does. It blocks a commit on a note without name, description or Why, a duplicate slug, a dead link, a note no hub lists, a hub MEMORY.md doesn't list, a size over its limit, or a glob that matches no tracked file. It warns, without blocking, when a commit changes files a memory's paths cover and leaves the memory untouched

The pre-commit hook

When the repo has no hook setup, the mod writes .githooks/pre-commit and sets core.hooksPath .githooks. Commit both .githooks/ and memory/lint.sh: the check then runs for everyone who commits, mod or not, and in a fresh clone the mod only sets core.hooksPath.

When the repo already has one (Husky, the pre-commit framework, a hook of its own), the mod leaves it alone and Claude tells you to add sh memory/lint.sh to it.

The mod doesn't touch a flat folder (no memory/hubs/): its MEMORY.md still goes into the prompt, and it gets no lint.

Moving from a flat folder

The keeper migrates on a branch, in three phases, because a big folder doesn't fit one Haiku context. The steps are in skills/project-memory/migrate.md:

  1. Plan. One run reads each note's name and description and writes the hub list to memory-migration/plan.md.
  2. Convert. One run per batch of about 15 notes. It drops metadata.type, splits rejections into their own notes, adds Why lines, and moves file-tied notes to .claude/rules/memory/. Each note gets a row in memory-migration/table.md.
  3. Hubs. One run writes the hubs and the new MEMORY.md, then fixes structure until the lint passes.

Review table.md: the hubs, each glob and how many files it matches, and each split. Spot-check the diff, delete memory-migration/, then merge.

If the repo's CLAUDE.md tells Claude to read memory/MEMORY.md, or the repo has its own project-memory skill, remove them. The mod's prompt section replaces the first, and the skills would otherwise both show up.

Install

/plugin install project-memory --marketplace noash-xrc/claude-tools
Source 1 files
hooks/register.ts 86 lines
1import type { EngineInterface, Register } from 'claude-code'
2
3type Memory = { dir: string; index: string; hubs: boolean; hookNote?: string }
4
5// Read once per session start: a repo gains a memory folder rarely enough that a reload catches it.
6let memory: Memory | undefined
7
8const LINT_CALL = 'sh memory/lint.sh'
9const HOOK = `#!/bin/sh\n${LINT_CALL}\n`
10
11const isAbsolute = (p: string) => /^([a-zA-Z]:)?[\\/]/.test(p)
12
13// Keeps memory/lint.sh current and wires it into pre-commit. A repo's own hook setup is never touched:
14// the answer is then a line for Claude to pass on.
15const install = async ($: EngineInterface, root: string): Promise<string | undefined> => {
16  const lint = await $.fs.read(`${$.plugin.root}/lint.sh`)
17  // CRs dropped, so a CRLF checkout of the same script isn't rewritten every session.
18  const copy = await $.fs.read(`${root}/memory/lint.sh`).catch(() => '')
19  if (copy.replace(/\r/g, '') !== lint.replace(/\r/g, '')) await $.fs.write(`${root}/memory/lint.sh`, lint)
20
21  const git = async (...args: string[]) => (await $.process.run(['git', ...args], { cwd: root })).stdout.trim()
22  const hooksPath = await git('config', '--get', 'core.hooksPath')
23  const hooksDir = await git('rev-parse', '--git-path', 'hooks')
24  const active = `${isAbsolute(hooksDir) ? hooksDir : `${root}/${hooksDir}`}/pre-commit`
25  const activeHook = await $.fs.read(active).catch(() => undefined)
26  if (activeHook?.includes(LINT_CALL)) return
27
28  const ours = `${root}/.githooks/pre-commit`
29  if (activeHook === undefined && (!hooksPath || hooksPath === '.githooks')) {
30    const existing = await $.fs.read(ours).catch(() => undefined)
31    if (existing === undefined) {
32      await $.fs.write(ours, HOOK)
33      await $.process.run(['chmod', '+x', ours]).catch(() => undefined)
34    } else if (!existing.includes(LINT_CALL)) return `\`.githooks/pre-commit\` exists but doesn't run the memory lint. Tell the user once: add \`${LINT_CALL}\` to it.`
35    if (!hooksPath) await git('config', 'core.hooksPath', '.githooks')
36    return
37  }
38  return `This repo has its own pre-commit setup (${activeHook === undefined ? `core.hooksPath ${hooksPath}` : active}), so the memory lint isn't wired in. Tell the user once: add \`${LINT_CALL}\` to that hook.`
39}
40
41const sectionText = (m: Memory) => [
42  '# Project memory',
43  m.hubs
44    ? [
45        `This repo keeps shared memory in \`${m.dir}\`. \`MEMORY.md\` lists its hubs. Each hub in \`hubs/\` lists the notes on one theme as \`[[slug]]\` lines.`,
46        'A note is `memory/<slug>.md`, or `.claude/rules/memory/<slug>.md` when it is tied to files: those load by themselves when you read or edit a matching file.',
47        'Before a non-trivial task, open the hubs whose themes it touches, then the notes that bear on it, and follow `[[links]]` that look relevant. A note with `status: rejected` is an approach not to re-propose.',
48      ].join('\n')
49    : `This repo keeps shared memory in \`${m.dir}\`, indexed in \`MEMORY.md\`. Before a non-trivial task, read the memory files whose index lines bear on it.`,
50  `\n${m.index.trim()}\n`,
51  'Save a memory only when the user asks you to remember something, following the `project-memory` skill. After the user corrects you or rejects an approach, offer once, in one line, to save it.',
52  'Hand structure fixes, stale-memory checks and cleanup to the `project-memory:memory-keeper` agent. When the pre-commit lint lists memories to recheck, give it those files and `git diff --cached`.',
53  ...(m.hookNote ? [m.hookNote] : []),
54].join('\n')
55
56export const register: Register = on => {
57  on('session.start', async ($, e, next) => {
58    // The nearest memory/MEMORY.md at or above the working directory, so a session started in a subfolder finds it.
59    const found = (await $.fs.ancestors({ names: ['memory/MEMORY.md'] }).catch(() => [])).at(-1)
60    let loaded: Memory | undefined
61    if (found) {
62      const root = found.dir.replace(/[\\/]$/, '')
63      const dir = `${root}/memory`
64      // Only the hub layout gets the lint: a flat folder would fail every check.
65      const hubs = await $.fs.exists(`${dir}/hubs`).catch(() => false)
66      // $.process is CLI only, so elsewhere the hook stays unwired and the prompt still loads.
67      const hookNote = hubs ? await install($, root).catch(() => undefined) : undefined
68      loaded = { dir, index: found.parts[0]?.content ?? found.content, hubs, hookNote }
69    }
70    memory = loaded
71    return next(e)
72  })
73
74  on('prompt.compose', async ($, e, next) => {
75    const r = await next(e)
76    return memory ? { sections: [...r.sections, { id: 'project-memory:recall', scope: 'session', text: sectionText(memory) }] } : r
77  })
78
79  // The keeper only makes sense where there is a memory folder.
80  on('agent.offer', async ($, e, next) => {
81    if (!e.agent.startsWith('project-memory:')) return next(e)
82    if (!memory) return { isOffered: false }
83    return next(e)
84  }).catch(($, e, next) => next(e))
85}
86