All Agent Engineering

Wire a tool into an OpenCode plugin and check execution limits

Load a local plugin, register a schema-defined tool, connect permission and cancellation, then check results, errors and reload.

AINavWritten / Updated
On this page

At a glance

Integrating a local plugin tool covers loading, registration and execution. This guide reads the official Plugins and Server build documentation and walks through an original network-free greeting tool: directory placement, enablement order, ctx.tool.transform, parameter schema, result and error contracts. External actions need explicit permission assertions and cancellation ownership; a loaded plugin does not establish one automatic restriction for every behavior. Only documentation and the integration design are checked here, without running OpenCode.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • OpenCode Wire a tool into an OpenCode plugin and check execution limits

Execution locations and responsibilities

  • OpenCode configuration loader and runtime Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Decide the load method and location → 2. Check relative paths and stacked arrays → 3. Confirm nothing disables the plugin → 4. Register a complete tool definition → 5. Assign permission, validation and cancellation ownership → 6. Reload and inspect the effective tool → 7. Accept each integration branch separately. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Decide the load method and location2. Check relative paths and stacked arrays3. Confirm nothing disables the plugin4. Register a complete tool definition5. Assign permission, validation and cancellationownership6. Reload and inspect the effective tool7. Accept each integration branch separately

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • Local paths configured in plugins must be directories; .opencode/plugins/ can also auto-discover .ts and .js files and package directories.

When not to use

  • This guide follows the documented Promise tool integration without inferring an unspecified sandbox, authorization strength or third-party API contract. Real external tools need permission and error evidence for their own resources and dependencies.
  • opencode plugin check and opencode plugin update target global package plugins and skip local plugins and exact package revisions; opencode plugin add accepts versioned package names but not local paths, so local plugins are configured directly and updating them is your own job.
  • TUI-only plugins are configured separately in cli.json, and only plugins that export ./gui-experimental add desktop UI; this sheet covers only a local plugin loaded by the server.
  • A change to a local dependency may not be watched, and a missed restart can look like the file changed but behavior did not.

Prerequisites and input

  • You have a local plugin directory and know which opencode.json(c) references it, or which .opencode/plugins/ it sits under.
  • You can get the plugin author's own source or notes, to read the tool name and parameters it registers.

Engineering checks

Load location — Local paths configured in plugins must be directories; .opencode/plugins/ can also auto-discover .ts and .js files and package directories.

Enablement and reload — Entries are processed in order, a - prefix disables, a later entry can re-enable, changes under watched directories reload automatically, and unwatched local dependencies may need a restart.

Tool parameters and execution responsibility — The Server documentation registers tools through a synchronous ctx.tool.transform editor using a complete ToolInfo definition with editor.add. This guide’s example fills name, description, input and execute; it does not infer that description is universally required. input uses JSON Schema and the example execute returns {content:string}. Inspect namespaced effective IDs outside transforms with ctx.tool.list and pass a Promise executor’s context.signal into cancellable work.

1. Decide the load method and location

Where: project directory and config files. Input: the local plugin directory. Action: pick one, either add a path to that directory in plugins or place it under .opencode/plugins/. A configured path to a single file is skipped; a plugins/ directory that relies on auto-discovery is not found when it sits only beside a project-root config, so configure its path explicitly or move it under .opencode/. Completion check: the path points to a directory, or the file sits in a discovered .opencode/plugins/. Stop condition: if the path is a single file, or the directory relies on auto-discovery but sits only beside the project root, change the placement or configure it explicitly before moving on; a valid directory already configured explicitly through plugins may proceed.

2. Check relative paths and stacked arrays

Where: every config file containing plugins. Input: each layer's plugins array. Action: confirm relative paths resolve from the config file that holds the entry; the documentation says arrays from applicable config files apply from lowest to highest rather than replacing one another. Completion check: you can list which entries each file contributes, and the same plugin is not referenced twice. Stop condition: if a resolved path differs from the intended directory, fix it before the next step.

3. Confirm nothing disables the plugin

