Skip to content

OpenCode: reimplemented Claude Code hooks/plugin as OpenCode plugin + skill + commands #236

Closed

Description

@cl0ckt0wer

Summary

Reimplemented agentmemory's 12 Claude Code hooks + 4 skills as an OpenCode plugin, skill, and commands. This gives non-Claude-Code users the auto-capture pipeline: tool calls → observations, session lifecycle, compaction memory injection, and manual recall/remember commands.

What was built

1. OpenCode Plugin (~/.config/opencode/plugins/agentmemory-capture.ts)

Claude hook OpenCode hook agentmemory API
SessionStart session.created POST /session/start
Stop session.idle POST /summarize
SessionEnd session.deleted POST /session/end
PostToolUse tool.execute.after POST /observe
PostToolUseFailure session.error POST /observe
UserPromptSubmit message.updated (user role) POST /observe
PreCompact experimental.session.compacting GET /context → output.context

2. Session Recall Skill

Updated skills/agentmemory-setup/SKILL.md to instruct the agent to call memory_smart_search and memory_lessons_recall at session start, with example queries.

3. Commands

Created .opencode/commands/recall.md and remember.md — wrap memory_smart_search and memory_save MCP tools with usage guidance.

Gaps (not yet implemented)

Claude feature Reason
PreToolUse (file enrichment) OpenCode tool.execute.before doesn't have stdout→context pipe; also disabled by default (#143)
SubagentStart/Stop OpenCode Task tool lifecycle not exposable via plugin events
Notification / TaskCompleted Claude-specific events with no OpenCode equivalent
Claude Memory Bridge (MEMORY.md sync) OpenCode uses AGENTS.md; could be implemented as a skill
/forget and /session-history commands Lower priority; can add later

PreCompact implementation detail

OpenCode's experimental.session.compacting hook has output.context: string[] — this maps directly to Claude's PreCompact stdout injection. The plugin calls GET /agentmemory/context and pushes the result into output.context.

Plugin registration

{ "plugin": ["./plugins/agentmemory-capture.ts"] }

Environment

  • agentmemory: v0.9.4 (Docker, iii-engine 0.11.6)
  • OpenCode + @opencode-ai/plugin v1.1.25
  • Full stack: Ollama embeddings + OpenRouter LLM + HTTP→stdio MCP bridge

Activity

  1. rohitg00 commented on May 8, 2026

    @rohitg00
    Owner

    Thanks @cl0ckt0wer — comprehensive writeup, the per-hook mapping table is exactly the kind of compatibility audit we need for every new agent surface.

    This is being implemented in:

    I've asked over there to consolidate the two PRs into one (they touch the same files), but either way this issue gets fully addressed.

    Re your "Gaps (not yet implemented)" table — those are tracked separately:

    Holding open until #237 + #239 land. Once they do, will close as fixed-by-#237/#239 with full credit to your audit work here.

  2. added a commit that references this issue on May 19, 2026
    68fddd4
  3. added a commit that references this issue on Jul 27, 2026
    23a979e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions