second-brain-cli 0.11.0

Universal memory layer for AI coding agents: ingest, recall, and sync across Claude Code and Cursor
second-brain-cli-0.11.0 is not a library.

second-brain

A universal memory layer for AI coding agents. Ingests conversation history from Claude Code and Cursor into a knowledge store with vector and lexical search, then serves it via MCP (Model Context Protocol) so any AI agent can recall what you've discussed, decided, and built across projects and machines.

Why

Every AI coding tool keeps its own conversation history locked in its own format. Claude Code stores JSONL in ~/.claude/projects/, Cursor keeps JSONL in ~/.cursor/projects/. None of them talk to each other, and none of them let you search across sessions. If you discussed an architecture decision with Claude last week and ask Cursor about it today, you start from zero.

second-brain fixes this by creating a single knowledge store that ingests from all your AI tools, embeds everything for semantic search, tracks relationships between memories (reinforces, contradicts, supersedes), and exposes it all through MCP so any connected agent can recall context from any previous conversation.

Memory Pipeline

  1. File watcher detects new .jsonl in ~/.claude/projects/ (10s debounce)
  2. Hash check skips unchanged files
  3. Adapter parses tool-specific format into conversation chunks
  4. Heuristic filter (is_memorable) rejects noise: tool output, short lines, code-only blocks
  5. Dedup checks first 128 chars against existing memories
  6. Embed generates 384-dim BGE vector (local)
  7. Store writes to SQLite with conversation and entity relations
  8. Consolidate (manual) distills raw memories via LLM into concise knowledge facts, then cleans up raw

Crates

Crate Description
second-brain-core SQLite storage, vector and lexical indexes, BGE-small-en-v1.5 embeddings, QueryEngine, schema types
second-brain-adapters Parsers for Claude Code JSONL and Cursor JSONL formats
second-brain-sync SSH transport, JSONL change log export/import, conflict resolution
second-brain-mcp Thin MCP stdio server, proxies to daemon over HTTP
second-brain-cli CLI binary for setup, ingest, recall, sync, consolidation
second-brain-api HTTP daemon: owns DB, embedder, file watcher, serves all endpoints on port 7200

Install

cargo install second-brain-cli second-brain-api second-brain-mcp
second-brain-cli setup

setup handles everything: creates ~/.second-brain/, installs a systemd user service, registers the MCP server with Claude Code (claude mcp add --scope user), starts the daemon, and runs the first ingest.

Or build from source:

git clone https://github.com/Anyesh/second-brain.git
cd second-brain
cargo build --release
./target/release/second-brain-cli setup

Usage

Ingest conversations

# Ingest Claude Code history
sb ingest claude-code

# Ingest Cursor history
sb ingest cursor

# Ingest everything
sb ingest all

Ingest reads from standard paths (~/.claude/projects/ for Claude Code, ~/.cursor/ for Cursor), parses conversations, extracts memories with types (episodic, semantic, procedural), generates 384-dim embeddings, and stores everything in SQLite with entity extraction and relationship tracking.

Recall

sb recall "how does authentication work in the API"
sb recall "what database did we choose and why"

Recall uses a weighted scoring function: 50% vector cosine similarity, 30% graph relevance (relation types and counts), 20% recency (exponential decay + access frequency). Results below a 0.59 similarity threshold are filtered out.

MCP server

sb setup registers this automatically. To register it by hand:

claude mcp add --scope user second-brain -e SECOND_BRAIN_API=http://127.0.0.1:7200 -- /path/to/second-brain-mcp

MCP tools available:

Tool Description
recall Semantic search with graph-boosted scoring
remember Store a new memory with embedding
ingest Trigger conversation ingestion
associate Create explicit relations between memories
forget Remove a memory by ID
context Get a memory with its graph neighborhood
status DB stats: memory count, index health, sync state

Sync

Bidirectional sync between machines over SSH using a sequence-numbered JSONL change log.

# Full bidirectional sync with a peer
sb sync user@remote-host

# Manual export/import
sb sync-export --after-seq 0 > changes.jsonl
cat changes.jsonl | sb sync-import

# Check sync state
sb sync-status

# Backfill sync log for data that predates the log
sb sync-backfill

