GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [FEATURE]: Plugin API: let a plugin run its tool transform last · Issue #57217 · anomalyco/opencode

[FEATURE]: Plugin API: let a plugin run its tool transform last #57217

New issue
Copy link
New issue
Copy link
Open
Open
[FEATURE]: Plugin API: let a plugin run its tool transform last#57217
Copy link

Description

@iceteaSA
iceteaSA
opened on Oct 19, 2026
Issue body actions

Problem

Tool transforms run in registration order. A plugin that adds its transform after a different plugin can replace a tool. The replacement discards the wrapper that an earlier plugin added. A plugin cannot select the last position for its transform.

Source (v2.0.31)

  • packages/core/src/state.ts:19 gives the order:

    Registers a scoped transform. Reads rebuild by applying every registered transform in order.

  • packages/core/src/state.ts:178 applies the transforms in insertion order:

    for (const transform of transforms) {

  • packages/core/src/tool/AGENTS.md:37 shows that the tool registry uses this state:

    The service uses shared State to replay synchronous transforms in registration order against a fresh editor.

Purpose

A credential-filter plugin adds a wrapper to all tools. The wrapper removes secrets from tool output. A plugin that adds its transform after a different plugin replaces one tool with its own definition. The replacement has no wrapper. The secret filter stops for that tool.

Proposed minimal API

Add an order option to ctx.tool.transform. A plugin with the last order runs after all other transforms.

What the plugin does today without it

The plugin cannot control the order. The plugin must add its transform again after all other plugins, and the order is not stable.

Activity

  1. opencode-agent commented on Oct 19, 2026

    @opencode-agent
    opencode-agentBot
    on Oct 19, 2026 – with OpenCode Agent
    Contributor
    More actions

    Thanks for the detailed write-up! You're asking for a way to make a plugin's ctx.tool.transform run after every other transform, so that a later plugin replacing a tool can't drop your wrapper. Right now transforms run in registration order by design (the latest registration for a tool name wins), so this would be a new option. Maintainers will consider it.

    For the credential-filter case specifically, you may not need transform ordering. The execute.after tool hook runs for every tool call, whichever plugin defined or replaced the tool, and OpenCode uses the event.result you leave behind. So redacting there can't be bypassed by another plugin's editor.add. Here's a minimal version (it type-checks against the v2 plugin API; I haven't run it in a live session):

    // .opencode/plugins/credential-filter.ts
    import { Plugin } from "@opencode/plugin"
    
    const patterns: RegExp[] = [
      /AKIA[0-9A-Z]{16}/g,
      /gh[pousr]_[A-Za-z0-9]{36,}/g,
      /sk-[A-Za-z0-9_-]{20,}/g,
    ]
    
    const redact = (text: string) => patterns.reduce((acc, re) => acc.replace(re, "[REDACTED]"), text)
    
    const redactValue = (value: unknown): unknown => {
      if (typeof value === "string") return redact(value)
      if (Array.isArray(value)) return value.map(redactValue)
      if (value && typeof value === "object")
        return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, redactValue(v)]))
      return value
    }
    
    export default Plugin.define({
      id: "credential-filter",
      setup: async (ctx) => {
        await ctx.tool.hook("execute.after", (event) => {
          if (event.status !== "completed") return
          const { content, output, metadata } = event.result
          event.result = {
            ...(output === undefined ? {} : { output: redactValue(output) }),
            ...(content === undefined
              ? {}
              : {
                  content:
                    typeof content === "string"
                      ? redact(content)
                      : content.map((part) => (part.type === "text" ? { ...part, text: redact(part.text) } : part)),
                }),
            ...(metadata === undefined ? {} : { metadata: redactValue(metadata) as typeof metadata }),
          }
        })
      },
    })

    To install it, save the file as .opencode/plugins/credential-filter.ts in your project and restart OpenCode. Replace the patterns with your own.

    If you also need to change tool definitions after everyone else (schemas, descriptions, options), or to redact progress updates while a tool is still running, the hook doesn't cover that. A transform ordering option would still be needed there, so feel free to add details if that's your case.

    Related issues:

    • feat(plugin): session-scoped tool registrations #52018: session-scoped tool registrations
    • Plugin API: ctx.tool.transform tools.add crashes with TypeError '_.name.replace' on undefined (beta-17498) #43753: a crash in ctx.tool.transform tools.add
    • fix(core): isolate invalid plugin tools during reload #35963: isolating invalid plugin tools during reload
  2. iceteaSA commented on Oct 20, 2026

    @iceteaSA
    iceteaSA
    on Oct 20, 2026
    Author
    More actions

    Thanks. We already use execute.after for some output, and we checked it at v2.0.32 before relying on it for every tool. Two gaps remain for a credential filter:

    1. Failures that are not Tool.Error skip the hook. executeTool catches only Tool.Error (tool.ts#L119-L121 at v2.0.32), so defects and interruption never reach execute.after. The status: "error" branch itself works: the host returns afterEvent.error, so a filter can replace it. Note that the example above returns early on errors, so a filter based on it would not redact error text.
    2. Streamed progress is stored before the hook runs ([FEATURE]: plugin hook for streamed tool metadata (bash output is persisted before tool.execute.after can redact it) #51937).

    If execute.after, or a final hook, ran for every terminal outcome, including defects and interruption, a credential filter would no longer need transform ordering. Ordering would then matter only for definition changes such as schemas, descriptions and options.

  3. mirsella commented on Nov 4, 2026

    @mirsella
    mirsella
    on Nov 4, 2026
    Contributor
    More actions

    Concrete use case for this: I wanted a small local plugin to remove the browser.* tools from the registry. In service-hosted sessions no desktop browser is ever attached, so every call fails with [browser.disconnected] (reproduced in #61609), and the tools still sit in the catalog. opencode.browser registers in the post group, so from a config plugin the transform only sees the MCP tools and there is nothing to remove.

    The only workaround left is an AGENTS.md line telling agents not to call them, which is the sort of thing a plugin should be able to handle.

    Either an ordering option or a priority on ctx.tool.transform would be enough. It doesn't have to be removal specifically; seeing the final registry after every plugin has registered covers it.

  4. rcsi-dev commented on Nov 18, 2026

    @rcsi-dev
    rcsi-dev
    on Nov 18, 2026
    More actions

    A concrete, fully-diagnosed case of the ordering problem — worse than plugin-vs-plugin: an internal post plugin overwrites a third-party plugin's tools by effective name, then hides them, and the third-party plugin can never win because internal plugins always register last.

    Case: @vymalo/opencode-browser vs the built-in desktop opencode.browser

    v2.2.6, Linux, fresh sessions. The plugin registers 27 tools (33 with the debug group), all named browser_<verb>. After install, every fresh session only ever sees 19 of them: browser_click, browser_snapshot, browser_screenshot, browser_scroll, browser_navigate, browser_back, browser_forward, browser_reload, browser_hover, browser_drag, browser_fill, browser_select, browser_wait, browser_console are silently missing — while browser_double_click, browser_type, browser_open, etc. work fine.

    Mechanism (all verified against a live server):

    1. BrowserPlugin is in the post list of packages/core/src/plugin/internal.ts (line 294), so it always registers after external plugins.
    2. Its tools use options.namespace: "browser" with short names (click, back, …), so effectiveName produces browser_click, browser_back, … — identical to the third-party plugin's un-namespaced tool names.
    3. The registry is keyed by effective name with last-write-wins (packages/core/src/tool.ts, editor.tools.set(id, tool)), so the built-in entries overwrite the third-party ones. (Confirmed with a diagnostic plugin dumping ctx.tool.list(): the 14 colliding IDs carry {namespace: "browser", permission: "browser"} — the built-in registrations, not the plugin's.)
    4. On top of that, BrowserConnection.make (packages/plugin-browser/src/connection.ts) pushes a browser-permission deny into every agent ("every agent hides the browser until an attachment allows it"), and Tool.snapshot drops wholly-denied tools — so the 14 clobbered names vanish from every agent's toolset entirely. No error, no log; the registration of the third-party originals was simply overwritten first.

    The 19 surviving tools are exactly the ones whose names the desktop plugin doesn't use — which is why the missing set looks arbitrary at first glance (e.g. browser_click missing while browser_double_click is present).

    Workaround we're running today

    "-opencode.browser" in plugins disables the desktop plugin (it is not in the guarded set), and all 33 tools come back with their original names. That's fine for us (no desktop attachment), but it also kills the desktop browser tools, and it requires knowing this whole mechanism — a third-party plugin author can't ship a config that fixes it for their users.

    Aside: the plugin tools could also defend themselves

    Worth noting the collision is symmetric: any third-party plugin that wants to keep these names can't, short of a namespace that renames every tool (browser_click → <ns>_browser_click). Something like a collision check at registration (warn/skip when an internal post tool would overwrite a non-internal registration) or namespacing internal toolsets out of the bare-name space would fix the class, not just this pair.

    Happy to provide the registry dumps / reproduction steps in detail if useful.

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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.