Where: the entry order of the plugins array. Input: the full entry list. Action: look for *, entries with a - prefix and .* prefix matches, and remember that a later entry with the same ID re-enables it. The page says the built-in plugins opencode.config.policy and opencode.provider.opencode ignore removals. Completion check: under the final order your plugin ID is enabled. Stop condition: if the plugin is disabled and you cannot tell whether that is intended, stop and ask the config owner.

4. Register a complete tool definition

Where: plugin setup(ctx) and ctx.tool.transform. Input: a tool name, purpose and parameter table. Load external data before registration and keep the transform synchronous, replayable and free of one-time side effects. Register name, description, input and execute with editor.add. The example input is an object with required name:string and additionalProperties=false. execute reads name and returns {content:greeting text}; this is a local design, not an existing remote API. Completion: inspect the effective ID outside transforms with ctx.tool.list. A later registration can override the same effective name, so resolve collisions. Stop integration on missing constraints, incomplete definitions or unexpected replacement.The four filled fields are this example and local acceptance choice. Verify actual required fields against the runtime ToolInfo instead of inferring them from a sample.

5. Assign permission, validation and cancellation ownership

Where: execute and the plugin local policy. Input: actual parameters, target resources and context. Define input shapes and invalid cases for this network-free string tool. For external actions such as deployment, call ctx.permission.assert before the action with sessionID, agent, tool source and action/resources matching the real target; an after-action record is insufficient. Pass context.signal into cancellable Promise operations such as fetch. A deny or rejection with feedback yields Tool.Error, which should propagate instead of becoming ordinary success output; a plain rejection ends the current step. Completion: identify owners for parameters, denial, underlying cancellation and errors. Stop an external tool without pre-action permission evidence or stoppable work instead of treating loading as a restriction.

6. Reload and inspect the effective tool

Where: transform registrations and the runtime. Input: the registered plugin plus changed source or captured data. Watched directory changes reload; use documented opencode service restart for unwatched local dependencies. After captured data changes call ctx.tool.reload to replay active transforms, keeping repeated external calls out of the callback. Inspect effective names, schemas and expected provenance with ctx.tool.list instead of relying only on the global-package plugin list. Completion: the new definition actually appears without unintended replacement by another transform. Stop with unconfirmed status if loading or final registry evidence is unavailable and inspect configuration and sources.

7. Accept each integration branch separately

Where: practice-repository calls and the acceptance sheet. Input: valid name, missing name, wrong types, denial and cancellation cases. With a real runtime observe parameter admission, the {content:string} result, error propagation and underlying stop behavior, keeping expected and actual outcomes separate. Missing parameters cannot count as success. Without a runtime retain execution items as unconfirmed after design review. Completion: loading, effective ID, input/result contracts and applicable permission/cancellation branches have evidence; record external actions as not applicable to the network-free sample. Stop on a mismatching branch and return to its owning step without declaring a completed real run.

Task example

Unexecuted synthetic walkthrough: prepare a server plugin at .opencode/plugins/demo-greeting/, confirm its configuration and enabled ID, and register greeting through a synchronous transform in setup. Its input permits only required string name, and execute returns a content object holding the greeting. Inspect the effective name in the real tool list. Expect valid input to produce content and missing or wrongly typed input to take an explicit failure branch. No network is used, so deployment permissions are not applicable. If external actions are later added, connect permission assertions and signal before resuming acceptance. Captured-data changes replay through reload without requests inside the transform. All outcomes are expectations.

Completion checks

  • The plugin sits in a discovered directory or is configured as a directory path, and is not referenced twice.
  • Under the final plugins entry order, the plugin ID is enabled.
  • You recorded how you observed loading, and did not treat the result of opencode plugin list for a local plugin as the only evidence.
  • Trace the effective name and complete input schema, define result/error contracts, and assign owners plus actual acceptance evidence for applicable external permissions and underlying cancellation; unexecuted items remain unconfirmed.

Verification scope

Official Plugins and Server documentation was read. OpenCode was not installed, signed in or run; no product API, tool or external action was executed and no real result observed. The greeting tool is an original integration example. Runtime checks are subsequent acceptance requirements, not passing receipts from this review.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. OpenCode · OpenCode documentation: opencode-plugins
  2. OpenCode · OpenCode documentation: opencode-build-server

Found an error? Tell us →