OpenCode

March 26, 2026 · View on GitHub

OpenCode has full MCP support and a plugin system that enables automatic memory recall and storage via lifecycle hooks, plus 16 built-in memory tools.

Integration Options

MethodWhat it doesSetup effort
Plugin (recommended)Automatic recall/remember + 16 built-in tools. No MCP needed.Install npm package
MCP onlyLLM-driven memory via MCP tool callsAdd MCP config

The plugin handles everything automatically — memory recall, per-turn search, and storage. It also registers 16 memory tools for explicit operations (search, add, update, delete, artifacts).

Install from npm

Add to your opencode.json (project) or ~/.config/opencode/opencode.json (global):

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["@fpytloun/opencode-mnemory"]
}

Set environment variables:

export MNEMORY_URL=http://localhost:8050
export MNEMORY_API_KEY=your-api-key  # if auth is enabled

Install from local files

# Global (recommended)
cp integrations/opencode/*.ts ~/.config/opencode/plugins/

# Or project-level
cp integrations/opencode/*.ts .opencode/plugins/

How the Plugin Works

PhaseHookAction
Session startsession.createdPre-fetches core memories and instructions (non-blocking)
Each user messagechat.messageStarts semantic search with user's query (non-blocking)
Before each LLM callexperimental.chat.system.transformInjects instructions + core memories + search results into system prompt
After each exchangesession.idleSends last exchange to mnemory for memory extraction (fire-and-forget)
On compactionexperimental.session.compactingPreserves core memories across context window compaction
After compactionsession.compactedResets state and re-fetches memories

Configuration

All configuration is via environment variables. See integrations/opencode/README.md for the full list.

Key variables:

VariableDefaultDescription
MNEMORY_URLhttp://localhost:8050Mnemory server URL
MNEMORY_API_KEY(empty)Bearer token for authentication
MNEMORY_AGENT_IDopencodeAgent ID sent to mnemory
MNEMORY_MANAGEDtrueInclude behavioral instructions in system prompt
MNEMORY_FIND_FIRSTtrueUse AI-powered search on first turn

MCP Setup (Alternative)

If you prefer MCP-only (without the plugin), add to your opencode.json:

{
  "mcp": {
    "mnemory": {
      "type": "remote",
      "url": "http://localhost:8050/mcp",
      "headers": {
        "Authorization": "Bearer your-api-key",
        "X-Agent-Id": "opencode"
      }
    }
  }
}

Note: With MCP-only, memory recall and storage are LLM-driven (the LLM must call tools explicitly). The plugin approach is recommended for automatic recall/remember.

Tips

  • The plugin registers 16 memory tools — no separate MCP config needed
  • Memory persists across session compaction
  • First turn uses AI-powered search for higher quality results; subsequent turns use fast vector search
  • If the mnemory server is offline, the plugin degrades gracefully — the LLM works normally without memory context