How it works
The OpenCode plugin (opencode/plugin.ts) listens to key events in your coding workflow:
Captured events
session.created— Registers the session with LongMemchat.message— Captures all assistant responses for future recalltool.execute.after— Records tool usage and outputs (except meta-tools)
Skipped tools
To avoid noise and recursion, LongMem skips capturing these tools:Plugin architecture
The plugin exports aPlugin object with these hooks:
The mem-search tool
LongMem provides a built-in tool for OpenCode that enables the LLM to search past sessions:Operations
search — Full-text search with temporal decay ranking
recent — Get latest observations for current project
get — Retrieve full details by observation IDs
timeline — Show chronological context around an observation
Installation
The OpenCode plugin is automatically installed byinstall.ts when you run:
- Detects your OpenCode installation
- Copies plugin files to
~/.longmem/ - Configures OpenCode to load the plugin
- Starts the LongMem daemon
Manual plugin configuration
If you need to configure the plugin manually, add it to your OpenCode config:Auto-start behavior
The plugin automatically starts the LongMem daemon if it’s not running:Context injection
Unlike some memory systems, LongMem does not auto-inject context into every prompt. Instead:- The LLM uses the
mem-searchtool when it needs context - This prevents chat contamination and token waste
- The LLM decides what’s relevant, not heuristics
Verification
Check that the plugin is working:- Plugin status: Active
- Sessions captured: [number]
- Last observation: [timestamp]