[Bug] OpenCode plugin not auto-loaded: `memorix hooks install` generates local JS file but OpenCode plugin array requires npm package names
Description
memorix hooks install --agent opencode --global generates a local plugin file at ~/.config/opencode/plugins/memorix.js, but OpenCode never loads it. OpenCode's plugin array in opencode.json expects npm package names (e.g., oh-my-openagent, opencode-mem), not local file paths. OpenCode does not auto-scan the plugins/ directory.
Adding "memorix" to the plugin array causes OpenCode to hang for 5+ minutes on startup (it tries to resolve it from npm, and since memorix is a CLI tool, not an OpenCode plugin package, the resolution hangs/times out).
Environment
- OS: Windows 11 (PowerShell)
- OpenCode: v1.4.6 (via
opencode-windows-x64) - Memorix: v1.0.6 (globally installed via npm)
- Node/Bun: OpenCode uses Bun runtime for plugins
Steps to Reproduce
- Install memorix globally:
npm install -g memorix - Run:
memorix hooks install --agent opencode --global - Verify the file was created:
~/.config/opencode/plugins/memorix.jsexists ✅ - Verify hooks status:
memorix hooks statusshows[OK] Opencode✅ - Start OpenCode — the plugin file is never loaded (no
session.createdevents captured) - (Optional) Add
"memorix"toopencode.jsonpluginarray → OpenCode hangs on startup for 5+ minutes
Root Cause Analysis
The installer generates a local JS file at ~/.config/opencode/plugins/memorix.js:
export const MemorixPlugin = async ({ project, client, $, directory, worktree }) => {
// ... hooks into OpenCode events, pipes to `memorix hook`
};
But OpenCode's plugin array expects npm package names. Looking at the source:
// src/hooks/installers/index.ts
function getGlobalConfigPath(agent: AgentName): string {
// ...
case 'opencode':
return path.join(home, '.config', 'opencode', 'plugins', 'memorix.js');
}
The file is written to the plugins directory, but OpenCode's plugin loading only resolves entries from the plugin array as npm packages. The plugins directory is not auto-scanned.
Other agents (Claude, Cursor, Gemini, etc.) use JSON-based hooks configs that are properly merged into the agent's settings file. OpenCode is the only agent that uses a JS plugin file, but the installer doesn't register it in opencode.json.
Expected Behavior
Either:
- The installer should also add the local plugin path to
opencode.json(if OpenCode supports local file references in the plugin array, e.g.,file:///path/to/memorix.jsor./plugins/memorix.js) - Or publish an npm package (e.g.,
memorix-opencode) that re-exports the plugin, so"memorix-opencode"can be added to the plugin array
Current Workaround
Manually call memorix_store via MCP tools in conversations (the AGENTS.md rules prompt the agent to do this). This works but defeats the purpose of automatic capture.
Additional Context
memorix hooks statusreports[OK] Opencodeeven though the plugin isn't loaded — the status check only verifies the file exists, not that OpenCode actually loads it- Formation Pipeline shows "No metrics collected yet" because no hook events are being captured
- Hook traces from manual
memorix hookCLI calls (stdin piping) do get recorded, confirming the backend works — only the OpenCode→memorix bridge is broken
This has been fixed in the 1.0.7 development cycle. The fix involved several changes:
Root cause: The original plugin used an invalid catch-all \event\ handler that OpenCode never called. Additionally, the issue title references \opencode.json\ plugin array but that array is for npm package names only. Local JS plugins in .opencode/plugins/\ are auto-loaded by OpenCode at startup and do NOT need registration in \opencode.json.
What was fixed:
- Plugin now uses individual event-name keys (\session.created, \ile.edited, \command.executed, etc.) instead of the invalid catch-all \event\ handler
- Replaced \Bun.spawn\ with \child_process.spawnSync\ for cross-runtime compatibility (OpenCode may fall back to Node.js on Windows where Bun segfaults)
- Fixed \ile.edited\ field extraction (\input.path\ before \input.file)
- Added exit code and stderr diagnostic logging + 10s timeout to prevent hangs
- Hooks status now distinguishes verified (config-based) vs unverified (plugin-based) agents
- Added generated-version markers so outdated plugin installs are detected and can be reinstalled
How it works now: \memorix hooks install\ (or \memorix integrate) writes .opencode/plugins/memorix.js. OpenCode auto-loads local plugins from that directory no \opencode.json\ registration needed. The \plugin\ array in \opencode.json\ is exclusively for npm packages.
Closing as fixed.