ctx-memory: how I built a decision memory for Claude on Drupal

ctx-memory is an experiment of mine: a small graph of project decisions, built on Drupal 11 and Typesense, which Claude queries over MCP. I have used it for about five months so that I don't start from zero when I come back to a project in a new session: I call up the project and Claude traces the related decisions, with the evidence next to them.

ctx-memory is an experiment: a decision memory for Claude built as a Drupal 11 site, with four custom entity types, Search API and Typesense. For about five months it has been one of the tools I use most when I work with AI. The code is private for now: it's a case study, and I'm happy to walk anyone interested through it.

What does Drupal do in ctx-memory?

The whole data model of ctx-memory lives in Drupal, which exposes it to the MCP server, the hooks and search through routes and modules. The idea under test is simple: a graph of decisions needs what Drupal already gives every entity, typed fields, revisions, permissions and an admin interface to fix a record. My own code covers the data model and the rules, and nothing else.

What Drupal does What ctx-memory does
four content entity types in a custom module context, decision, evidence and relation, each with revisions and the revision UI, so every change to a decision keeps its history
Dynamic Entity Reference (opens in a new tab) source and target of a relation can be any entity, so one entity type links a decision to its context and to its evidence
permissions confirming a decision takes its own permission, and only my account holds it: the agents capture, a person decides
Search API with Search API Typesense indexes contexts, decisions and evidence for search, with no indexing code of mine
a plugin type every source of evidence is a plugin, and a submodule reads git
REST routes under /ctx/ the surface the MCP server and the two hooks call, in a module of its own that can be uninstalled while the data model stays
Drush commands capture evidence, promote decisions and query the graph from the terminal

Why a custom system, when ready-made ones exist?

I went custom to keep control and to be able to see it. There are plenty of MCP servers that give Claude a memory, and some of them are well made. If you want a ready-made one, cognee (opens in a new tab) is a sound choice: open source under Apache-2.0, written in Python, it turns documents, code and conversations into a knowledge graph with graph and vector search, and it ships an MCP server. I wanted to try a solution of my own instead: use Typesense for search, and keep the data in a small graph on Drupal whose structure I control, field by field.

The problem was a practical one. When I work on the same project across several sessions, each new session starts without remembering the choices made in the earlier ones. With ctx-memory the decisions stay: I find them by querying the graph, instead of explaining them again or, worse, contradicting them.

How is ctx-memory built?

ctx-memory brings together a few components, each with a single job:

Component Role
Drupal 11 on PostgreSQL holds the data model: entities, revisions and permissions
Typesense, through Search API indexes everything for search, with an in-memory index that can be rebuilt from the database
MCP server gives Claude three tools: search, read, capture
two Claude Code hooks capture on their own the proposal.md of every OpenSpec change and every committed ADR, with the permalink
Graph Explorer a 3D view of the graph, to look at how the data is organised
Sablier starts the stack on the first request and stops it when it sits idle

Which rules keep the memory reliable?

The project specification sets four rules as non-negotiable principles:

  1. a captured decision always starts as «proposed», and only a person can confirm it, with a permission no agent holds.
  2. a decision is confirmed only with at least one piece of evidence pointing to a stable source.
  3. the graph is append-only: a decision changes only through a new one that supersedes it, with a date.
  4. every record states who wrote it, a person or a model, and in which run.

In daily use the first rule does most of the work. Every decision in the graph was captured by a model, and each one counts only after I review it: I confirm it, discard it, or later supersede it with a newer one.

How do I use it day to day?

From the terminal, with Claude. I call up the project, and Claude traces the related decisions and their evidence, so a new session starts again from context that is already defined. New decisions are written into the graph by the ctx-memory skill, as proposals.

I don't use the Graph Explorer to search: it's there to look at the structure of the data and to check that the graph is growing the right way.

Image
The ctx-memory Graph Explorer: four main contexts with their areas, decisions and evidence, drawn as a 3D graph.

Sources

I read the ctx-memory specification and code again on 15 October 2026, for this version of the article.

AI modified

This text was translated by AI.

How was AI used?

Translated from the Italian original with AI assistance, then read and corrected by a person, who holds editorial responsibility.