Feature Request: Add Hook Support for OpenCode
Problem Description
Currently, agentmemory supports 12 auto hooks in Claude Code, automatically capturing session context and saving to memory. However, OpenCode only supports MCP server, lacking Hook functionality.
Based on README compatibility:
| Agent | Supported Features |
|---|---|
| Claude Code | 12 hooks + MCP + skills ✅ |
| OpenCode | MCP server only ❌ |
Expected Behavior
OpenCode users should also be able to use Hook functionality:
- PreToolUse / PostToolUse — Capture tool usage events
- OnThinking — Track LLM inference state
- OnChunk — Process streaming chunks
- OnEnd — Auto-summarize and save on session end
Proposed Solutions
- Expose Hook API in OpenCode (Claude Code compatible interface)
- Add Hook integration to agentmemory OpenCode plugin
- Or extend OpenCode MCP to forward Hook events
References
- OpenCode: https://github.com/opencode-ai/opencode
- Claude Code Hooks: https://claude.com/product/claude-code
Thanks for the request. The OpenCode situation is upstream-bound — agentmemory can't run hooks the host agent doesn't fire. Breaking it down:
What's blocked upstream
- OpenCode doesn't expose a Claude-Code-equivalent hook bus today.
PreToolUse,PostToolUse,OnThinking,OnChunk,OnEndhave no OpenCode counterparts we can subscribe to, so there's nothing for an agentmemory-side plugin to receive. - Claude Code's hook API isn't a portable spec; it's a process/stdin contract between the CLI and the plugin, not something OpenCode can adopt without its own implementation.
What we can do on our side today
- MCP tool parity — every observation that a Claude Code hook writes is already reachable via MCP tools + REST. After #159 lands (proxy path merged from @agentmemory/mcp to the running server),
memory_observe,memory_smart_search,memory_sessions, and the graph endpoints are all available from OpenCode's MCP client. - Client-side explicit capture — users drive
memory_save/memory_observemanually for high-value moments. Less ergonomic than auto-hooks but covers the important cases. - REST polling adapter — a tiny daemon that watches OpenCode's session file / log output and emits observations to
/agentmemory/observe. This would live inintegrations/opencode/alongside the other adapters, mirroring the hermes and openclaw patterns.
What needs upstream movement
- Track the OpenCode hook-API discussion in their repo. If/when they ship a hook bus, we wire an
integrations/opencode/hooks.tsthe same way the Claude Code plugin does today.
Happy to take option 3 (REST polling adapter) as a follow-up if someone's willing to share their OpenCode session-log format — that's the piece we'd need to build against.
💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂
Thanks for filing — important call-out. We can't add this from the agentmemory side though: OpenCode doesn't expose a hook API for plugins to register against. The lifecycle events you're referencing (PreToolUse / PostToolUse / OnThinking / OnChunk / OnEnd) only exist as a Claude Code plugin contract.
What agentmemory can offer for OpenCode today:
- MCP server: 51 tools accessible from any OpenCode chat (
memory_save,memory_recall,memory_compress,session_summary, etc.) - REST API: explicit
POST /agentmemory/observefrom any wrapper script you run alongside OpenCode
What unblocks the hook integration:
- OpenCode upstream needs a hook/plugin contract. Worth filing a tracking issue at https://github.com/opencode-ai/opencode referencing the Claude Code hook spec.
- Once that lands, we can ship an integration package (mirroring
integrations/hermesandintegrations/openclaw) that registers against it.
Closing as upstream-blocked — happy to reopen the moment OpenCode ships a hook surface, or if there's an existing extension API I missed (point me at the file?). Filing on the OpenCode side is the lever that moves this.