Deploy GBrain: Self-Hosted Agent Memory for Claude Code & Codex

Give Claude Code, Codex and ChatGPT one shared memory over MCP.

Deploy GBrain: Self-Hosted Agent Memory for Claude Code & Codex

Just deployed

/var/lib/postgresql/data

Deploy and Host GBrain on Railway

GBrain logo

GBrain is an open source memory and knowledge base for AI agents, created by Garry Tan. It stores your notes and your company's docs as pages for people, companies, projects and ideas, links them into a knowledge graph, and gives agents hybrid keyword and semantic search over all of it through MCP. Claude Code, Codex, ChatGPT, Claude Desktop, Cursor and other MCP clients check the brain before they answer, and anything you ask one agent to remember is available to the others in the next session. GBrain is MIT licensed with about 33,400 GitHub stars and ships new releases many times a week; this template builds GBrain 0.60.311.0 on Postgres with pgvector, with its HTTP MCP server, OAuth 2.1, an admin dashboard and a background jobs worker. Hosted memory services usually charge per request or per seat. GBrain on Railway costs about $5–15/month, plus any embedding or model usage you choose to add.


What This Template Deploys

ServicePurpose
GBrainBuilt from a small Dockerfile that installs the tagged GBrain release with Bun. Runs the HTTP MCP server on port 8080 with a public domain, the admin dashboard, and the jobs worker. Volume at /data for config, logs and the brain's Markdown folder, kept as a git repository. Health check on /health.
Postgrespgvector/pgvector:pg17, private only. Stores pages, links, embeddings and the job queue.

On first start the service creates the brain on Postgres and applies migrations. Later starts run any pending migrations and then serve.


About Hosting GBrain

Coding agents forget everything between sessions, and each tool keeps its own small memory. GBrain gives them one shared, searchable memory that you own. Running it on a server instead of your laptop means every machine and every hosted assistant can reach the same brain.

One brain for every agent. Claude Code, Codex, ChatGPT, Claude Desktop and other MCP clients read and write the same pages.

Pages and a knowledge graph. Notes about people, companies, meetings and decisions are linked, so agents can follow relationships instead of guessing.

Hybrid search. Keyword search works with no API keys. Add an embedding key and GBrain adds semantic search and reranking.

Remote MCP with OAuth. The HTTP MCP server supports OAuth 2.1, so hosted clients such as ChatGPT and Claude Desktop can connect securely.

Admin dashboard. Manage clients, tokens and settings from a web dashboard, signed in with an owner token.

Background jobs. A worker handles embedding, syncing and extraction jobs. Autopilot mode adds a maintenance cycle that tidies and enriches the brain.

Markdown you own. The brain's content is kept as Markdown files in a git repository on the volume, alongside the database index.


Deploy GBrain in Under 5 Minutes

  1. Click Deploy on Railway. Optionally add VOYAGE_API_KEY, OPENAI_API_KEY or OPENROUTER_API_KEY for semantic search.
  2. Wait for the health check to pass; the first boot creates the brain and its tables.
  3. Open GBRAIN_ADMIN_URL and sign in with GBRAIN_ADMIN_BOOTSTRAP_TOKEN from the service variables.
  4. Add GBRAIN_MCP_URL as a remote MCP server in Claude Code, Codex, ChatGPT or Claude Desktop and approve the OAuth prompt.
  5. Ask your agent to remember something, then recall it from another agent to confirm the shared memory works.

Common Use Cases

  • Shared memory for coding agents: Claude Code and Codex remember project decisions across sessions and machines.
  • Company knowledge for AI: give agents your facts page, decisions log and docs before they answer.
  • Personal second brain: keep notes on people, companies and ideas that every assistant can search.
  • Meeting and call notes: store transcripts so agents can answer "what did we decide, and why?"
  • Founder and investor research: track companies and people with linked pages.
  • Team onboarding: let new teammates ask agents questions answered from written history.
  • Multi-device workflows: one brain reachable from your laptop, desktop and hosted chat apps.

Configuration

