Updated: November 30, 2026.

An OpenCode plugin is TypeScript or JavaScript that runs inside the OpenCode server and changes how it behaves: custom tools the model can call, hooks that intercept tool executions and prompts, commands, agent registrations, and event subscriptions. You drop a file into .opencode/plugins/ and it loads. No build step, no marketplace. I use one in production to block the agent from ever reading .env files, and it is fifteen lines.

Where plugin files live

OpenCode auto-discovers plugins in two places:

.opencode/plugins/          # per project, committed with the repo
~/.config/opencode/plugins/ # global, all projects

Both direct .ts/.js files and plugin directories work. Published plugins are npm packages: add them to the plugins array in opencode.json(c) and manage them with the CLI:

opencode plugin add [email protected]
opencode plugin list
opencode plugin update
opencode plugin remove opencode-acme-plugin

Version handling is pragmatic. A bare package name stays on the version it installed, while a range like name@^1.2.0 or name@latest auto-updates on startup and every 24 hours. Exact versions and commit hashes stay pinned. The plugins configuration docs cover the full matrix.

A working plugin, verbatim

This is the plugin I run on client projects. It throws when the agent tries to read a .env file and injects an environment variable into every shell command:

import { Plugin } from "@opencode/plugin"

export default Plugin.define({
  id: "company.guard",
  async setup(ctx) {
    await ctx.tool.hook("execute.before", (event) => {
      const input = event.input as { filePath?: string }
      if (event.tool === "read" && input.filePath?.includes(".env")) {
        throw new Error("Do not read .env files")
      }
    })

    await ctx.shell.hook("create.before", (event) => {
      event.env.COMPANY_ENV = "development"
    })
  },
})

Save it as .opencode/plugins/guard/index.ts and it loads on the next session. The id is required and identifies the plugin in status output and storage. Changes under watched directories reload automatically, so edits land without a restart in most cases.

Adding a custom tool follows the same shape. Register through a transform and the tool appears in the model's catalog:

await ctx.tool.transform((editor) => {
  editor.add({
    name: "greeting",
    description: "Create a greeting",
    input: {
      type: "object",
      properties: { name: { type: "string" } },
      required: ["name"],
      additionalProperties: false,
    },
    async execute(input) {
      return { content: `Hello ${(input as { name: string }).name}!` }
    },
  })
})

Through the same setup(ctx) you can register commands (ctx.command.transform), subscribe to the server event stream (ctx.event.subscribe), register agents, add providers and models, and read plugin options from opencode.json(c). The server plugin API reference documents every domain.

The V1 to V2 API change, and why your old plugin is dead

This is the part most blog posts get wrong. OpenCode's plugin API was rebuilt. A V1 plugin was an async function from @opencode-ai/plugin that returned one object of tools and hooks. V2 is a Plugin.define({ id, setup }) from @opencode/plugin. The migration guide states it bluntly: V1 plugin implementations do not run in V2, and moving the file or renaming the config entry is not enough. The config key changed too, from plugin to plugins, and local plugins must be directories, not single files.

If a plugin you installed months ago silently stopped loading, this is almost certainly why. Check whether the package shipped a V2 port, or port it yourself with the migration table.

Plugin vs agent vs skill

Three extension points, three different jobs:

What it isWritten inRuns
PluginCode: tools, hooks, commands, event handlersTypeScript/JSInside the server, always active
AgentA named profile: system prompt, model, permissionsMarkdown or JSONCAs a primary or subagent session
SkillInstructions the model loads when relevantSKILL.md markdownIn the current session's context

An agent changes who the model is and what it may do. A skill changes what the model knows when the task matches. A plugin changes what OpenCode itself can do, including things the model never sees. If you want a read-only reviewer, write an agent. If you want to forbid .env reads at the tool layer no matter which agent runs, write a plugin. My OpenCode vs Claude Code comparison covers how this plugin model stacks up against Claude Code's marketplace approach.

What plugins are worth writing

From running this stack daily: guard hooks first (file and command denylists, the .env block above), then prompt redaction. The session prompt hook rewrites incoming prompts before admission, which is where I strip internal hostnames from anything heading to a third-party model. Custom tools are worth it only when the capability does not exist as an MCP server yet, since MCP servers are the more portable way to add tools and they work in Claude Code too. Everything else, agents and skills handle as plain markdown with none of the maintenance.

FAQ

How do I install an OpenCode plugin?

Three ways: drop a .ts or .js file into .opencode/plugins/ (project) or ~/.config/opencode/plugins/ (global) for auto-discovery, add an npm package to the plugins array in opencode.json(c), or run opencode plugin add <package>. Local plugin entries must point at directories; a path to a single file is skipped.

What language are OpenCode plugins written in?

TypeScript or JavaScript. The plugin runs inside the OpenCode server, and the SDK comes from the @opencode/plugin package. A plugin can also ship TUI and desktop GUI parts from the same package, which is more than most people need.

Why is my old OpenCode plugin not loading?

The V1 plugin API does not run in V2 OpenCode. V1 plugins were async functions returning a tools-and-hooks object from @opencode-ai/plugin; V2 requires a Plugin.define with an id and a setup(ctx) from @opencode/plugin. The config key also changed from plugin to plugins. Port the implementation using the official migration guide.

What is the difference between OpenCode plugins and agents?

An agent is a profile that changes the system prompt, model, and permissions of a session, written as markdown. A plugin is code that registers tools, hooks, commands, and transforms inside the OpenCode server, active regardless of which agent runs. Use an agent for behavior specialization, a plugin for capabilities and enforcement.

Are OpenCode plugins free?

Yes. OpenCode itself is free and MIT licensed, plugins are ordinary TypeScript files or npm packages, and the plugin CLI ships with the core tool. What you pay for is model usage through your provider, not the extension system.

Sources