Skip to content

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

@cl0ckt0wer

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

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