Skip to content

[feat] lifecycle hooks #573

Closed
Closed

Description

@monotykamary

Hooks are probably hidden gems for a client/server architecture CLI like opencode. It's bit different that the current event system hooks in that we can inject other behaviors (like inline linting) or pass messages to a UI framework.

Claude Code has these hooks:
• PreToolUse: runs before a tool is called; can block or modify tool execution (e.g., validate or restrict commands).
• PostToolUse: runs after a tool completes successfully; can provide feedback or take actions based on tool results.
• Notification: runs when Claude Code sends notifications (e.g., when awaiting input or permission).
• Stop: runs when Claude Code finishes responding; can block or allow the session to end.

Maybe a middle ground we can take advantage of for /share as well, as the websocket sends some simple key values:

// Initial message (just created)                                        
{ "key": "session/message/abc/msg1", "content": { "parts": [],           
"metadata": {...} }}                                                     
                                                                         
// After text starts streaming                                           
{ "key": "session/message/abc/msg1", "content": { "parts": [{"type":     
"text", "text": "I'll help..."}], "metadata": {...} }}                   
                                                                         
// After tool call starts                                                
{ "key": "session/message/abc/msg1", "content": { "parts": [..., {"type":
"tool-invocation", "state": "partial-call"}], "metadata": {...} }}       
                                                                         
// After tool completes                                                  
{ "key": "session/message/abc/msg1", "content": { "parts": [..., {"type":
"tool-invocation", "state": "result", "result": "..."}], "metadata":     
{"tool": {"call_123": {"time": {...}}}} }}                               

Activity

  1. thdxr commented on Jul 1, 2025

    @thdxr
    Member

    we're likely going to have a plugin system where you can define these in typescript instead of the awkward hooks format claude code has

    we actually have some experimental command based hooks here: https://raw.githubusercontent.com/sst/opencode/refs/heads/dev/packages/opencode/config.schema.json

  2. self-assigned this
    on Jul 1, 2025
  3. haydnhkim commented on Jul 3, 2025

    @haydnhkim

    It would be nice to have a hook that matches Claude Code's PreToolUse.

  4. marked Hooks #1219 as a duplicate of this issue on Jul 25, 2025
  5. ghost91- commented on Aug 6, 2025

    @ghost91-
    Contributor

    @monotykamary is this already solved by the new plugin functionality? Or are any particular hooks still missing?

  6. monotykamary commented on Aug 6, 2025

    @monotykamary
    ContributorAuthor

    Oh probably; this issue can probably be closed. Probably deserves a documentation update for all of the events that opencode has:

    • installation.updated
    • lsp.client.diagnostics
    • message.updated
    • message.removed
    • message.part.updated
    • message.part.removed
    • storage.write
    • file.edited
    • server.connected
    • permission.updated
    • permission.replied
    • session.updated
    • session.deleted
    • session.idle
    • session.error
    • file.watcher.updated
    • ide.installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions