
AI & Copilot
Giving Claude a Second Brain
How I gave Claude persistent memory in Postgres: an MCP server with per-project isolation enforced by database roles, not application code.
By Paul Bentley19 min read
On this page
- What separation has to mean
- Prior art: Karpathy's LLM wiki pattern
- Where claude-brain diverges: the knowledge layer isn't for humans
- The rules engine
- Subjects and Postgres roles
- The kind vocabulary
- Search before add
- Capture at session end, and why I turned it off
- The lint loop
- How it's actually deployed
- What it feels like to use
- What I learnt building it
- What's next
Every conversation I have with Claude starts the same way: with Claude knowing nothing about me, nothing about my homelab, nothing about any of the projects I'm working on. I fix this the obvious way, by pasting context, pointing at files, or re-explaining decisions I've already explained fifty times.
That works, and it costs more than it looks. Everything I paste lands in the context window, and the context window is finite. On a standard plan it is finite enough to feel, which changes the problem entirely: the tokens spent explaining the background are the same tokens the actual work needs. Front-load enough history to make a session useful and a real portion of the budget is gone before anything has been done. Run long enough and the conversation gets compacted, the summary quietly loses the detail that was pasted in, and it gets pasted again. I have had sessions where the first ten minutes were me re-explaining my own infrastructure, and the first thing lost to compaction was that same explanation.
The deeper problem is that this is the wrong shape. Handing over everything that might be relevant, up front, on the off-chance, is the opposite of how retrieval should work. What I want is for the model to pull the two or three things that actually bear on the conversation at hand, at the moment it needs them, from something that already knows them. Then the cost scales with relevance rather than with the size of my history. The model is capable; the context it gets handed is threadbare, and it is threadbare because the only mechanism for filling it is expensive at both ends.
I have a lot of working contexts, each with its own repo, its own vocabulary, and in several cases its own rules about what can be discussed where.