sveltejs/writing-opencode-plugins
OpenCode plugins, @opencode-ai/plugin, @opencode-ai/plugin/tui, plugin hooks, custom tools, TUI routes, slots, keymaps, and packaging. Use when creating, editing, reviewing, testing, or publishing server or TUI plugins for OpenCode.
npx skills add https://github.com/sveltejs/ai-tools --skill writing-opencode-plugins
Use this skill to implement production-quality OpenCode plugins. Treat the repository's exported types and runtime as authoritative because plugin APIs are evolving and public docs may lag.
| Need | Plugin target | Import | Configuration |
| -------------------------------------------------------------------- | --------------------------- | ------------------------------ | ---------------------------------------------------------------- |
| Hooks, tools, auth, providers, model parameters, shell environment | Server | @opencode-ai/plugin | opencode.json or auto-discovered .opencode/plugins/*.{ts,js} |
| Commands, keybindings, routes, dialogs, slots, themes, notifications | TUI | @opencode-ai/plugin/tui | Explicit tui.json plugin entry |
| Both | Two target-only entrypoints | Both imports in separate files | Package exports ./server and ./tui |
Never export server and tui from the same module. Do not use server event hooks as a substitute for interactive TUI APIs.
Read these files before implementing unfamiliar behavior:
packages/plugin/src/index.ts: authoritative server plugin and hook types.packages/plugin/src/tool.ts: custom tool schema, context, permission, metadata, attachments, and result types.packages/plugin/src/tui.ts: authoritative TUI API and module types.packages/opencode/specs/tui-plugins.md: TUI loading, packaging, lifecycle, and API semantics.packages/opencode/src/plugin/shared.ts: target validation, IDs, and entrypoint resolution.packages/opencode/src/plugin/loader.ts: install, compatibility, and import behavior.If these disagree with examples or website docs, follow exported types and runtime behavior, then update stale documentation when appropriate.
Prefer the explicit module object for new server plugins:
import type { Plugin, PluginModule } from '@opencode-ai/plugin';
const server: Plugin = async ({ client, directory }, options) => ({
dispose: async () => {},
});
export default {
id: 'acme.example',
server,
} satisfies PluginModule & { id: string };
Legacy server-only local plugins may export a plugin function directly. In a legacy module every distinct named export is interpreted as a plugin, so do not export unrelated constants. Prefer a default module object for new code.
TUI plugins always use a default module object:
/** @jsxImportSource @opentui/solid */
import type { TuiPlugin, TuiPluginModule } from '@opencode-ai/plugin/tui';
const tui: TuiPlugin = async (api) => {
api.ui.toast({ message: 'Plugin loaded' });
};
export default {
id: 'acme.example-tui',
tui,
} satisfies TuiPluginModule & { id: string };
File plugins require a stable, non-empty id. npm plugins may derive the ID from the package name, but an explicit namespaced ID makes state, diagnostics, and collision handling clearer.
satisfies against the public plugin type.options; they arrive as unvalidated Record<string, unknown>.process.cwd().AbortSignal for long-running or cancellable work.client.app.log() for structured server logging instead of console.log.Server plugin tests belong under packages/opencode/test/plugin/ or the closest owning subsystem. TUI runtime tests belong under packages/opencode/test/cli/tui/; component-level TUI tests may belong in packages/tui.
Test at least:
Run tests from the package directory, never the repository root. Use bun typecheck from the owning package for type checking.
engines.opencode, and config target are correct.Take sveltejs/writing-opencode-plugins from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.