The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the GrayMatter listing page.
AI agents forget everything between sessions. GrayMatter gives them persistent memory, a self-building knowledge graph, and cuts context tokens by 90%.
One binary. Drop it in. Run it. No Docker, no databases, no config files, no cloud accounts, no bullshit.
General-purpose MCP server. Zero vendor lock-in.
Works with Claude Code, Cursor, Codex, OpenCode, Antigravity — and any MCP-compatible client.
Also a plain Go library if you don't use MCP.
Free. Offline. No account required.
Every AI agent is stateless by default. Each run re-injects the full conversation history — and that history grows linearly. Two prompts in and you've already burned half of your daily quota.
That's not just a memory problem. That's a money and performance problem.
Mem0, Zep, Supermemory solve this — but they're Python/TypeScript-only and require a running server. The Go ecosystem has no production-ready, embeddable, zero-dependency memory layer for agents.
That gap is GrayMatter.
~90% reduction in context tokens — versus full-history injection.
Remembers what a sliding window forgets: facts planted 96 sessions back come back 83% of the time.
Context quality improves over time as consolidation surfaces only what matters.
No Docker. No Redis. No API key required for storage.
Drop it in once. It auto-connects to Claude Code, Cursor, Codex, OpenCode, Antigravity — any MCP-compatible client picks it up automatically.
Your agent doesn't just remember facts — it builds a map of how they connect.
Run the daemon with --kg and every consolidation cycle extracts typed
entities (person, organization, project) and links the ones that appear
together. No manual tagging. No configuration. The graph builds itself from
ordinary use.
Every edge carries receipts: the fact IDs that produced it.
Export to Obsidian with one command — entities become notes,
connections become wikilinks, and the whole graph renders natively.
The graph as one self-contained page — inline force-directed SVG, zero external assets, works offline. Hover any edge to see the fact IDs that produced it:
Watch it build, one frame per session:
You can't improve what you can't see.
graymatter tui opens a live terminal dashboard with everything your
agent memory is doing — no extra setup required.
What you get at a glance:
The dashboard auto-refreshes every 5 seconds. Press 1–4 to switch tabs,
r to force refresh, q to quit.
graymatter doctor --graph extends visibility to the knowledge graph itself:
hubs by degree, articulation points, orphans, and a declared connectivity
ratio — printed or emitted as JSON.
| Persistent memory | Facts survive across sessions. Recall by meaning, not just keyword |
| 90% token reduction | Top-8 relevant facts instead of full-history injection |
| Automatic hooks | Claude Code injects routine recall every turn; MCP remains available for writes and focused searches (graymatter hooks install) |
| Receipts, not vibes | recall --explain returns why each fact ranked: per-signal ranks, fused score, provenance |
| Knowledge graph | Typed entities and co-mention edges, auto-populated from ordinary use |
| Self-curation | memory_reflect lets the agent add, update, forget, and link its own memories |
| Context block | Projects top facts into CLAUDE.md / AGENTS.md inside a token budget (context-sync) |
| Free auditor | doctor --audit measures tokens, duplicates, staleness, and marker conflicts in any instruction file |
| Deterministic decay | 30-day half-life; facts fade when nothing touches them. Tombstones, never deletes |
| Single binary | ~10 MB static. No Docker, no Redis, no config files, no cloud accounts |
Install and see it working in under a minute — no API keys, no Ollama:
graymatter init --global still performs that normal setup in the current
directory. It additionally installs the managed memory instructions in Claude
Code and OpenCode's home-scoped instruction files. It does not globalize
project-scoped MCP configs: each repository must be wired separately with
graymatter init or manual client configuration. Codex is the exception in
the table below because its MCP config is already home-scoped.
graymatter demo seeds a scratch store, runs consolidation, and opens the
TUI — then graymatter kg render --out kg-graph.html shows the graph it
built. Restart your editor. Seven memory tools are live.
graymatter init auto-wires every supported client at once. Existing entries
from other MCP servers are merged, never overwritten.
| Client | Config file | Scope |
|---|---|---|
| Claude Code | .mcp.json | project |
| Cursor | .cursor/mcp.json | project |
| Codex (OpenAI) | ~/.codex/config.toml | home |
| OpenCode | opencode.jsonc | project |
| Antigravity (Google) | mcp_config.json | opt-in |
| Windsurf | .windsurf/mcp.json | project |
| VS Code Copilot Agent | .vscode/mcp.json | project |
Also works out of the box: Pi (reads .mcp.json natively), Zed, Cline,
and any MCP-compatible client — point them at graymatter mcp serve.
Per-client verified configs for 25 clients, including the ones that need a
different shape (VS Code's servers key, Codex TOML, Zed's
context_servers), live in docs/integrations.md.
See docs/AGENTS.md for tool parameters and query patterns.
Numbers produced by go run ./benchmarks/token_count — real Recall calls,
keyword embedder, no LLM required:
| Sessions | Full injection | GrayMatter | Reduction |
|---|---|---|---|
| 1 | ~80 tokens | ~80 tokens | 0% |
| 10 | ~630 tokens | ~550 tokens | 12% |
| 30 | ~1,880 tokens | ~550 tokens | 71% |
| 100 | ~6,960 tokens | ~670 tokens | 90% |
Tokens are only half the question. A second benchmark checks whether the returned facts actually answer the query, against a real sliding window:
| sliding window | GrayMatter | + MinRelevance | |
|---|---|---|---|
| Finds a fact planted 96 sessions ago | 0% | 83% | 83% |
| Returns a superseded fact | 0% | 0% | 0% |
| Tokens per query | 95 | 114 | 64 |
At equal fact count, relevance-selected facts cost slightly more tokens than a
window's newest-first picks. With MinRelevance, GrayMatter drops below the
window's cost while keeping full recall of old facts. Method and per-query
detail in benchmarks/RESULTS.md.
Every figure on this page is machine-checked against a live run in CI.
Consolidation is the only "smart" step. Everything else is deterministic.
graymatter hooks install writes the hook block into .claude/settings.json
and after that the hook runner supplies routine recall automatically:
| Hook | What it does |
|---|---|
SessionStart | Injects the freshest live facts plus project-wide __shared__ conventions — and re-injects after /compact (your memory survives compaction) |
UserPromptSubmit | Short per-turn recall (top-3 agent + top-3 shared), suppressed when identical to the previous turn; remember: <text> in a prompt is an instant deterministic save, remember shared: <text> saves into the shared namespace every agent reads |
PreCompact | Deterministic checkpoint before context compaction |
SessionEnd | Checkpoint + detached consolidation (survives the editor closing) |
Hooks and MCP are complementary. Every non-empty hook recall begins with a
bracketed GrayMatter hook recall ran marker naming the namespace it actually
queried. This page never spells that marker out in full, so an agent reading
the docs cannot mistake them for a live recall. The agent reuses
only the newest block available for the session's initial turn. If that ID
matches its own, each non-empty section replaces that scope's startup search.
If the IDs differ, it reruns both project and __shared__ searches because
cross-namespace deduplication may have placed a shared fact in the project
section. Missing sections also fall back to MCP. Focused and batch searches,
writes, corrections, aliases, and checkpoint tools always remain available.
Failure contract: every error exits 0 with empty stdout and a receipt in
<dataDir>/hooks.log — a broken memory degrades silently, it never breaks
the session. graymatter hooks doctor verifies registration, the recorded
binary path, and store latency; the hot path is machine-checked in
benchmarks/hook_latency with hardware-relative
gates — the recall's marginal cost against the same machine's checkpoint
baseline (≤ 200 ms) and in-process scaling (≤ 2.5× of linear at 10k facts) —
because absolute wall-clock numbers on shared CI runners measure the runner
queue, not the code. Reference-hardware figure: p99 121 ms user-prompt on a
10k-fact store, no LLM, localhost only by construction.
graymatter context-sync projects the highest-weight live facts into a managed
block inside CLAUDE.md / AGENTS.md, inside an explicit token budget.
Safety properties:
<file>.bak.Tradeoffs written down rather than left as folklore. Each ADR includes the condition under which it should be reversed.
| # | Decision |
|---|---|
| 001 | Memory decays on a 30-day half-life |
| 002 | bbolt single writer, shared via daemon |
| 003 | The KG write path exists; auto-population is gated — amended by 008 |
| 004 | Local-first single node, deliberately not multi-tenant |
| 005 | Embeddings degrade Ollama → OpenAI → Anthropic → keyword |
| 006 | Signal weights are configurable — a sliding window is the special case |
| 007 | Contradictions resolved by tombstone, never delete |
| 008 | KG auto-population ships gated and measured |
| 009 | init --kg persists activation via sentinel file |
| 010 | Pinned facts are exempt from decay, pruning and summarisation |
| 011 | Consolidation is propose/apply with tombstone receipts; Ollama summarises locally |
| 012 | Tool definitions are engineered against the TDQS rubric and pinned by contract tests |
| 013 | Tool results carry structuredContent twins with declared output schemas |
| Layer | Tech | What it holds |
|---|---|---|
| KV store | bbolt (pure Go, ACID) | Facts, sessions, checkpoints, metadata, KG |
| Vector index | chromem-go (pure Go) | Semantic embeddings, hybrid retrieval |
| Export | Markdown files | Human-readable, git-friendly, Obsidian-compatible |
Single file: .graymatter/gray.db. No migrations. Append-only with decay-based eviction.
GrayMatter degrades gracefully across four modes, always finding a way to work:
| Mode | When |
|---|---|
| Ollama | Local model available |
| OpenAI | OPENAI_API_KEY set |
| Voyage AI | VOYAGE_API_KEY set — Anthropic's recommended embeddings partner (voyage-3, 1024 dims) |
| Keyword-only | Nothing available — TF-IDF + recency, zero deps |
Full suite requires no LLM and no network. Runs clean on Linux, macOS, Windows.
Coverage, measured as the multi-platform union in CI (coverage-union job):
core library ≈ 90%, CLI module ≈ 81%. Gates: core ≥ 82%, CLI ≥ 72%, and they
only ratchet upward. Fuzz targets: FuzzTokenize, FuzzUnmarshalFact,
FuzzKeywordScore, exercised nightly plus a nightly mutation-testing run
whose surviving-mutant report feeds the test-writing queue.
The REST server exposes /metrics behind the bearer token. Library users get
OnRecall, OnPut, and OnVectorIndexError hooks plus a pluggable
VectorBackend interface.
Network surfaces bind loopback-only with bearer auth. Memory is untrusted input: recalled facts are fenced, never concatenated as system prompt. See docs/threat-model.md.
Not tied to any vendor. Not a framework. Not a hosted service. Not a knowledge-base UI. Not trying to win the enterprise memory market.
It is exactly one thing: the missing stateful layer for Go agents, packaged as an MCP server and a library you import in three lines.
Code graphs parse your source tree and expose symbols, call edges, and blast radius. The repo is the source of truth. GrayMatter never reads your source — facts exist only because something deliberately wrote them, and they carry a 30-day half-life that code graphs must never have, since a stale fact means something changed and a stale code graph means nothing did.
Context compressors shrink payloads already moving through the transport. GrayMatter never sees your traffic — the agent writes one distilled sentence and recalls a handful later. Some compressors ship session memory; the difference is scope. They stack.
GrayMatter — v0.19.1 — September 2026