OpenCode Plugin
The OpenCode Mem-Brain plugin gives the assistant persistent memory inside OpenCode. Before every AI turn it searches your memories and injects relevant context automatically. After a successful turn it captures the conversation as a memory. No manual wiring needed.
Install
1. Install the plugin
bunx opencode-membrain@latest install2. Set your credentials (or add to your shell profile)
export MEMBRAIN_API_KEY="mb_live_..."
export MEMBRAIN_API_URL="https://mem-brain-api-cutover-v4-production.up.railway.app"On Windows: use
$env:MEMBRAIN_API_KEY="mb_live_..." and $env:MEMBRAIN_API_URL="https://mem-brain-api-cutover-v4-production.up.railway.app" in PowerShell, or set the same variables in System Properties → Environment Variables. Git Bash / WSL can use the export lines above as-is.3. Restart OpenCode, then initialize memory for the current project
/membrain-initThat's it. The plugin is now active.
/membrain-init stores basic project context (language, framework, repo structure) so future searches return project-aware results out of the box.How it works
- Auto-recall: before each AI turn, the plugin queries your memories with the current conversation context and injects a
[MEMBRAIN CONTEXT]block into the prompt. - Auto-capture: after a successful turn, the last exchange is stored as a memory with scope and temporal tags for reliable retrieval later.
- Container tagging: all plugin-written memories include a
container.<tag>tag so you can search, filter, or wipe them cleanly.
Slash commands
| Command | What it does |
|---|---|
/remember <text> | Manually save something to memory right now |
/recall <query> | Search memories and show results in the chat |
/recall <query> -- interpreted | Search and return an LLM summary instead of raw results |
AI tools
The plugin registers a single membrain tool with multiple modes. Examples:
| Mode | Description |
|---|---|
add | Store a memory; optional ingestionScope (tag regex for merge/link candidates only) |
search | Semantic search; optional keywordFilter or scopeRegex (not both); responseFormat raw | interpreted | both |
traverse | Semantic graph traversal from startMemoryId with a natural-language query |
get / delete / cleanup / stats / help | Batch read, filtered delete, cleanup, statistics, and inline help |
Configuration
Set MEMBRAIN_API_KEY and MEMBRAIN_API_URL (see install above). Optional: ~/.config/opencode/membrain.jsonc with apiKey and apiUrl.
| Variable | Description |
|---|---|
MEMBRAIN_API_KEY | Your mb_live_... API key |
MEMBRAIN_API_URL | Base URL of your Mem-Brain API (must include /api/v1 prefix only if your host requires it — the client appends /api/v1) |