Sign In

@betterdb/memory

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@betterdb/memory

BetterDB Memory for Claude Code — Valkey-powered persistent memory across sessions

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
24
60%
Maintainers
1
Weekly downloads
 
Created
Source

BetterDB Memory for Claude Code

Persistent, semantic memory for Claude Code sessions — powered by Valkey.

Every time you start a new Claude Code session, context is lost. BetterDB Memory automatically captures what you did, embeds it as vectors in Valkey, and retrieves relevant history at the start of each new session.

Quick Start

Prerequisites

  • Bun runtime — required (the CLI and all hooks run on Bun, not Node)
  • Claude Code installed
  • Valkey 8.0+ with the Search module

Install

# 1. Copy .env.example and fill in your settings
cp .env.example .env

# 2. Install
bunx @betterdb/memory install

The install will:

  • Compile native hook binaries to ~/.betterdb/bin/
  • Register 4 lifecycle hooks with Claude Code
  • Register the MCP server for mid-conversation tools
  • Create the Valkey search index
  • Save your .env values to ~/.betterdb/memory.json for runtime use

Don't have Valkey?

The setup skill will offer to spin one up in Docker for you. Or run it manually:

# Via CLI
bunx @betterdb/memory docker-valkey

# Or directly with Docker
docker run -d --name betterdb-valkey -p 6379:6379 -v betterdb-valkey-data:/data valkey/valkey-search:8 valkey-server --save 60 1

How It Works

HookWhat it does
SessionStartRetrieves relevant memories via vector search, injects as context
PostToolUseRecords every tool call to a temp JSONL file
StopSummarizes the session, embeds it, stores in Valkey
PreToolUseSurfaces file-specific history when accessing known files

MCP Tools

Claude can use these mid-conversation:

  • search_context — Semantic search over past sessions
  • store_insight — Save a decision, pattern, or warning
  • list_open_threads — Show unresolved items
  • forget — Delete a specific memory

CLI Commands

bunx @betterdb/memory install        # Set up hooks + MCP server
bunx @betterdb/memory status         # Check health
bunx @betterdb/memory uninstall      # Remove everything
bunx @betterdb/memory maintain       # Run aging/compression manually
bunx @betterdb/memory docker-valkey  # Manage Docker Valkey container

Configuration

Copy .env.example to .env and fill in your values before running bunx @betterdb/memory install. They get saved to ~/.betterdb/memory.json and used by the compiled binaries at runtime.

Core

VariableDefaultDescription
BETTERDB_VALKEY_URLredis://localhost:6379Valkey connection URL
BETTERDB_VALKEY_INDEX_NAMEbetterdb-memory-indexValkey search index name
BETTERDB_EMBED_DIM1024Embedding dimensions
BETTERDB_MAX_CONTEXT_MEMORIES5Memories injected per session
BETTERDB_CONTEXT_FILE.betterdb_context.mdContext injection file
BETTERDB_ALLOW_REMOTE_FALLBACKtrueFall back to remote APIs if local models unavailable

Model Providers

VariableDefaultDescription
BETTERDB_EMBED_PROVIDERauto-detectForce embed provider: ollama, voyage, openai, groq, together
BETTERDB_SUMMARIZE_PROVIDERauto-detectForce summarize provider: ollama, anthropic, openai, groq, together
BETTERDB_EMBED_MODELmxbai-embed-largeOllama embedding model name
BETTERDB_SUMMARIZE_MODELmistral:7bOllama summarization model name
BETTERDB_OLLAMA_URLhttp://localhost:11434Ollama API URL

API Keys

At least one embedding provider and one summarization provider must be available. Ollama is free and local; the others require API keys.

VariableProviderUsed for
ANTHROPIC_API_KEYAnthropicSummarization only (no embeddings)
VOYAGE_API_KEYVoyage AIEmbeddings only
OPENAI_API_KEYOpenAIEmbeddings + summarization
GROQ_API_KEYGroqEmbeddings + summarization
TOGETHER_API_KEYTogether AIEmbeddings + summarization

Aging Pipeline

VariableDefaultDescription
BETTERDB_DECAY_RATE0.95Memory importance decay per day
BETTERDB_COMPRESS_THRESHOLD0.3Importance threshold for compression
BETTERDB_DISTILL_MIN_SESSIONS5Min sessions before knowledge distillation
BETTERDB_AGING_INTERVAL_HOURS6Hours between automatic aging runs

License

MIT

Keywords

claude-code

FAQs

Package last updated on 04 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts