Skip to content

[FEATURE]: Expose resolved tool identity to tool.execute.before hooks #56820

Open

Description

@Stiix72

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

In OpenCode v2.0.27, the tool.execute.before hook can receive a tool invocation name that differs from the underlying tool selected for execution.

OpenCode maintains a request-specific mapping between tool definitions and their executors. However, the before-hook runs before the invocation name is resolved through that mapping.

The public before-hook API does not expose the authoritative resolved tool identity or provide access to the request-specific mapping.

Consequently, plugins cannot always reliably identify which underlying tool is about to execute.

Example

Consider a hypothetical tool registered as read_file.

A tool-definition transformation exposes that tool under the name inspect_file.

A plugin intending to intercept executions of read_file receives:

input.tool === "inspect_file"

Because the plugin expects read_file, it may fail to recognize the invocation and skip its intended before-hook processing.

OpenCode subsequently resolves the invocation to the correct underlying executor.

The tool itself executes correctly, but the plugin may not have performed its intended checks or modifications.

Why this matters

This limitation can affect plugins that use before-execution hooks for:

  • Tool-specific argument transformations
  • Validation and additional restrictions
  • Logging and auditing
  • Compatibility with older plugin APIs

It also becomes relevant when multiple plugins transform tool definitions or when registered tool names collide.

In isolated, source-backed tests against v2.0.27, identical before-hook inputs were observed for invocations that subsequently resolved to different underlying executors.

This demonstrates that the public before-hook fields alone are insufficient to determine the actual execution target in every case.

This appears to be a general plugin API limitation, rather than an issue specific to V1-to-V2 compatibility.

Technical details

The examined v2.0.27 execution path follows this sequence:

  1. OpenCode constructs the available tool definitions and retains their associated executors in a request-local mapping.
  2. OpenCode invokes tool.execute.before hooks using the invocation name.
  3. The invocation name is resolved through the internal mapping.
  4. Arguments are validated and the selected tool executes.

The before-hook interface exposes the tool name and invocation context, but not the final selected executor identity.

Additionally, other before-hooks may modify the invocation name, making a resolver that runs too early potentially unreliable.

Suggested improvement

Would it be possible to expose the authoritative selected tool identity through a supported plugin API before execution?

One possible approach would be a hook stage after final tool-name resolution but before argument validation and execution.

Such a hook could provide both:

Invoked tool name: The name supplied in the invocation.

Resolved tool identity: The actual underlying tool or executor selected by OpenCode.

An alternative request-scoped resolution mechanism could also work, provided its result remains valid when execution occurs.

This would allow plugins to implement reliable tool-specific behavior without guessing alias relationships or relying on registration-name heuristics.

Questions

Is the current before-hook behavior intentional?

Are plugins expected to identify tools exclusively by their invocation names?

Is there an existing supported API for determining the selected underlying tool before execution?

Would exposing resolved tool identity through a public hook be an appropriate enhancement?

Environment

OpenCode: v2.0.27

Interfaces examined: Promise and Effect plugin hooks

Verification: Archived host-source inspection and isolated source-backed tests

Scope: Public plugin API; no modifications to OpenCode itself

This request is intended to clarify and potentially improve tool identity handling for plugins. It does not suggest that OpenCode's underlying tool execution or native permission enforcement is necessarily incorrect.

Related discussion

#35364 — V2 tool plugin APIs and execution integration architecture.

Activity

  1. opencode-agent commented on Oct 18, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed write-up! You're asking for the plugin API to expose which tool OpenCode has actually picked to run, not just the name the model called. The idea is that tool.execute.before hooks (or a new hook stage after name resolution) could reliably match the underlying tool even when a transform has renamed it.

    I checked the current code and this matches what you describe. tool.execute.before receives the invocation name, and the lookup to the real tool happens afterwards in a request-local mapping that plugins can't see. ctx.tool.list() only returns the registry after transforms, not that per-request mapping. So right now there is no supported way for a plugin to get the resolved tool identity before it runs, and a plugin can't work around this.

    One possible addition is a read-only resolved tool ID on the execute.before/execute.after events, or a separate hook that fires after final name resolution and before argument validation. Maintainers will consider this.

    Related issues:

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

Metadata

Metadata

Assignees

No one assigned

    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