Skip to main content

OpenCode Plugin

Automatically saves conversation facts to your persistent memory layer and injects relevant memories as context before the agent answers.

← Back to MCP Setup


Installation​

npm install -g @audaxic/memory-opencode

Setup​

Before using the plugin, configure your API key:

npx @audaxic/memory-opencode setup

This will prompt you for your Audaxic general API key and save it to ~/.config/audaxic/config.json with secure file permissions (600). It also offers to save a separate key for the current project directory.

Get your API key from: memory-dashboard.audaxic.com


Configuration​

Server plugin​

Add to your opencode.json:

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

TUI plugin (sidebar indicator + toast)​

Add to your ~/.config/opencode/tui.json:

{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["@audaxic/memory-opencode"]
}

The plugin will be automatically loaded by OpenCode on startup.


How It Works​

  1. Message Capture: V1 uses chat.message and message.part.updated; V2 uses the prompt session hook and the session.text.ended event.

  2. Immediate Save: Each captured message is written to a unique file under ~/.config/audaxic/pending/ in milliseconds. Hooks never wait on the network.

  3. Background Send: A background sender posts files to POST /add (30s timeout, 3 concurrent). Messages larger than the API's 15,000-character limit are split at newline boundaries.

  4. Crash Safety: A parking file is deleted only after the API confirms receipt. On any failure, the file stays on disk and is retried.

  5. Recovery and Parallel Safety: A periodic tick and a startup scan retry files older than 60 seconds. Files are claimed atomically, abandoned claims are healed after 5 minutes, and multiple sessions never share a parking file.

  6. Silent Failure: If no API key is configured, the plugin logs a warning and disables itself without blocking OpenCode.


The TUI plugin adds a status block to the session sidebar:

StateDisplay
Idle● Audaxic Memory / listening
Saved● Audaxic Memory / saved (brief, after each message)
Searching● Audaxic Memory / retrieving...
Retrieved● Audaxic Memory / retrieved 3 memories (brief)
Error● Audaxic Memory / last save failed (yellow)

The indicator updates every 2 seconds by polling the server's status file.


Environment Variable Alternative​

Instead of using the setup script, you can set the API key as an environment variable:

export AUDAXIC_API_KEY="ak_your_key_here"

The plugin checks in this order:

  1. AUDAXIC_API_KEY environment variable
  2. directoryKeys entry matching the OpenCode workspace directory
  3. ~/.config/audaxic/config.json general apiKey

Directory-specific API keys​

Give each project its own memory project by mapping a directory to an API key:

npx @audaxic/memory-opencode key set --global
cd C:\projeler\my-project
npx @audaxic/memory-opencode key set
npx @audaxic/memory-opencode key list
npx @audaxic/memory-opencode key resolve

The shared config:

{
"apiKey": "ak_general...",
"directoryKeys": {
"C:\\projeler\\my-project": "ak_project_a...",
"C:\\projeler\\another-project": "ak_project_b..."
}
}

Matching uses the nearest parent directory. Git worktrees fall back to the main checkout's key. The config is stored with mode 0600; keys never go into a repository. In OpenCode v2 one background service can serve multiple workspaces, so the plugin resolves the key per workspace and stores the key with every parked message. A message captured in workspace A is always sent to A's project.

See Directory-Specific API Keys for the full precedence, worktree behavior, and parallel-session rules.


Memory Search & Context Injection​

After a user prompt is received and before the agent answers, the plugin:

  1. Takes the latest user message (excluding synthetic parts like file-read output)
  2. Searches your memory via POST /search (up to 5 results, 8s timeout, 2 attempts)
  3. Injects the results as a synthetic user message wrapped in <audaxic_memory_context>...</audaxic_memory_context> into the model request

The injection is:

  • In-memory only — never persists to the session, so it won't appear in conversation history or the TUI
  • Once per user message — subsequent agent loop steps (tool calls, etc.) reuse the already-injected context instead of re-searching
  • Silent on failure — if the search API is unreachable, the plugin logs a warning and the conversation proceeds without context

To disable auto-search/injection (saving still works):

export AUDAXIC_SEARCH=off

Architecture​

OpenCode session
|
|-- prompt / assistant text
| -> pending/<timestamp>-<random>.json (one file per message, mode 0600)
| -> background POST /add
| -> success: delete the file
| -> failure: keep the file and retry after 60s
|
|-- before each model request
-> POST /search
-> inject <audaxic_memory_context> into the request (in-memory only)

API Endpoints​

EndpointMethodDescription
https://api.memory.audaxic.com/addPOSTSave conversation messages
https://api.memory.audaxic.com/searchPOSTSearch memories for context injection

Troubleshooting​

Server plugin fails with a directory error​

Use @audaxic/[email protected] or newer. Version 1.4.0 assumed ctx.directory was a string; OpenCode v2 provides ctx.location.directory. Update the plugin pin in opencode.json/tui.json and restart OpenCode.

Directory key is not being used​

npx @audaxic/memory-opencode key resolve

If it shows the general key, add a mapping for the workspace directory or a parent. If it shows the environment override, unset AUDAXIC_API_KEY for that process.

Plugin not loading​

  1. Verify @audaxic/memory-opencode is installed globally
  2. Check opencode.json has the plugin configured
  3. Restart OpenCode after adding the plugin

Messages not saving​

  1. Verify API key is set: npx @audaxic/memory-opencode setup
  2. Check ~/.config/audaxic/config.json exists and has valid key
  3. Check the ~/.config/audaxic/pending/ directory for unsent message files
  1. Add plugin to ~/.config/opencode/tui.json
  2. Restart OpenCode

Context not being injected​

  1. Verify API key is set and valid at memory-dashboard.audaxic.com
  2. Check network connectivity to api.memory.audaxic.com
  3. If AUDAXIC_SEARCH=off is set, injection is intentionally disabled — unset it to re-enable