KirtiRamchandani/memory.cpp

Your repo remembers: local-first AI memory and context control plane for developers and coding agents.

What it solves

Coding agents often feed on a huge, messy pile of repository context — old docs, failed attempts, stale decisions, test logs — which bloats prompts, slows down responses, breaks prompt caching, and sometimes leaks secrets or pushes the agent to make wrong patches. memory.cpp treats this as a compilation problem: instead of just retrieving more context, it decides what actually belongs in the prompt, what should be left out, and how to keep the reusable part stable across requests.

How it works

memory.cpp runs before the model sees the request. It takes repo files, git history, tool traces, and user-remembered facts, then builds a typed intermediate representation (MemoryIR) where each block carries metadata like source anchor, trust, freshness, sensitivity, token cost, and cache role. A series of optimizer passes then splits this into a stable prefix (durable repo knowledge, byte-identical across tasks) and a fresh suffix (task-specific text, logs, errors). The stable prefix is hashed with blake3 so prompt caches can hit reliably. It also tracks negative memory — explicit exclusions for stale docs, superseded decisions, or harmful content — and freshness proofs tie every piece of memory to a source file, commit, test, or human confirmation. The output includes a cache manifest, a provenance ledger, and optional lockfile for reproducibility.

Who it’s for

Developers and teams building long-horizon coding agents that need to reference repository context efficiently and safely. It’s also useful for anyone who wants to reduce token costs, improve prompt-cache hit rates, or audit exactly what context an agent was given. The project ships as a Rust CLI (memory) and can also install as an MCP server for Claude or other tooling.

Highlights

  • Local-first by default: all data lives in a SQLite vault under .memory.cpp/, no cloud, no telemetry, no network calls unless you explicitly enable a connector.
  • Compiler-style design: separates stable prefix from fresh suffix, making prompt caching actually work.
  • Negative memory blocks stale, contradictory, or secret-laden context from ever entering the prompt.
  • Includes CAMC-Bench, a synthetic benchmark that shows the full pipeline reduces tokens by ~58% while eliminating stale entries, contradictions, and secrets, while keeping task success at 3/3.
  • Provides a rich CLI: compile, cache-manifest, prove, audit-stale, lock, reproduce, benchmark, and more.
  • Can generate provider-specific packs for Claude, Codex, Gemini, Cursor, Continue, and MCP.

Related

  • Project
  • Project
  • Project
  • Project