VariableDefaultDescription
GBRAIN_ADMIN_BOOTSTRAP_TOKEN🔐 Auto-generatedOwner credential for the admin dashboard; keep it private
GBRAIN_PUBLIC_URLRailway domainPublic URL and OAuth issuer; change it if you add a custom domain
GBRAIN_MCP_URLdomain plus /mcpMCP endpoint to give your AI clients
GBRAIN_ADMIN_URLdomain plus /adminAdmin dashboard address
GBRAIN_DATABASE_URLprivate Postgres URLPostgres with pgvector
VOYAGE_API_KEYemptyOptional; GBrain's default embeddings and reranker
OPENAI_API_KEYemptyOptional; embeddings and chat features
OPENROUTER_API_KEYemptyOptional; embeddings and chat through OpenRouter
ANTHROPIC_API_KEYemptyOptional; chat features such as fact extraction and query expansion
GBRAIN_MODELemptyOptional chat model as provider:model
GBRAIN_AUTOPILOTfalsetrue runs autopilot, which also spends model tokens
GBRAIN_HTTP_CORS_ORIGINclaude.ai, chatgpt.comBrowser origins allowed for the OAuth handshake
GBRAIN_HTTP_TRUST_PROXY1Trusts Railway's proxy for client IPs and HTTPS

Search quality. Without a key, search is keyword-only. Adding one embedding key turns on semantic search for new and existing pages as the worker processes them.

Costs of model features. Embeddings and chat features are billed by the provider you choose. Leave autopilot off until you want the maintenance cycle.

Custom domain. Add it to the GBrain service, then update GBRAIN_PUBLIC_URL so OAuth issues tokens for the new address, and reconnect your clients.

Upgrades. The image builds a pinned GBrain tag, 0.60.311.0. Newer releases are available; change the tag in a fork of the Dockerfile to upgrade, and migrations run on the next start.

Backups. Back up Postgres and the /data volume together, since pages live in both the database and the Markdown repository.


Getting Good Results from Your Brain

Start with a few key pages. A short facts page with numbers agents may repeat, and a decisions log with the date and reason for each decision, answer most everyday questions.

Tell agents the brain exists. Agents rarely call an MCP server nobody mentioned. GBrain's setup commands add a short brain-first instruction to Claude Code and Codex; add a similar line to other clients' instructions.

Write things down as you go. Ask your agent to remember decisions, preferences and context at the end of a session, so the next session starts from them.

Link people and companies. Mention people and companies by name on meeting and project pages so the knowledge graph connects them.

Add an embedding key when search feels literal. Keyword search finds exact words; semantic search finds related ideas phrased differently.

Review now and then. Skim recent pages in the admin dashboard to remove outdated facts before agents repeat them.


GBrain vs. Alternatives

FeatureGBrain on RailwayMem0ZepLetta
HostingSelf-hostedHosted or self-hostedHostedHosted or self-hosted
LicenseMITApache-2.0Proprietary serviceApache-2.0
MCP server✅✅VariesVaries
Knowledge graph✅Graph option✅❌
Works without API keys✅ keyword search❌❌❌
Markdown files you own✅❌❌❌
PriceAbout $5–15/month plus usageFree tier, then paidPaid plansFree tier, then paid

Mem0 and Zep are memory layers aimed at apps you build. Letta is a framework for stateful agents. GBrain is a ready-made brain for the agents you already use, with your content in Markdown.


Dependencies for GBrain Hosting

  • A Railway account.
  • Optional: an embedding or model API key.

Deployment Dependencies

Implementation Details

The start script runs as an unprivileged user, initializes the brain once, applies migrations on every start, keeps the jobs worker running in a restart loop, and then starts the HTTP server.


Frequently Asked Questions

What is GBrain? An MIT-licensed open source memory and knowledge base for AI agents, served over MCP.

How much does it cost to host? About $5–15/month on Railway, plus any embedding or model usage you add.

Do I need an API key? No. Keyword search works without one; add a key for semantic search.

How do I connect Claude Code or ChatGPT? Add GBRAIN_MCP_URL as a remote MCP server in the client and approve the OAuth sign-in.

How do I reach the admin dashboard? Open GBRAIN_ADMIN_URL and sign in with GBRAIN_ADMIN_BOOTSTRAP_TOKEN.

Is this the hosted gbrain.io service? No. It is the open source GBrain running in your own Railway project.


Why Deploy and Host GBrain on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying GBrain on Railway, you get one shared memory for all your AI agents, with your knowledge on your own database and volume.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
Weaviate
Vector database with hybrid search and an API key-protected API

GitHub Locker
1
View Template
Möbius Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

Tracklayer
1