Skip to content

Conversation

@ananas-viber
Copy link

Summary

Implements the permission.ask plugin hook that was defined but never triggered in PermissionNext.ask().

Problem

Issue #7006: Plugins cannot intercept permission requests because Plugin.trigger("permission.ask", ...) is never called in the permission system.

This prevents plugins like oh-my-opencode from implementing PreToolUse hooks for:

  • Auto-approving safe operations
  • Auto-denying restricted file patterns
  • Delegation enforcement for orchestrator agents

Solution

Add Plugin.trigger("permission.ask", info, { status: "ask" }) call in PermissionNext.ask() before showing the UI prompt:

  • If plugin returns "allow" → auto-approve (continue)
  • If plugin returns "deny" → throw DeniedError
  • If plugin returns "ask" or unchanged → proceed with existing UI prompt flow

Testing

This change follows the exact same pattern used in permission/index.ts which already has working Plugin.trigger("permission.ask", ...) integration.

Impact

  • Enables oh-my-opencode and other plugins to implement PreToolUse hooks
  • Backward compatible - no behavior change if no plugin handles the hook
  • Unblocks delegation enforcement patterns for orchestrator agents

Fixes #7006

The permission.ask hook was defined in the plugin SDK types but never
triggered in PermissionNext.ask(), preventing plugins from intercepting
permission requests.

This fix adds the Plugin.trigger() call before showing the UI prompt,
allowing plugins like oh-my-opencode to auto-approve or auto-deny
based on custom logic (e.g., PreToolUse hooks for delegation enforcement).

Fixes anomalyco#7006
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

This PR may be related as it also deals with plugin interactions around permission asking in the tool context. However, it appears to be a different approach (adding askPermission to ToolContext) compared to PR #7077 which focuses on triggering the permission.ask hook in PermissionNext.

The other search results only returned PR #7077 itself (the current PR), which is expected.

@ananas-viber ananas-viber marked this pull request as draft January 6, 2026 12:26
@ananas-viber
Copy link
Author

Clarification: Relationship to PR #6042

After deeper investigation, I want to clarify how this PR relates to #6042:

This PR (#7077) and PR #6042 are complementary, not duplicates:

PR Purpose Direction
#6042 Adds askPermission to ToolContext Plugin requests permission
#7077 (this) Triggers permission.ask hook Plugin intercepts permission

Different Use Cases:

Note on oh-my-opencode:

The original description mentioned oh-my-opencode PreToolUse hooks. To clarify:

  • oh-my-opencode's PreToolUse hooks use the tool.execute.before plugin hook (which already works)
  • This PR enables a different hook (permission.ask) for intercepting permission dialogs

Both approaches are valid and serve different purposes in the plugin ecosystem.

ananas-viber pushed a commit to ananas-viber/oh-my-opencode that referenced this pull request Jan 6, 2026
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath
without checking if zsh actually exists on the system. This caused
hook commands to fail silently with exit code 127 on systems without
zsh installed.

The fix ensures `findZshPath()` is always called to verify the shell
exists before wrapping commands. If zsh is not found, commands fall
through to use the default shell via `spawn` with `shell: true`.

Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks
now execute correctly on systems without zsh.
@ananas-viber
Copy link
Author

Closing this PR after further investigation.

Findings

The original issue (oh-my-opencode PreToolUse hooks not firing) was caused by a different problem: oh-my-opencode's executeHookCommand uses forceZsh: true on Linux but doesn't verify zsh exists before using it. On systems without zsh, hook commands fail silently with exit code 127.

The Fix

The actual fix is in oh-my-opencode, not opencode:

Why This PR Isn't Needed

  • permission.ask hook (what this PR adds) is only triggered when prompting the user for permission
  • tool.execute.before hook (what oh-my-opencode uses for PreToolUse) is already triggered on every tool execution
  • These are different hook pathways - the oh-my-opencode fix addresses the actual issue

Testing

Verified with stock opencode v1.1.3 + patched oh-my-opencode:

  • PreToolUse hooks now fire correctly for Edit, Read, Glob, etc.
  • No changes to opencode required

Apologies for the noise - the root cause investigation led us down the wrong path initially.

ananas-viber added a commit to ananas-viber/oh-my-opencode that referenced this pull request Jan 6, 2026
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath
without checking if zsh actually exists on the system. This caused
hook commands to fail silently with exit code 127 on systems without
zsh installed.

The fix ensures `findZshPath()` is always called to verify the shell
exists before wrapping commands. If zsh is not found, commands fall
through to use the default shell via `spawn` with `shell: true`.

Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks
now execute correctly on systems without zsh.
ananas-viber pushed a commit to ananas-viber/oh-my-opencode that referenced this pull request Jan 6, 2026
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath
without checking if zsh actually exists on the system. This caused
hook commands to fail silently with exit code 127 on systems without
zsh installed.

The fix ensures `findZshPath()` is always called to verify the shell
exists before wrapping commands. If zsh is not found, commands fall
through to use the default shell via `spawn` with `shell: true`.

Tested with patched opencode (anomalyco/opencode#7077) - PreToolUse hooks
now execute correctly on systems without zsh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

permission.ask plugin hook is defined but not triggered

1 participant