Skip to main content

Give your coding agent a memory: ModusBrain + Claude Code / Codex

Coding agents got very good at code. They’re still amnesiac about everything else. Claude Code and Codex forget your last conversation, can’t tell you what you decided three meetings ago, and re-derive context you already have written down somewhere. ModusBrain is the retrieval layer that fixes that: search, synthesis, and a self-wiring knowledge graph, wired into your agent over MCP. There are two ways to do this. Pick the one that matches where you are:
  • Path A — I already run a brain (OpenClaw, Hermes, or any modusbrain serve host) and I want my Claude Code / Codex to reach the same brain. → jump to Path A
  • Path B — I have nothing yet. Spin up a local brain in 2 seconds and wire it into my coding agent. → jump to Path B
Both end in the same place: an agent that searches your brain before it answers, and writes new knowledge back as you work. The last section, Now make it actually useful, is the same for both and is the part that changes how you work. Prerequisite for either path: bun install -g github:thebuildceo/modusbrain.

Path A: connect an agent to a brain you already have

You already have a populated brain (the OpenClaw / Hermes case: it’s on your agent host, full of meetings, people, and ideas). You want Claude Code on your laptop, and Codex too, to query it. This is the remote path: the host serves HTTP, your laptop agents connect with a token.

A1. On the host: serve over HTTP

If your host isn’t already serving HTTP MCP, start it:
Two flags matter and people skip them:
  • --bind 0.0.0.0 — the default bind is 127.0.0.1 (loopback only), which silently refuses every remote connection. If your agent “can’t reach the brain” and you didn’t pass this, that’s why. modusbrain serve --http warns you at startup when --public-url is set without --bind.
  • --public-url — the externally reachable HTTPS URL (your Render/Railway URL, ngrok domain, Tailscale Funnel, etc.). It’s the issuer the OAuth/MCP layer advertises.
Watch the startup banner. It now prints a Skills: line:
If it says not published, your connected agents will be able to search and write but won’t see your skill catalog (the OpenClaw skills that make your setup special). Turn it on:
(New brains from modusbrain init default this ON. Brains upgraded from before v0.41.36 stay OFF until you opt in, so this is the common gotcha for existing OpenClaw users.)

A2. On the host: mint a token

Copy the modusbrain_… token it prints. It’s a long-lived, full-access secret. Treat it like a password; prefer a scoped OAuth client for anything cloud-hosted (see DEPLOY.md).

A3. On the laptop: one command per agent

--install runs the agent’s mcp add for you AND smoke-tests the token: it actually calls get_brain_identity before handing off, so a wrong or expired token fails right now, not silently on the agent’s first request. You’ll see:
Drop --install to print a paste-ready block instead (useful when the host and the agent are different machines, or you want to read before you run). Codex reads the bearer from $MODUSBRAIN_REMOTE_TOKEN at runtime, so the token never lands in Codex’s config file. Keep that variable exported in your shell profile.

A4. Verify

In the agent: “Call get_brain_identity, then search my brain for [a topic you know is in there].” You should get your own pages back. Done. Full per-client detail: Claude Code, Codex, Perplexity.

Path B: start from nothing (local brain, local agent)

No OpenClaw, no server, no token. The lowest-friction path in the whole product: a local PGLite brain in the same process your agent spawns. Zero server, zero tunnel.

B1. Create a local brain

B2. Put something in it

A brain with nothing in it answers nothing, so an empty brain on day one feels broken. Two ways to fill it:
You don’t have to import everything up front. The capture-as-you-go habit (see the next section) means the brain fills with the decisions and context you generate while working, and is genuinely useful by day two.

B3. Wire it into your coding agent

That’s the whole wire-up. No token, no URL, no tunnel. The agent spawns modusbrain serve as a stdio subprocess and talks to your local brain directly.

B4. Verify

In the agent: “search my brain for PGLite” (or whatever you just captured). You get the page back. The same brain is now query-able from the CLI (modusbrain query "...") and from your agent.

Now make it actually useful

Connecting is the easy part. The value comes from teaching your agent a few habits. These are the patterns that turn a coding agent into a knowledge-aware one. Paste the protocol below into your agent’s instructions file (CLAUDE.md for Claude Code, AGENTS.md for Codex / Cursor / others), then lean on the patterns.

The brain-first protocol (paste this in)

The four patterns worth stealing

These come straight from a production OpenClaw setup. They translate directly to any coding agent with ModusBrain connected: 1. Brain-first lookup (never ask what you can retrieve). The single highest- value habit. Before the agent asks you “which repo?” or “who owns this?”, it searches. Try: “What did we decide about the auth rewrite?” and watch it pull the decision page instead of asking you to re-explain. 2. Ambient capture (your brain as a side effect of working). Don’t make saving a separate chore. Tell the agent: “As we work, capture any decision or new idea to the brain without interrupting.” After a month of this, you have hundreds of linked pages and patterns you didn’t know were there. 3. Briefing from your brain (not from the internet). “What do I need to know before my 2pm with the Acme team?” pulls your meeting history, the people, what’s still open, what the brain doesn’t know yet. The agent does your prep because it read your context. (query gives you the synthesized answer with citations; this is the example on the README.) 4. whoknows (expertise routing). “Who do I know who’s shipped a rate limiter in Postgres?” The find_experts tool ranks people in your brain by relevance + recency. Useful the moment your brain has more than a handful of people in it. That’s the spine of it. Two commands to connect, one protocol to paste, four habits to build. Your agent stops being amnesiac.

Troubleshooting

Next steps