GBrain: Give Claude a Memory That Wires Itself
An open-source brain layer for AI agents by Garry Tan. It captures what you feed it, links entities automatically, and serves synthesized answers over MCP.
Claude forgets. Close a session and the context is gone, so every new project starts cold and you paste the same background again. GBrain is the fix. It is an open-source knowledge system by Garry Tan that sits underneath your agent as a persistent brain layer, capturing what you tell it and serving it back across sessions and projects. The repo has crossed 23.8k stars, and the production deployment behind it indexes over 146,000 pages, so this is not a toy.
The part that makes it worth your time is the graph. Most memory tools store notes and let you search them. GBrain reads what you capture, pulls out entity references, and builds typed connections between them on its own. Edges like 'works_at', 'founded', 'invested_in', and 'advises' get created with zero LLM calls, which keeps it fast and cheap. The result is a graph that wires itself as your notes grow, instead of a flat pile you have to organize by hand.
Search gives you hits. Think gives you an answer.
GBrain splits retrieval into two moves. 'gbrain search' returns the top pages ranked by a hybrid score that blends vector embeddings, BM25 keyword matching, and source-tier weighting. 'gbrain think' goes further: it synthesizes an answer with citations and tells you where the knowledge is thin through explicit gap analysis. That gap analysis is the honest part. Instead of confidently filling holes, it points at them, which is what you want from a system your agent leans on. On the project's own benchmarks, turning the graph on added 31.4 points to retrieval quality over the graph-disabled version.
Wiring it into Claude Code
For a personal brain on your own machine, GBrain runs entirely local. It defaults to PGLite, a zero-config Postgres 17 compiled to WASM, so there is no separate database server to stand up and no tunnel. Two commands get you a working MCP server that Claude Code can call. The CLI runs on Bun.
gbrain init --pglite
claude mcp add gbrain -- gbrain servebun install -g github:garrytan/gbrain
gbrain init --pglite
gbrain doctor
gbrain import ~/notes/
gbrain query "what themes show up across my notes?"Feeding and asking the brain
Capture is flexible. You can write a thought inline, point it at a file, or pipe text straight in. Querying is where the two-tier design pays off: reach for 'search' when you want sources, and 'think' when you want a synthesized answer over them.
- 1Capture a quick thought: gbrain capture "the thought I want to remember"
- 2Capture a file: gbrain capture --file ./notes/today.md
- 3Pipe from anything: echo "from a pipe" | gbrain capture --stdin
- 4Pull sources: gbrain search "who's working on AI agents at portfolio companies?"
- 5Get a synthesized, cited answer: gbrain think "who's working on AI agents at portfolio companies?"
When to reach for it, and what to watch
- Best fit: a personal or team knowledge base that you query across many projects, where you want answers with citations rather than a list of links.
- PGLite is tuned for personal brains up to roughly 50,000 pages. Past that, or for shared access, move to Postgres with pgvector (Supabase or self-hosted).
- It needs API keys for an embedding provider and an LLM. The graph edges are free of LLM calls, but synthesis and embeddings are not, so plan for that cost.
- The CLI runs on Bun, so install that first. Server and team deployments add OAuth, an admin dashboard, and scoped access if you outgrow the local setup.
- It is MIT licensed and exposes 30+ tools over MCP, with clients including Claude Code, Codex, Cursor, and Claude Desktop. Credit and thanks to Garry Tan for shipping it open source at github.com/garrytan/gbrain.
Want the next drop first?
New builds and skills land in the Vault every week.
Follow for the weekly drops