agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

Feature Request: Add Hook Support for OpenCode

Open downwind7clawd-ctrl opened this issue 7 months ago • 3 comments

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:

  1. PreToolUse / PostToolUse — Capture tool usage events
  2. OnThinking — Track LLM inference state
  3. OnChunk — Process streaming chunks
  4. OnEnd — Auto-summarize and save on session end

Proposed Solutions

  1. Expose Hook API in OpenCode (Claude Code compatible interface)
  2. Add Hook integration to agentmemory OpenCode plugin
  3. 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

downwind7clawd-ctrl avatar Apr 17 '26 04:04 downwind7clawd-ctrl

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, OnEnd have 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

  1. 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.
  2. Client-side explicit capture — users drive memory_save / memory_observe manually for high-value moments. Less ergonomic than auto-hooks but covers the important cases.
  3. REST polling adapter — a tiny daemon that watches OpenCode's session file / log output and emits observations to /agentmemory/observe. This would live in integrations/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.ts the 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.

rohitg00 avatar Apr 18 '26 10:04 rohitg00

💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂

MaiHHConnect avatar Apr 19 '26 00:04 MaiHHConnect

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/observe from any wrapper script you run alongside OpenCode

What unblocks the hook integration:

  1. 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.
  2. Once that lands, we can ship an integration package (mirroring integrations/hermes and integrations/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.

rohitg00 avatar Apr 26 '26 23:04 rohitg00