§00System 01 / PersistenceCase Study

Persistent memory for AI coding agents, served over MCP.

Every developer working with AI coding agents has the same conversation every session: re-explaining the codebase from scratch before a single line gets written. Memex ends that by turning every commit into structured, queryable graph state — so the next session, in any agent, starts where the last one left off.

MITPython333 passing · ~93% coverage
View on GitHub
§01OverviewWhy it exists

AI coding agents are stateless by design. Context windows are ephemeral, and every switch from one agent harness to another resets everything to zero. The architecture behind a codebase — the reasoning behind a refactor, the decisions made last month, the bug that was already found and fixed — exists only in the developer's head, re-typed into a prompt on every session.

Memex is a daemon and MCP server that watches a repository continuously and writes what it observes into a bitemporal knowledge graph: modules, symbols, decisions, problems, lockfile facts. Agents query it instead of re-discovering the same refactor every time the context gets cleared.

The insight that makes it more than a read-only cache: agents are themselves a source of knowledge worth persisting. An agent working a multi-hour refactor accumulates understanding — why an abstraction exists, an undocumented coupling between two modules — that normally disappears when the session ends. Memex lets the agent write that back, so the graph gets smarter with every session instead of only ever being read from.

§02ArchitectureHow it fits
REPOWATCHERtree-sitter · git hooksSYNTHESIZERGemini Flash → decisionsGRAPHNeo4j · bitemporalMCP SERVER14 tools→ Claude · Cursor · Codex— AGENT WRITES DECISIONS BACK

A commit triggers the whole pipeline: extraction, synthesis, and a bitemporal write, before any agent ever asks a question.

Watcher

Git hooks + tree-sitter observe every file save and commit, extracting symbols locally in under 50ms — no LLM call on the hot path.

Synthesizer

Gemini Flash distills each commit's diff into Decision nodes. Batched by a debounce window, never called inside a live tool response.

Graph

Neo4j via Graphiti. Bitemporal — every edge carries created_at and an optional expired_at. Facts are expired, never deleted.

MCP server

14 tools (8 read, 4 write, 2 analytic) over stdio or HTTP, serving Claude Code, Cursor, Codex, and Gemini CLI identically.

Scheduler

A nightly job recomputes confidence decay across the graph and surfaces edges that have gone stale.

§03Technical DecisionsTradeoffs & rationale

Confidence is computed at query time, never stored as a mutable number.

A stored confidence score that mutates invites silent drift no one notices. Recomputing it on every read — from base confidence, validation status, recency, and access count — keeps the graph auditable.

Rejected —A single stored confidence field updated in place on each access.

Two decay regimes, not one.

Human-validated facts decay slowly (half-life ~139 days). Unvalidated facts must earn their place — stale at exactly 30 days unless corroborated. One curve either lets unreviewed guesses linger forever or makes trusted facts vanish too fast.

Gemini Pro for grounded synthesis, Flash for everything else.

explain_change uses Pro because grounding a cross-referenced explanation actually matters. Every other tool call — the high-volume path — uses Flash. The split is by task criticality, not a blanket cost decision.

Hierarchical Leiden clustering over a hybrid edge graph, not flat tagging.

get_project_context has to stay under 1500 tokens whether the repo has 50 modules or 5,000. Clusters are pinned by Jaccard similarity ≥ 0.5 across reruns, so names survive renames instead of reshuffling on every commit.

§04ImplementationStack & delivery
Pythontree-sitterNeo4j (via Graphiti)Gemini Flash / ProDockerMCP (stdio + HTTP)SQLite (local telemetry)pytest
  • 333 tests passing, ~93% coverage
  • Published on PyPI (memex-mcp) and npm (stifler-memex-mcp)
  • Installable via the Claude Code plugin marketplace, uv, pip, or npx with zero install
  • Self-hosted team deployment: one shared Neo4j + memex-server, auth on by default, database ports never exposed to the host
  • CI: GitHub Actions test suite + CodeQL + OpenSSF Scorecard on every push
§05ImpactMeasurable outcomes
14
MCP tools — 8 read, 4 write, 2 analytic
5K+
PyPI downloads (memex-mcp)
333
Tests passing, ~93% coverage
139d
Validated-fact half-life under decay

Published on both PyPI and npm, listed on the Claude Code plugin marketplace, and tracked by an OpenSSF Scorecard — built to be depended on, not a demo.