Sync resolves conflicts with last-write-wins on memory updates (newer last_accessed wins). Conversations, entities, and relations use create-or-skip semantics.

Consolidation

Distill raw conversation memories into higher-level summaries using a local LLM (Ollama).

sb consolidate                                        # default: 50 memories, concurrency 3
sb consolidate --limit 200                            # process more
sb consolidate --model gemma-4-E4B-it-Q4_K_M          # default model
sb consolidate --llm-url http://gpu-server:8081        # OpenAI-compatible endpoint
sb consolidate --concurrency 3                         # parallel LLM requests
sb consolidate --guard none                           # skip the identifier rewrite (default: retry)
sb consolidate --dry-run                               # preview without writing

Uses any OpenAI-compatible chat completions endpoint (llama.cpp, Ollama, vLLM). When a distillate drops an exact identifier its excerpt names (a path, backticked command, ticket id or number), the default --guard retry asks the model once to rewrite it with them and keeps the rewrite only if it loses nothing the first draft had. After consolidation, raw memories are automatically cleaned up. Distilled memories are the primary knowledge store, linked to sources via DistilledFrom relations.

Daily Pipeline

End-of-day automation: consolidate memories via local LLM.

sb daily-pipeline                            # consolidate memories
sb daily-pipeline --llm-url http://localhost:8081 --model my-model

Requirements:

  • Local LLM at localhost:8081 (llama.cpp, Ollama, vLLM) or pass --llm-url
  • Default model: gemma-4-E4B-it-Q4_K_M (override with --model)

Memory Types

Memories are classified at ingest time (heuristic, no LLM):

Type Trigger patterns
Task TODO, FIXME, action item, remaining, need to
Decision decided, chose, went with, agreed, selected
Architecture architecture, data model, schema, the approach
Debugging root cause, the bug, the issue is, error:
Question contains "?" + interrogative word
Procedural steps:, to do this, run, install, how to
Episodic deployed, shipped, migrated, found that
Semantic catch-all factual knowledge

Priority order: first match wins (Task → Decision → ... → Semantic).

Configuration

Env var Default Description
SECOND_BRAIN_DB ~/.second-brain/brain.db Path to the SQLite database
SECOND_BRAIN_API http://127.0.0.1:7200 Daemon URL (used by MCP server and CLI)
SECOND_BRAIN_BIND 127.0.0.1:7200 Daemon listen address
SECOND_BRAIN_RERANK_DOC_CHARS 1024 Cross-encoder document character budget; 0 disables truncation
SECOND_BRAIN_RERANK_POOL min(cores, 4) Rerank session pool size (concurrency headroom, not throughput)
SECOND_BRAIN_RERANK_CHECKOUT_SECS 30 Seconds to wait for a free rerank session before falling back to the non-reranked hybrid path
RUST_LOG - Tracing filter (e.g. info, second_brain_mcp=debug)

Query scoring

The QueryEngine combines three signals:

  • Vector similarity (weight: 0.5): cosine distance between query embedding and memory embedding using BGE-small-en-v1.5 (384 dimensions)
  • Graph relevance (weight: 0.3): based on relation types connected to the memory. Reinforces (+0.3), RelatesTo (+0.2 * strength), DistilledFrom (+0.15), Mentions (+0.1), DerivedFrom (+0.05), Contradicts (-0.1), Supersedes (-0.2)
  • Recency (weight: 0.2): exponential decay over 30 days plus a logarithmic access frequency boost

Weights are configurable via QueryEngine::with_weights(vector, graph, recency).

Graph schema

Relation types:

  • RELATES_TO (Memory -> Memory): semantic relationship with strength
  • REINFORCES (Memory -> Memory): one memory strengthens another
  • CONTRADICTS (Memory -> Memory): conflicting information with resolution
  • SUPERSEDES (Memory -> Memory): newer information replaces older
  • DISTILLED_FROM (Memory -> Memory): consolidation link
  • DERIVED_FROM (Memory -> Conversation): provenance tracking
  • MENTIONS (Memory -> Entity): entity extraction links

Dependencies

  • fastembed 5 for BGE-small-en-v1.5 embeddings (384-dim, runs locally, no API calls)
  • Rust 1.85+

License

MIT