Skip to content

Plugin hook parity with Claude Code lifecycle events (7 gaps) #50133

Closed as not planned

Description

@RayLuxembourg

Plugin hook parity with Claude Code's lifecycle events

I'm a plugin author (opencode plugin driving a knowledge-base lifecycle: capture on stop, retrieval on prompt, tooling-finding harvest on subagent stop). Mapping Claude Code's 33 documented hook events (https://code.claude.com/docs/en/hooks) against the opencode plugin API, most of the core loop ports cleanly — thank you. The gaps below are all cases where the information exists inside opencode but no plugin surface exposes it. One consolidated issue rather than seven; happy to split if you prefer.

What already ports (for context)

SessionStart→chat.system.transform, UserPromptSubmit→chat.message, PreToolUse→tool.execute.before (throw=block works), PostToolUse→tool.execute.after, SubagentStart/Stop→task before/after, Stop→session.idle, PreCompact→session.compacting, SessionEnd→session.deleted, StopFailure→session.error, PostCompact→session.compacted.

The gaps

  1. PostToolUseFailure has no documented signal. tool.execute.after receives {title, output, metadata} — but nothing says whether it fires when the tool call fails, or how a failure surfaces in that payload. A documented error/status field (or a dedicated hook) would let plugins react to failures vs successes differently.
  2. No PostToolBatch. Parallel tool calls resolving as a batch is invisible; plugins see N individual afters with no grouping.
  3. Notifications are send-only. Plugins can push tui.toast, but there is no event for receiving notification-worthy moments (permission prompts, idle) the way Claude's Notification event provides.
  4. No CwdChanged / DirectoryAdded. Session cwd tracking is invisible to plugins. Concrete cost: path-scoped guards (e.g. "refuse broad git add only inside repo X") cannot be written safely.
  5. No PreModelSwitch / PostModelSwitch. Model changes mid-session are invisible.
  6. Tool hooks carry no cwd. tool.execute.before/after input is {tool, sessionID, callID} (+args on output for before). Without cwd, any guard that should only fire in one project must match on command text, which is fragile. This is the single highest-value addition for guard authors.
  7. No per-agent hooks. Claude lets subagent/skill frontmatter declare hooks that live only while that agent runs. In opencode every enforcement must live in the global plugin with manual agent-name matching.

Environment

opencode with @opencode-ai/plugin + @opencode-ai/sdk (types as installed 2026-09-20). Willing to test early cuts of any of these.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the Claude Code mapping, it's really useful.

    This is about the v1 plugin API (@opencode-ai/plugin / @opencode-ai/sdk, with hooks like tool.execute.after, chat.system.transform and session.idle). v1 (0.x/1.x) only gets fixes for critical bugs, so new hook surface there is unlikely to be added.

    OpenCode v2 (@opencode/cli) has a completely new plugin API in @opencode/plugin, where hooks are registered per domain (ctx.tool.hook, ctx.session.hook, ctx.permission.hook, ...). Part of your list already looks different there. For example, the v2 tool execute.after event includes status: "completed" | "error" (your gap 1) and the agent ID of the call. We'd encourage you to try porting your plugin to v2. If any of these gaps are still there in v2, please open a new issue against v2 for them (split up or together, whichever you prefer).

    If you think something here is a critical problem in v1, please reply and explain.

  2. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Closing this as not planned. These hook requests are for the v1 plugin API (@opencode-ai/plugin), and v1 only gets critical fixes. Nobody has replied to say any of them is critical in v1.

    Thanks again for the thorough Claude Code mapping. If you port your plugin to the v2 API (@opencode/plugin) and find gaps that are still there (cwd on tool hooks, model-switch events, per-agent hooks and so on), please open a new issue for v2 and reference this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions