A Step-by-Step Coding Tutorial to Implement GBrain: The Self-Wiring Memory Layer Built by Y Combinator’s Garry Tan for AI Agents
GBrain, an open-source memory layer built by Garry Tan, President and CEO of Y Combinator, helps AI agents remember past interactions and learn from experience.

Your AI agent is smart, but it's also forgetful. Every time you start a new session, it's like starting from scratch - no memory of who you met, what you read, or what you decided last week. But what if your AI agent could remember and learn from its past experiences?
That's where GBrain comes in. GBrain is an open-source, markdown-first, Postgres-backed knowledge layer that helps AI agents ingest meetings, emails, tweets, and notes, and then auto-wires a typed knowledge graph on top. It was built by Garry Tan, President and CEO of Y Combinator, to power his own OpenClaw and Hermes deployments.
The production brain behind Garry's actual agents currently holds 146,646 pages, 24,585 people, 5,339 companies, and 66 autonomous cron jobs. In this hands-on tutorial, we'll walk through how to install GBrain locally, import a small notes folder, run a real search, watch the knowledge graph wire itself, and connect it to Claude Code via MCP. The entire process should take about 20 minutes.
First, you'll need to install GBrain. As of v0.38, the canonical install path is a single global Bun install: gbrain init --pglite provisions a local PGLite database in ~/.gbrain/. PGLite is full Postgres compiled to WASM - no server, no Docker, ready in roughly two seconds.
For this tutorial, we'll defer the embedding provider so you can follow along without an API key right away. We'll wire it up in Step 6 when we run hybrid search. The brain repo is just a directory of markdown files.
Each file follows GBrain's compiled truth + timeline pattern: a current best-understanding section on top, an append-only evidence trail below. When importing files, make sure to use full slug paths for wikilinks (e.g., [[people/alice-chen]], not just [[alice-chen]]) for the graph extractor to resolve them. GBrain ships two search verbs.
gbrain search is keyword-only (BM25 on Postgres tsvector) and works without embeddings: gbrain query is the full hybrid pipeline: vector (HNSW on pgvector) + BM25 + Reciprocal Rank Fusion + optional multi-query expansion (Anthropic Haiku) + an optional ZeroEntropy reranker. It needs embeddings, which we deferred in Step 2. The brain is more useful when an AI agent can read and write to it directly.
GBrain exposes 74 tools over the Model Context Protocol via stdio. The canonical setup is one command (not a hand-edited JSON file): Now you can ask Claude Code something like 'search the brain for inference optimization' and it'll route through the search tool and return your indexed results.
Source: MarkTechPost