← Writing · No 10 · Architecture

Memory for AI agents: the context-vault architecture

By Felix Hellström · Stockholm · 780 words

Every AI session starts cold. The agent has no memory of what you built last week, the decisions you already made, or the patterns that work for your codebase. You re-explain the same context at the start of every session, and the model treats it as new every time.

The common workaround is a CLAUDE.md file: dump your context into a markdown file the agent reads on startup. It works until it doesn't. The files bloat, they go stale, you forget to update them, and eventually the agent is reading context that actively misleads it. A flat file is a place to put memory, not a memory system.

context-vault is the memory system. This is how it's built and why each piece is there.

The shape: an MCP server over local SQLite

context-vault is a Model Context Protocol server that sits between your AI clients and a local SQLite database. Because it speaks MCP, the same memory layer works across Claude Code, Cursor, and Windsurf without per-client glue. Because the store is local SQLite, your context stays on your machine: no cloud account, no third party holding your decisions.

An agent doesn't read the whole database into its prompt. It calls tools: store an entry, search for relevant ones, flag a conflict. The vault is a service the agent queries, not a document it ingests.

Four ideas do the work

Lifecycle tiers. Every entry is session (the current piece of work), project (stable patterns and conventions), or durable (long-term knowledge that outlives any one project). Tiers are what keep memory from growing forever. Session noise expires; durable knowledge compounds. Without tiers, a memory layer is just an append-only log that gets slower and less relevant every week.

Semantic retrieval. Instead of loading everything, the agent queries for what's relevant using embeddings. A question about deployment pulls the deployment decisions, not the entire history. This is what keeps prompts lean and token costs flat as the vault grows; retrieval cost is bounded by relevance, not by total size.

Conflict detection. When you store a decision that contradicts one already in the vault, the system flags it instead of silently keeping both. This was the hardest part to build. I landed on embedding similarity plus domain heuristics: if two entries share tags and cover similar ground but disagree, surface them for review. It's the feature that stops a memory layer from becoming a pile of stale, contradictory advice.

Buckets. Isolated namespaces per project or context. Client work doesn't bleed into a side project; one product's conventions don't leak into another's. Memory that can't be scoped is memory you stop trusting.

Why it's worth the test suite

The implementation is deliberately small (TypeScript, SQLite, a lightweight local embedding model), but it carries 693 passing tests. That ratio is intentional. When you build a memory layer that agents depend on for correctness, a silent data-loss bug doesn't show up as a crash. It shows up three weeks later as an agent confidently acting on a decision you reversed. The tests exist because the failure mode is invisible, not loud.

The MCP surface took its own iteration. The protocol is solid, but the ergonomics around tool definitions and error handling reward getting the contract exactly right, so a client never has to guess what a tool returned.

What it changes

I run context-vault in my daily workflow. Decisions, patterns, project briefs, and the occasional hard-won insight go into the vault as I work; the next session picks them up automatically. The practical result is that per-session context setup drops to near zero. The agent already knows.

The deeper result is that memory becomes infrastructure rather than a habit. Once an agent can remember across sessions, providers, and machines, it stops being a stateless tool you re-brief every morning and starts being a collaborator that accumulates knowledge: which is the entire point of building the layer instead of maintaining yet another markdown file.

context-vault is published on npm and the source is open:

npx context-vault init

The repo is at github.com/fellanH/context-vault and the docs are at context-vault.com.

I build agent infrastructure — a Rust multi-agent OS I operate daily, and context-vault, a published MCP memory layer that works across Claude Code, Cursor, and Windsurf.

Available Q3 2026. If you're building agent systems and want someone who has shipped this kind of infrastructure, let's talk.

Next up