Repository navigation
Closed as duplicate
Description
Summary
The permission.ask hook defined in the @opencode-ai/plugin SDK is never triggered because OpenCode's permission system uses PermissionNext.ask() which emits Bus events instead of calling Plugin.trigger("permission.ask", ...).
Expected Behavior
When a permission check requires user approval, plugins should receive the permission.ask hook callback as documented in the SDK.
Actual Behavior
The permission.ask hook is never called. Instead, permission.asked events are emitted via the Bus system and can only be captured through the generic event hook.
Root Cause Analysis
OpenCode has two permission modules:
permission/index.ts(legacy/unused) - ContainsPermission.ask()that callsPlugin.trigger("permission.ask", ...)at line 134permission/next.ts(actively used) - ContainsPermissionNext.ask()that publishesBus.publish(Event.Asked, info)at line 140
All actual permission checks use PermissionNext.ask(), which:
- Emits
permission.askedvia the Bus system (triggers genericeventhook) - Does NOT call
Plugin.trigger("permission.ask", ...)
Code Evidence
// packages/opencode/src/permission/next.ts:128-141 (ACTIVELY USED)
if (rule.action === "ask") {
const id = input.id ?? Identifier.ascending("permission")
return new Promise<void>((resolve, reject) => {
const info: Request = {
id,
...request,
}
s.pending[id] = {
info,
resolve,
reject,
}
Bus.publish(Event.Asked, info) // <-- Emits "permission.asked", NOT "permission.ask" hook
})
}Suggested Fix
Either:
- Add
Plugin.trigger("permission.ask", info)call inPermissionNext.ask()before/after the Bus publish - Or document that plugins should use the
eventhook withtype: "permission.asked"instead
Workaround
Plugins can listen to permission events via the generic event hook:
export default {
name: "my-plugin",
hooks: {
event: async (event) => {
if (event.type === "permission.asked") {
// Handle permission request
console.log("Permission requested:", event.properties)
}
}
}
}Environment
- OpenCode version: latest (dev branch)
- Discovered while building an external agent manager that tracks session state
Reacted by Jacob Daitzman
Reacted by Jacob Daitzman
Metadata
Metadata
Assignees
Labels
No labels
Activity
github-actions commentedon Jan 18, 2026
This issue might be a duplicate of existing issues. Please check:
permission.askplugin hook is defined but not triggered #7006:permission.askplugin hook is defined but not triggeredThis appears to be the same issue with identical root cause analysis and suggested fixes. Feel free to ignore if your specific case differs.
permission.askplugin hook is defined but not triggered #7006