GeezerVison is showing github.com — Hooks support? · Issue #1473 · anomalyco/opencode
DescriptionIs there an option to use hooks with opencode?
I want the agent to call a script after a task ends to automatically commit and push everything and open a PR.
Currently, it works by giving the instructions to the agent, but it consumes more and a lot of tokens. Also the output is not always consistent. Sometimes it doesn't set the assignee or labels, sometimes it randomly does nothing at all and I have to follow prompt to run the GitHub stuff.
And it's not efficient to let AI handle a simple task that can be run programmatically.
What is the best way to solve this with opencode? Reacted by arash-qc, Giovanni, Alp Sahin, Raymel, dev-abhirup-sc, enprop, Henrique Souza, Emin Meydanoglu, Max Sysoev, Benedict Summers and 7 more Reacted by Christopher Carroll Smith, arash-qc, Alp Sahin, Henrique Souza, Emin Meydanoglu and Somshubra Majumdar Reacted by Thomas Roche, Hayashi Tomoharu and Henrique Souza Activityfahmi-grande commented on Aug 1, 2025 Up for this. Claude Code hooks can do so much things right now. especially for this PreToolUse thdxr commented on Aug 1, 2025 we'll have something better than hooks - likely tomorrow Reacted by Fabio Tielen, Florian Vidal, mbastakis, Henry Moran, tomdevelops, Dan Kubb, Anh Dung Nguyen, Adam Hosker, enprop, Sheldon Zheng and 5 more Reacted by Tobias Walle, Muhammad Fahmi Ayil Ilahi, Dan Kubb, Arsham Shirvani and Bohdan Mart SquallLeonhart13 commented on Aug 1, 2025 ofonseca-pyming commented on Aug 4, 2025 Reacted by Arsen Nuramatov, tomdevelops, Adam Hosker, enprop, Luqmaan and John1995ac rmoriz commented on Aug 8, 2025 Did someone get the plugin approach to work? even the examples (notification) won't work for me. Neither in a project, nor globally (v0.4.1) asafyish commented on Aug 9, 2025 I also tried using simple plugins, nothing works.
I have a plugin in ~/.config/opencode/plugin - but it doesn't load, no errors in the logs. darrenhinde commented on Aug 9, 2025 Also having the same issue, tried both in project and the global level. rmoriz commented on Aug 9, 2025 let's use opencode to debug 😎
https://opencode.ai/s/U09ntSBv
Based on my analysis of the opencode plugin system, I've identified several issues that could prevent plugins from loading or working properly:
Issues Found:
-
Plugin Hook Structure Mismatch in Documentation vs. Implementation
Documentation shows tool.execute.before as nested hooks in /packages/web/src/content/docs/docs/plugins.mdx:96-106
But implementation expects flat hook names like "tool.execute.before" in /packages/opencode/src/plugin/index.ts:25-36
-
Missing Error Handling in Plugin Loading
Plugin loading in /packages/opencode/src/plugin/index.ts:20-35 lacks error handling
If a plugin fails to load or export properly, it could silently fail or crash the loading process
-
Inconsistent Plugin Discovery Paths
Global plugins search in ~/.config/opencode/plugin/.ts via /packages/opencode/src/config/config.ts:108
Project plugins search in .opencode/plugin/.ts via /packages/opencode/src/config/config.ts:109
But documentation mentions .opencode/plugin directory, not specific file patterns
-
Plugin Configuration Loading Issues
Config loading at /packages/opencode/src/config/config.ts:475-482 tries to resolve plugin paths but catches errors silently
This could mask actual plugin loading failures
-
Event System Integration
Plugin initialization in /packages/opencode/src/plugin/index.ts:59-68 subscribes to all bus events
But there's no verification that plugins actually get called properly
-
No Plugin Validation or Loading Logs
Missing debug logging to help troubleshoot plugin loading issues
No validation that exported functions match the Plugin interface
Main Problem Areas:
config.ts:105-111 - Plugin discovery and path resolution
plugin/index.ts:20-35 - Plugin loading loop with no error handling
plugin/index.ts:42-57 - Hook triggering mechanism
plugin/index.ts:59-68 - Event subscription for plugins
The most likely cause of user reports is that plugins are failing to load due to path resolution issues or silent failures in the loading process, with no debugging information to help users understand what went wrong.
rmoriz commented on Aug 9, 2025 this works for me:
Write .opencode/plugin/say-notification.ts
import type { Plugin } from "@opencode-ai/plugin"
export const SayNotificationPlugin: Plugin = async ({ app, client, $ }) => {
console.log("Say Notification Plugin initialized!")
return {
event: async ({ event }) => {
// Trigger when session becomes idle (user stops interacting)
if (event.type === "session.idle") {
try {
// Use macOS say command to announce session completion
await $`say "Your opencode session is now idle and ready for new input"`
} catch (error) {
console.error("Failed to use say command:", error)
}
}
},
}
}
prompt:
can you create an example plugin in typescript that calls macos' "say" command with a message when the session is idle?
rmoriz (11:46 PM)
I'll create an example TypeScript plugin that uses macOS's say command when a session becomes idle.
claude-sonnet-4 (11:46 PM)
Reacted by Christopher Carroll Smith and ikkun1222 rmoriz commented on Aug 9, 2025 TODO:
JavaScript plugins are supported, but there's a discrepancy in the current implementation. The config only searches for .ts files, but the
documentation shows JavaScript examples. This might be one of the issues causing plugin loading problems.
Here's the JavaScript version I created. The main differences from TypeScript:
• No type imports needed
• Same functionality and structure
• Works with Bun's native JavaScript support
However, I noticed the config currently only searches for .ts files in /packages/opencode/src/config/config.ts:108-109. This should
probably
be updated to also include .js files to match the documentation.
The JavaScript plugin should work if you manually add it to your config or if the search pattern gets updated to include .js files.
claude-sonnet-4 (11:55 PM)
Reacted by Christopher Carroll Smith asafyish commented on Aug 10, 2025 The problem I had was indeed js file instead of ts. rekram1-node commented on Aug 29, 2025
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|