Repository navigation
Description
Summary
codebase-memory-mcp install configures OpenCode with only bare MCP server registration and a static AGENTS.md file. Claude Code receives three additional integration layers — a PreToolUse hook that auto-injects graph context during Grep/Glob, a SessionStart reminder hook, and a consolidated skill (codebase-memory) — that make the tool proactive rather than passive. OpenCode has equivalent hook primitives (tool.execute.before, experimental.chat.system.transform, plugin system) but the installer does not wire them up.
This issue requests full feature parity for OpenCode so that codebase-memory-mcp install delivers the same proactive integration depth as Claude Code.
Current State
What Claude Code gets
| Integration | Mechanism | Location |
|---|---|---|
| MCP server | .claude/.mcp.json |
— |
| Consolidated skill | ~/.claude/skills/codebase-memory/SKILL.md |
cbm_install_skills() — quick decision matrix, exploration/tracing workflows, quality analysis, 14 tool reference, Cypher examples, edge types, gotchas |
| PreToolUse hook | settings.json → hooks.PreToolUse with matcher `Grep |
Glob` |
| SessionStart hook | ~/.claude/hooks/cbm-session-reminder |
Injects one-line reminder to prioritize search_graph, trace_path, get_code_snippet, query_graph, get_architecture, search_code over raw grep |
What OpenCode gets today
| Integration | Mechanism | Location |
|---|---|---|
| MCP server | opencode.json |
cbm_upsert_opencode_mcp() |
| Static instructions | ~/.config/opencode/AGENTS.md |
Static file, no dynamic behavior |
| PreToolUse hook | Missing | — |
| SessionStart hook | Missing | — |
| Skill | Missing | — |
The OpenCode install path (cli.c:3094) calls only install_generic_agent_config() with cbm_upsert_opencode_mcp. Compare this to the Claude Code path which additionally calls cbm_install_skills(), cbm_upsert_claude_hooks(), and installs the cbm-session-reminder and cbm-code-discovery-gate shim scripts.
Requested Features
1. Pre-tool hook: tool.execute.before (equivalent to Claude Code PreToolUse)
OpenCode supports a tool.execute.before hook via its plugin system. This should be wired to intercept grep and glob tool calls (never read — same invariant as Claude Code) and inject structured graph context from search_graph as additional context, identical to what the cbm-code-discovery-gate shim does for Claude Code.
Implementation approach:
- Create a small plugin file (e.g.
~/.config/opencode/plugins/cbm-augment.tsor.js) that exports atool.execute.beforehook - The hook inspects the incoming tool name; if it matches
greporglob, extract the search token, call thecodebase-memory-mcpbinary in CLI mode (codebase-memory-mcp cli search_graph '{"name_pattern": "..."}'), and inject results as additional context - Must be non-blocking: all failure paths (binary missing, no indexed project, query timeout) must return silently without preventing the original tool call
- Register the plugin in
opencode.jsonunder the"plugin"key
Reference: Claude Code equivalent is cbm_upsert_claude_hooks() in cli.c which registers the cbm-code-discovery-gate shim under hooks.PreToolUse with matcher "Grep|Glob".
2. Session-start context injection (equivalent to SessionStart hook)
OpenCode supports experimental.chat.system.transform which can modify the system prompt sent to the LLM. This should inject the same codebase-memory reminder that cbm-session-reminder provides for Claude Code — instructing the agent to ALWAYS use codebase-memory-mcp tools first for code exploration, listing the specific tools (search_graph, trace_path, get_code_snippet, query_graph, get_architecture, search_code), and advising grep/glob/read for text/configs/non-code files.
Implementation approach:
- Either via the same plugin file (adding an
experimental.chat.system.transformhook) or via a separate mechanism - The injected text should be the same content as
cbm-session-reminder(the session reminder script content defined incli.c) - Alternatively, this could be folded into the
AGENTS.mdfile dynamically, but the system transform hook is more reliable since it runs on every session regardless of whether the agent reads AGENTS.md
Reference: Claude Code equivalent is cbm-session-reminder script installed to ~/.claude/hooks/ and registered under hooks.SessionStart in settings.json. Codex, Gemini CLI, and Antigravity all get a similar SessionStart reminder — OpenCode is the only hook-capable agent that does not.
3. Skill installation (equivalent to Claude Code codebase-memory skill)
Install the consolidated codebase-memory skill to OpenCode's skills/instructions directory. The skill content is already defined in the skill_content static variable in cli.c and includes:
- Quick Decision Matrix (question to tool mapping)
- Exploration Workflow (list_projects, get_graph_schema, search_graph, get_code_snippet)
- Tracing Workflow (search_graph, trace_path, detect_changes)
- Quality Analysis (dead code, fan-out, fan-in)
- 14 MCP Tools reference
- Edge Types reference
- Cypher query examples
- Gotchas and tips
Implementation approach:
- Install the skill to the appropriate OpenCode location (e.g.
~/.config/opencode/skills/codebase-memory/or wherever OpenCode discovers instruction files) - The skill content (
SKILL.mdwith YAML frontmatter) can be reused as-is from the Claude Code skill — the tool names and workflows are agent-agnostic - Add a call to
cbm_install_skills()(or equivalent) in the OpenCode branch ofinstall_cli_agent_configs()
Reference: Claude Code equivalent is cbm_install_skills() which writes SKILL.md to ~/.claude/skills/codebase-memory/. The old 4-skill layout (codebase-memory-exploring, codebase-memory-tracing, codebase-memory-quality, codebase-memory-reference) was consolidated into a single skill (CBM_SKILL_COUNT = 1).
Proposed Multi-Agent Support Table Update
The README table currently shows:
| Agent | MCP Config | Instructions | Hooks |
|---|---|---|---|
| Claude Code | .claude/.mcp.json |
4 Skills | PreToolUse (Grep/Glob graph augment, non-blocking) |
| OpenCode | opencode.json |
AGENTS.md |
— |
After this change:
| Agent | MCP Config | Instructions | Hooks |
|---|---|---|---|
| Claude Code | .claude/.mcp.json |
1 Skill (codebase-memory) |
PreToolUse (Grep/Glob graph augment, non-blocking) |
| OpenCode | opencode.json |
1 Skill (codebase-memory) + AGENTS.md |
tool.execute.before (grep/glob graph augment, non-blocking) + experimental.chat.system.transform (session reminder) |
Technical Notes
- OpenCode's plugin system loads TypeScript/JavaScript files specified in
opencode.jsonunder the"plugin"key. A plugin exports a function receiving a context object and returns an object with hook implementations. - The
tool.execute.beforehook receives(input, output)whereoutput.argscan be mutated before the tool runs. For graph augmentation, the hook should add context to the tool input or system context, not block the tool. - The
experimental.chat.system.transformhook allows modifying the system prompt — this is the correct place to inject the session-start reminder. - All hooks must be structurally non-blocking (same design principle as Claude Code's
cbm-code-discovery-gatewhich always exits 0). - The
hook-augmentsubcommand of thecodebase-memory-mcpbinary already exists and is agent-agnostic — it takes a search token and returns graph context. The OpenCode plugin can call this directly viaBunShell($) orchild_process.
Uninstall
codebase-memory-mcp uninstall should also remove:
- The plugin file from
~/.config/opencode/plugins/ - The plugin entry from
opencode.json"plugin"array - The skill from the OpenCode skills directory
Environment
- OS: Linux (but should work cross-platform)
- OpenCode: latest, global config
~/.config/opencode/opencode.json - codebase-memory-mcp: v0.8.x
Related
- OpenCode MCP registration: wrong config shape, stale paths, short timeout #437 — OpenCode MCP registration bugs (closed, config shape fixed)
- "install" command does not work for opencode in windows 11 #221 — Windows install broken for OpenCode (open)
- The README claims "11 agents, one command — configures MCP entries, instruction files, and pre-tool hooks for each" but OpenCode does not receive hooks or skills, making this claim inaccurate for OpenCode.
Activity
DeusData commentedon Jun 23, 2026
Thanks for the precise gap analysis — OpenCode is indeed the only hook-capable agent getting bare MCP registration + a static
AGENTS.mdwhile Claude Code / Codex / Gemini CLI / Antigravity all get the proactive layers.Wiring
tool.execute.before(matching grep / glob only, never read, non-blocking on every failure path), the session-start system transform, and the consolidated skill via the installer is the right parity target. Labelingenhancement/editor/integrationand tracking under the integration task #395.This is a well-scoped contribution if you'd like to take it on.
feat: OpenCode feature parity — plugin + skills + hooks
SC-CTS commentedon Aug 18, 2026
In the 0.10.5 install I see an OpenCode extension mentioned:
But the install command does not update
opencode.jsoncto actually reference the plugin.DeusData commentedon Oct 2, 2026
Thanks for the original parity request and the installation follow-up, and sorry this has been waiting.
For the missing
pluginentry: current OpenCode documentation says local files in~/.config/opencode/plugins/load automatically at startup. The missing entry alone therefore does not establish a loading failure. That documentation does not verify the behavior of the OpenCode version used with your 0.10.5 installation.In the current source at 96c3f41, the generated plugin augments results after tool execution and attempts lifecycle context on the first qualifying result and during compaction. This differs from the before-tool handling and session-start system transform originally accepted here. Source inspection alone does not establish that the parity target is complete; the next step remains maintainer validation against a specified OpenCode version and reconciliation with that target.
Also,
0 installedcan mean an existing skill was skipped; it does not necessarily mean the skill is absent. I'm keeping this open, with no additional reporter information required for that maintainer follow-up.DeusData commentedon Oct 19, 2026
Thank you again for the OpenCode integration request. The October response leaves parity validation and reconciliation with the original hook target on the maintainer side. I have no new compatibility result to report, and no additional reporter details are required for that follow-up.
DeusData commentedon Oct 25, 2026
Thank you for your patience. Sorry for the delay. OpenCode parity validation and the original hook target still need maintainer follow-up. I’ll follow up soon.