OpenCode Plugin
Automatically saves conversation facts to your persistent memory layer and injects relevant memories as context before the agent answers.
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
-
Message Capture: V1 uses
chat.messageandmessage.part.updated; V2 uses the prompt session hook and thesession.text.endedevent. -
Immediate Save: Each captured message is written to a unique file under
~/.config/audaxic/pending/in milliseconds. Hooks never wait on the network. -
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. -
Crash Safety: A parking file is deleted only after the API confirms receipt. On any failure, the file stays on disk and is retried.
-
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.
-
Silent Failure: If no API key is configured, the plugin logs a warning and disables itself without blocking OpenCode.
Sidebar Indicator
The TUI plugin adds a status block to the session sidebar:
| State | Display |
|---|---|
| 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:
AUDAXIC_API_KEYenvironment variabledirectoryKeysentry matching the OpenCode workspace directory~/.config/audaxic/config.jsongeneralapiKey
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:
- Takes the latest user message (excluding synthetic parts like file-read output)
- Searches your memory via
POST /search(up to 5 results, 8s timeout, 2 attempts) - 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
| Endpoint | Method | Description |
|---|---|---|
https://api.memory.audaxic.com/add | POST | Save conversation messages |
https://api.memory.audaxic.com/search | POST | Search 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
- Verify
@audaxic/memory-opencodeis installed globally - Check
opencode.jsonhas the plugin configured - Restart OpenCode after adding the plugin
Messages not saving
- Verify API key is set:
npx @audaxic/memory-opencode setup - Check
~/.config/audaxic/config.jsonexists and has valid key - Check the
~/.config/audaxic/pending/directory for unsent message files
Sidebar not showing
- Add plugin to
~/.config/opencode/tui.json - Restart OpenCode
Context not being injected
- Verify API key is set and valid at memory-dashboard.audaxic.com
- Check network connectivity to
api.memory.audaxic.com - If
AUDAXIC_SEARCH=offis set, injection is intentionally disabled — unset it to re-enable