This project has a persistent memory system (BetterDB). When a user asks about previous sessions, past commands, earlier decisions, or anything from prior conversations, always use the search_context MCP tool first before answering. Do not guess or rely only on CLAUDE.md — search your actual memories.
Available MCP tools:
search_context— Search past sessions for relevant context. Use this for any "what did I/we do" questions.store_insight— Save an important decision, pattern, or warning explicitly.list_open_threads— Show unresolved items from past sessions.forget— Delete a specific memory.
/plugin marketplace add BetterDB-inc/memory
/plugin install betterdb-memory
Then run /betterdb-memory:setup to configure your Valkey connection.
bunx @betterdb/memory installdocker compose up -d # Start Valkey (with search module) + Ollama
bun install # Install dependencies
bun run setup-index # Create the FT indexOllama models are pulled automatically by the ollama-init container. If running Ollama locally, pull manually:
ollama pull mxbai-embed-large
ollama pull mistral:7b- Runtime: Bun only. No Node.js, tsx, or ts-node.
- Unit tests:
bun test tests/unit— no external deps required. - Integration tests:
bun test tests/integration— requires Docker (Valkey) running. SetBETTERDB_SKIP_INTEGRATION=trueto skip. - Type checking:
bun run typecheck— must pass with zero errors.
bun run build:hooks # Compile hook binaries → dist/hooks/Hook binaries are platform-specific (bun build --compile). Always rebuild before running install-hooks.sh. Cross-compile with --target if deploying to a different OS/arch.
- All hooks use the
runHook()wrapper fromsrc/hooks/_utils.ts. - Hooks must never throw unhandled exceptions — errors go to stderr, exit code is always 0.
- Hook events:
SessionStart,Stop,PreToolUse,PostToolUse. - Hooks receive JSON on stdin per the Claude Code hooks contract.
- If Ollama is unavailable at session end, raw transcripts are queued to
betterdb:ingest_queue— never dropped.
Changing BETTERDB_EMBED_MODEL or BETTERDB_EMBED_DIM requires re-embedding all stored memories:
bun run migrate-embeddings -- --dry-run # Preview
bun run migrate-embeddings # ExecuteThe system refuses to start if BETTERDB_EMBED_DIM doesn't match the stored dimension.
- Default models must be MIT or Apache 2.0 (currently:
mxbai-embed-large,mistral:7b). - Attribution-required models (CC BY, Qwen License) go in
PRESET_ATTRIBUTIONonly. - Verify license before adding any new default model.
- No secrets in code. All connection strings and API keys via
.envonly..envis gitignored. - Valkey key prefix: All keys use
betterdb:prefix. Never write bare keys. - Single responsibility per file. Client code knows nothing about hooks. Hooks import from client and memory modules only.
- No
any. TypeScript strict mode. Use.parse()or.safeParse()for all Zod results. - Compression is bounded. Max 50 memories from compress queue, max 100 per project group per run.
.betterdb_context.mdis transient. Gitignored. Cleaned up on session end.- Bun APIs preferred. Use
Bun.file(),Bun.write(),Bun.spawnSync()over Node equivalents. - Valkey Search module:
valkey/valkey-bundle:8ships with valkey-search pre-loaded — no custom Dockerfile needed. Verify withvalkey-cli MODULE LIST(should showsearch).