A searchable memory database (SQLite full-text search) for Claude: search/add/get/index tools, a /memdb command, and your memory files indexed automatically

A small collection of Claude Code mods (plugins that hook into the session). Install only the ones you want.
| Mod | What it does |
|---|---|
| agent-dashboard | One Dashboard pane with usage and context bars, tasks, tests, sessions and subagents |
| auto-handover | /handover writes a handover note and starts (or proposes) a fresh session |
| auto-compact | Compacts past 250k tokens and saves the full transcript before every compaction |
| build-trimmer | Trims long xcodebuild / swift build output so it does not fill your context |
| prompt-upgrade | /improve rewrites a rough prompt into a clear one |
| keep-going | Stops Claude ending a turn on a vague "want me to…?": it keeps working or asks with options |
| memdb | A searchable memory database Claude can query and add to |
| cache-tax | Keeps the prompt cache warm during breaks and stops a cold send once with its price (third-party, MIT) |
| reflect-mod | Turns your corrections into CLAUDE.md rules, saved with one press (third-party, MIT) |
memdb (it also needs SQLite with FTS5, which most Python builds have) and for build-trimmer's xctrim.py.build-trimmer is for Apple development (Xcode / SwiftPM). agent-dashboard and auto-handover work best in the desktop app, where panes and new sessions are available.To get every mod and the settings this repo is used with (auto-compact at 200k, the built-in auto-compact at the same size), clone it and run the setup script:
git clone https://github.com/flyingpurplepizzaeater/claude-mods.git
cd claude-mods && ./setup.sh
It copies each mod to ~/.claude/mods/<mod> and adds three keys to the env of ~/.claude/settings.json: CLAUDE_CODE_PLUGIN_DIRS (the mods, kept alongside any plugin folders already listed), AUTO_COMPACT_THRESHOLD and CLAUDE_CODE_AUTO_COMPACT_WINDOW. Nothing else in the file changes, and the old one is kept as settings.json.bak. Name mods to install only those (./setup.sh memdb cache-tax), set AUTO_COMPACT_THRESHOLD=300k before it for another size, and run it again after git pull to update. New sessions load the mods. It needs rsync and python3, and follows CLAUDE_CONFIG_DIR if you set it.
Use either this or the marketplace install below for a mod, not both, or its hooks run twice.
At the prompt of a terminal session (swap memdb for any mod name above):
/plugin install memdb --marketplace flyingpurplepizzaeater/claude-mods
Claude asks Add marketplace?: answer y, then pick a scope (user scope is the first one). If the mod has options, a screen lets you set them. You then see Installed memdb. Plugin is now active., and its hooks run from then on, with no reload needed.
From a shell:
claude plugin install memdb --marketplace flyingpurplepizzaeater/claude-mods
In the desktop app, where /plugin does not run: click + next to the prompt box, then Plugins, Add marketplace with flyingpurplepizzaeater/claude-mods, then Add plugin.
If you have already added the marketplace, claude plugin install <mod>@claude-mods is enough.
Opens one Dashboard pane at session start and stacks everything in it:
/dashboard brings the pane to the front. The pane refreshes every 5 seconds.
Options (all can be changed later in /config):
| Option | Default | Meaning |
|---|---|---|
planNote | on | Tell Claude to write long or multi-part requests into its task list first |
queueMessages | on | A message sent while Claude is working goes to the end of its task list instead of derailing it. Start the message with !now to act on it immediately |
buildReminder | off | After a long build or test run in the foreground, remind Claude to use the background next time |
/handover asks Claude to write a short handover note (goal, state, done, next steps, key files, gotchas) to ~/.claude/handovers/ and then starts a fresh session that continues from it. In the desktop app it starts the session directly (or proposes it as a card); elsewhere it leaves the "continue" prompt in the prompt box for you to send after /clear.
/handover write the note and hand over now
/handover status show whether auto mode is on, the threshold and this session's size
/handover on | off automatic handover past a context threshold (off by default)
/handover threshold 200k set the threshold (at least 1k; never above 80% of the window)
The threshold can also be set with the environment variable AUTO_HANDOVER_THRESHOLD or per project in .claude/auto-handover.json ({ "threshold": "120k" }). Notes go to $CLAUDE_CONFIG_DIR/handovers if that variable is set. No plugin options.
After each answer, if the context is past 250k tokens, it compacts the conversation, telling the summary to keep the goal, decisions, files changed and next steps. Before every compaction (your /compact, the built-in auto-compact, or its own) it saves the full conversation as markdown to ~/.claude/compact-saves/: every message and each tool call with its result, long ones clipped. Common secrets (API keys, tokens, JWTs, private keys, password: …) are redacted, and the folder is owner-only (700, files 600). A failed save never blocks the compaction. With memdb installed, the saves become searchable there.
/autocompact status on or off, the threshold, this session's size and the last save
/autocompact on | off automatic compaction (on by default; saves happen either way)
/autocompact threshold 250k set the threshold (at least 10k)
/autocompact now save and compact now
The threshold can also be set with the environment variable AUTO_COMPACT_THRESHOLD. Saves go to $CLAUDE_CONFIG_DIR/compact-saves if that variable is set. If the model's context window is no larger than the threshold, the built-in auto-compact fires first (the transcript is still saved). No plugin options.
Its own compaction runs between turns, so after one it sends a short prompt telling the session to carry on where it left off (or say in one line that it was done or waiting for you); /autocompact now doesn't. Long autonomous runs are smoother if the built-in auto-compact, which compacts mid-turn and keeps going, fires at the same size: set CLAUDE_CODE_AUTO_COMPACT_WINDOW to the threshold plus 13000 (e.g. 213000 for 200k). The mod then stays as a backup and still saves the transcript before every compaction.
Wraps xcodebuild, swift build and swift test commands that Claude runs in Bash. The full output goes to a log file and Claude sees only the errors, failing tests, the summary and the tail, plus the log path. The exit code is preserved. Logs are in ~/.claude/build-trimmer/logs and are deleted after 7 days. Add # no-trim to a command to leave it alone.
Options:
| Option | Default | Meaning |
|---|---|---|
developerDir | empty (off) | DEVELOPER_DIR to build with, e.g. /Applications/Xcode-beta.app/Contents/Developer |
developerDirPathMatch | empty | Use developerDir only when the command or working folder contains this text, e.g. /MyApp. Empty means every build |
extraBuildScripts | empty | Comma-separated script names that run xcodebuild or swift test themselves, e.g. test.sh,ci.sh |
A command that already sets DEVELOPER_DIR is never changed. If python3 is missing the full log is shown instead.
/improve <rough prompt> rewrites a rough prompt into a clear, specific one, using what the session already knows about your project, and puts it in the prompt box so you can review and edit it. Run /improve send to submit the last one. It keeps your intent and does not add goals you did not ask for. No options.
When Claude ends a turn by handing the next move back in plain text ("Want me to…?", "Should I…?", "Let me know if…"), the mod blocks that stop once and tells Claude to either keep working, routing around anything blocked, or ask properly with AskUserQuestion (2–4 options, recommendation first). A turn that already asked with AskUserQuestion, plan approval or the desktop app's wrap-up buttons is let through, and so is the second stop in a row, so it never loops. Safety confirmations (push, send, delete) still get asked, as options. The phrases it looks for are in hooks/check.ts. No options.
A searchable memory database (SQLite full-text search, ranked and stemmed) for Claude. It indexes your Claude memory files (~/.claude/projects/*/memory/*.md) automatically, and also holds:
memdb_add)memdb_index)~/.claude/compact-saves/ is indexed automatically, one entry per exchange (your prompt and the work that answered it), titled with the date and the prompt's first line and filed under the folder the session ran in. Search ranks memories and notes above docs and docs above transcripts, shows at most two old conversations by default (the best exchange of each) and says how many more matched; search with kind transcript for all of them. Deleting a save removes it; the database file is owner-only (600).Claude gets these tools: memdb_search, memdb_add, memdb_get, memdb_index and memdb_forget, and a short note in the system prompt telling it to search before rereading long notes. You get /memdb <words> to search, plus /memdb stats, /memdb list, /memdb get <name> and /memdb sync.
If Python is missing, older than 3.8, or lacks FTS5, the tools answer with a clear message instead of failing.
Options:
| Option | Default | Meaning |
|---|---|---|
python | python3 | Python command to run the script |
dbPath | empty | Database file. Empty means ~/.claude/memdb/memory.db (or under $CLAUDE_CONFIG_DIR) |
promptNote | on | Add the short "memdb is available" note to the system prompt |
The script also works on its own, with no Claude involved. After installing, find it under the plugin folder (or clone this repo):
python3 plugins/memdb/bin/memdb.py --help
python3 plugins/memdb/bin/memdb.py search "database port"
python3 plugins/memdb/bin/memdb.py add staging-port "It is 5433" -d "staging DB port"
MEMDB_PATH overrides the database location.
cache-tax by Karan Bansal (MIT), copied here at upstream commit 432a08d (2.3.0) so it installs with the rest. /keepwarm keeps the one-hour prompt cache warm through a break by sending a tiny ping 50 minutes after the last request; /keepwarm always does that for every session, for up to six hours after each turn. When the cache has gone cold, it stops the first send once and shows what the rewrite will cost. /cache-tax shows the cache state and prices. See its README.
One change from upstream: after a compaction in the middle of a turn (the built-in auto-compact), it starts pinging again as soon as the next request comes back, rather than when the turn ends. Without it, a long autonomous turn that compacted and then sat at a permission prompt or a question went cold. Two tests at the end of tests/register.test.ts cover it.
reflect-mod from claude-reflect by Bayram Annakov (MIT), copied unchanged at upstream commit b6c4232 (3.3.0). After a short prompt that corrects Claude, a model check decides whether it is a reusable rule; if so, a band above the prompt offers to save it to CLAUDE.md with one press. See its README.
/config in a terminal session (each mod's options are rows there), or reinstall and answer the options screen.claude plugin update <mod> (or claude plugin marketplace update claude-mods first).claude plugin disable <mod>; turn back on with claude plugin enable <mod>.claude plugin uninstall <mod>. To drop the marketplace too: claude plugin marketplace remove claude-mods.~/.claude/memdb/; delete that folder if you want the data gone. auto-handover notes stay in ~/.claude/handovers/, auto-compact saves in ~/.claude/compact-saves/ and build-trimmer logs in ~/.claude/build-trimmer/logs/.Each mod is a folder under plugins/. Check one with:
claude plugin validate plugins/<mod>
claude plugin test plugins/<mod>
claude plugin validate . # the marketplace file
MIT licensed, see LICENSE.
hooks/register.ts 97 lines1import type { Engine, Register } from 'claude-code'
2
3import { HELP, NOTE, PLUGIN, PREFLIGHT, TOOLS, commandArgs, preflightMessage } from './memdb'
4import type { Args } from './memdb'
5
6type Outcome = { ok: true; text: string } | { ok: false; text: string }
7
8type Config = { python: string; dbPath: string }
9
10// The python check passes once per python command and is then remembered; a failure is retried on the next call.
11const checked = new Set<string>()
12
13async function check($: Engine, python: string): Promise<string | undefined> {
14 if (checked.has(python)) return undefined
15 try {
16 const r = await $.process.run([python, '-c', PREFLIGHT], { timeoutMs: 15_000 })
17 if (r.exitCode !== 0) return preflightMessage(python, r.exitCode, r.stdout)
18 } catch {
19 return `memdb could not start "${python}": it is not installed or not on PATH. Install Python 3.8+ or set the "python" option of the memdb plugin.`
20 }
21 checked.add(python)
22 return undefined
23}
24
25async function run($: Engine, cfg: Config, args: string[], stdin?: string): Promise<Outcome> {
26 const problem = await check($, cfg.python)
27 if (problem) return { ok: false, text: problem }
28 try {
29 const r = await $.process.run([cfg.python, `${$.plugin.root}/bin/memdb.py`, ...args], {
30 ...(stdin !== undefined ? { stdin } : {}),
31 ...(cfg.dbPath ? { env: { MEMDB_PATH: cfg.dbPath } } : {}),
32 timeoutMs: 60_000,
33 })
34 const out = r.stdout.trim()
35 const err = r.stderr.trim()
36 if (r.exitCode !== 0) return { ok: false, text: `memdb failed (exit ${r.exitCode}): ${err || out || 'no output'}` }
37 return { ok: true, text: out || err || 'Done.' }
38 } catch (e) {
39 return { ok: false, text: `memdb could not run: ${String(e)}` }
40 }
41}
42
43// Runs one tool call: builds its argv, runs memdb.py, and answers with the output (or an error the model reads).
44async function serve($: Engine, cfg: Config, name: string, e: unknown): Promise<{ result: string } | { deny: string }> {
45 const t = TOOLS.find(x => x.name === name)!
46 let built
47 try {
48 built = t.build(e as Args)
49 } catch (err) {
50 return { deny: `${name}: ${(err as Error).message}` }
51 }
52 const out = await run($, cfg, built.args, built.stdin)
53 return out.ok ? { result: out.text } : { deny: out.text }
54}
55
56const failed = () => ({ deny: 'memdb: the tool failed unexpectedly.' })
57
58export const register: Register = (on, options) => {
59 const cfg: Config = {
60 python: (typeof options.python === 'string' && options.python.trim()) || 'python3',
61 dbPath: typeof options.dbPath === 'string' ? options.dbPath.trim() : '',
62 }
63 const promptNote = options.promptNote !== false
64
65 on('session.start', async ($, e, next) => {
66 for (const t of TOOLS) {
67 await $.tool.register({ name: t.name, description: t.description, inputSchema: t.inputSchema, isDeferred: false })
68 }
69 await $.command.register({
70 name: 'memdb',
71 description: 'Search the memory database (/memdb <words>), or: stats, list, get <name>, sync',
72 argumentHint: '<words> | stats | list | get <name> | sync',
73 })
74 return next(e)
75 })
76
77 // One hook per tool, each with its literal name.
78 on('tool.call', { tool: 'mcp__memdb__memdb_search' }, ($, e) => serve($, cfg, 'memdb_search', e)).catch(failed)
79 on('tool.call', { tool: 'mcp__memdb__memdb_add' }, ($, e) => serve($, cfg, 'memdb_add', e)).catch(failed)
80 on('tool.call', { tool: 'mcp__memdb__memdb_get' }, ($, e) => serve($, cfg, 'memdb_get', e)).catch(failed)
81 on('tool.call', { tool: 'mcp__memdb__memdb_index' }, ($, e) => serve($, cfg, 'memdb_index', e)).catch(failed)
82 on('tool.call', { tool: 'mcp__memdb__memdb_forget' }, ($, e) => serve($, cfg, 'memdb_forget', e)).catch(failed)
83
84 on('command.run', { command: 'memdb' }, async ($, e) => {
85 const args = commandArgs(e.args)
86 if (args === 'help') return { text: HELP }
87 return { text: (await run($, cfg, args)).text }
88 })
89
90 if (promptNote) {
91 on('prompt.compose', async ($, e, next) => {
92 const r = await next(e)
93 return { sections: [...r.sections, { id: `${PLUGIN}:note`, text: NOTE, scope: 'session' as const }] }
94 }).catch(($, e, next) => next(e))
95 }
96}
97hooks/memdb.ts 154 lines1// Pure helpers for the memdb mod: tool definitions, argv building, python preflight.
2
3export type Args = Record<string, unknown>
4export type Run = { argv: string[]; stdin?: string }
5
6export const PLUGIN = 'memdb'
7
8const str = (v: unknown) => (typeof v === 'string' ? v : v === undefined || v === null ? '' : String(v))
9const opt = (flag: string, v: unknown): string[] => (str(v).trim() === '' ? [] : [flag, str(v)])
10
11/** A required string argument, or a message saying which is missing. */
12function need(a: Args, key: string): string {
13 const v = str(a[key]).trim()
14 if (!v) throw new Error(`Missing required argument "${key}".`)
15 return v
16}
17
18export type ToolDef = {
19 name: string
20 description: string
21 inputSchema: Record<string, unknown>
22 /** The memdb.py arguments (after the script path), plus stdin when the body goes there. */
23 build: (a: Args) => { args: string[]; stdin?: string }
24}
25
26const KINDS = ['memory', 'note', 'doc', 'transcript']
27const TYPES = ['user', 'feedback', 'project', 'reference']
28
29export const TOOLS: ToolDef[] = [
30 {
31 name: 'memdb_search',
32 description:
33 'Ranked full-text search over the memory database: Claude memory files, saved notes, indexed docs and saved past conversations (at most two of those by default; kind transcript for all). Use it before rereading a long notes file or when you need a fact you may have stored. Returns matching entries with snippets (set full to get whole bodies).',
34 inputSchema: {
35 type: 'object',
36 properties: {
37 query: { type: 'string', description: 'Words to search for; every word must match (prefix ok), with an any-word fallback.' },
38 kind: { type: 'string', enum: KINDS, description: 'Only this kind of entry.' },
39 project: { type: 'string', description: 'Only entries whose project contains this text.' },
40 limit: { type: 'integer', minimum: 1, maximum: 50, description: 'Max results (default 8).' },
41 full: { type: 'boolean', description: 'Return full bodies instead of snippets.' },
42 },
43 required: ['query'],
44 },
45 build: a => ({
46 args: [
47 'search',
48 ...opt('-k', a.kind),
49 ...opt('-p', a.project),
50 ...opt('-n', a.limit),
51 ...(a.full === true ? ['-f'] : []),
52 '--',
53 need(a, 'query'),
54 ],
55 }),
56 },
57 {
58 name: 'memdb_add',
59 description:
60 'Save or replace a note in the memory database (names are unique: adding an existing name replaces it). Use it for niche facts that are too small or too many for the always-loaded memory file.',
61 inputSchema: {
62 type: 'object',
63 properties: {
64 name: { type: 'string', description: 'Short slug, e.g. "staging-db-port".' },
65 body: { type: 'string', description: 'The note text.' },
66 type: { type: 'string', enum: TYPES, description: 'user | feedback | project | reference (default project).' },
67 project: { type: 'string', description: 'Project the note belongs to.' },
68 desc: { type: 'string', description: 'One-line description, searched with higher weight than the body.' },
69 },
70 required: ['name', 'body'],
71 },
72 build: a => ({
73 args: ['add', '-t', str(a.type).trim() || 'project', ...opt('-d', a.desc), ...opt('-p', a.project), '--', need(a, 'name'), '-'],
74 stdin: need(a, 'body'),
75 }),
76 },
77 {
78 name: 'memdb_get',
79 description: 'Show full entries by name (exact or substring match), up to 5.',
80 inputSchema: {
81 type: 'object',
82 properties: { name: { type: 'string', description: 'Entry name or part of it.' } },
83 required: ['name'],
84 },
85 build: a => ({ args: ['get', '--', need(a, 'name')] }),
86 },
87 {
88 name: 'memdb_index',
89 description:
90 'Index markdown files (handoff notes, plans, long docs) into the database, split by heading, so memdb_search can find parts of them. Indexed files are re-synced automatically when they change.',
91 inputSchema: {
92 type: 'object',
93 properties: {
94 paths: { type: 'array', items: { type: 'string' }, minItems: 1, description: 'Markdown file paths.' },
95 project: { type: 'string', description: 'Project label for these docs.' },
96 },
97 required: ['paths'],
98 },
99 build: a => {
100 const paths = Array.isArray(a.paths) ? a.paths.map(str).filter(s => s.trim() !== '') : []
101 if (paths.length === 0) throw new Error('Missing required argument "paths".')
102 return { args: ['index', ...opt('-p', a.project), '--', ...paths] }
103 },
104 },
105 {
106 name: 'memdb_forget',
107 description: 'Delete a note that was saved with memdb_add. Memory files are removed by deleting the .md file instead.',
108 inputSchema: {
109 type: 'object',
110 properties: { name: { type: 'string', description: 'Exact note name.' } },
111 required: ['name'],
112 },
113 build: a => ({ args: ['forget', '--', need(a, 'name')] }),
114 },
115]
116
117/** Checked once per session before the first call: Python 3.8+, with SQLite FTS5. */
118export const PREFLIGHT = [
119 'import sys',
120 'if sys.version_info < (3, 8):',
121 ' sys.stdout.write(sys.version.split()[0]); sys.exit(3)',
122 'import sqlite3',
123 'try:',
124 ' sqlite3.connect(":memory:").execute("create virtual table t using fts5(a)")',
125 'except Exception:',
126 ' sys.stdout.write(sqlite3.sqlite_version); sys.exit(4)',
127].join('\n')
128
129export function preflightMessage(python: string, exitCode: number, stdout: string): string {
130 if (exitCode === 3) return `memdb needs Python 3.8 or newer, but ${python} is ${stdout.trim() || 'older'}. Install a newer Python or set the "python" option of the memdb plugin.`
131 if (exitCode === 4) return `memdb needs SQLite with FTS5, which this Python's sqlite3 (${stdout.trim() || 'unknown version'}) lacks. Use a Python built with FTS5 (python.org or Homebrew builds have it) via the "python" option.`
132 return `memdb could not run ${python} (exit ${exitCode}). Install Python 3.8+ or set the "python" option of the memdb plugin.`
133}
134
135export const NOTE = `[memdb] A searchable memory database is available through the tools memdb_search, memdb_add, memdb_get and memdb_index (mcp__memdb__*). Search it before rereading long notes or memory files, and store niche facts that do not belong in the always-loaded memory with memdb_add.`
136
137export const HELP = `/memdb <words> search memories, notes and indexed docs
138/memdb stats counts and database size
139/memdb list list memories and notes
140/memdb get <name> show an entry in full
141/memdb sync re-sync memory files now
142Tools for Claude: memdb_search, memdb_add, memdb_get, memdb_index, memdb_forget`
143
144/** What a /memdb command line means, as memdb.py arguments. */
145export function commandArgs(raw: string): string[] | 'help' {
146 const text = raw.trim()
147 if (text === '' || text === 'help') return 'help'
148 const [verb = '', ...rest] = text.split(/\s+/)
149 const tail = rest.join(' ')
150 if (rest.length === 0 && (verb === 'stats' || verb === 'list' || verb === 'sync')) return [verb]
151 if (verb === 'get' && tail) return ['get', '--', tail]
152 return ['search', '--', text]
153}
154