Loading...
Loading...
Create OpenCode plugins using the @opencode-ai/plugin SDK. Use for building custom tools, event hooks, auth providers, or tool execution interception. Use proactively when developing new plugins in .opencode/plugin/ or ~/.config/opencode/plugin/. Examples: - user: "Create a plugin to block dangerous commands" → implement tool execution before hook with blocking logic - user: "Add a custom tool for jira" → design tool schema and implementation using SDK context - user: "Show toast on file edit" → react to file edit events and display status message - user: "Build a custom auth provider" → implement auth flow for new model provider - user: "Intercept git commits" → add hook to validate commit messages before execution
npx skill4agent add igorwarzocha/opencode-workflows create-opencode-plugin| Step | Action | Read |
|---|---|---|
| 1 | Verify SDK reference | Run extract script |
| 2 | Validate feasibility | This file |
| 3 | Design plugin | |
| 4 | Implement | |
| 5 | Add UI feedback | |
| 6 | Test | |
| 7 | Publish | |
bun run .opencode/skill/create-opencode-plugin/scripts/extract-plugin-api.tsreferences/hooks.mdreferences/events.mdreferences/tool-helper.mdpackages/opencodereferences/hooks.mdreferences/hook-patterns.mdreferences/CODING-TS.MDindex.ts| Scope | Path | Use Case |
|---|---|---|
| Project | | Team-shared, repo-specific |
| Global | | Personal, all projects |
import type { Plugin } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
// Setup code runs once on load
return {
// Hook implementations - see references/hook-patterns.md
}
}| Parameter | Type | Description |
|---|---|---|
| | Current project info (id, worktree, name) |
| SDK Client | OpenCode API client |
| | Bun shell for commands |
| | Current working directory |
| | Git worktree path |
references/hook-patterns.mdreferences/tool-helper.mdreferences/events.mdreferences/examples.mdreferences/CODING-TS.MD.opencode/plugin/my-plugin/
├── index.ts # Entry point, exports Plugin
├── types.ts # TypeScript types/interfaces
├── utils.ts # Shared utilities
├── hooks/ # Hook implementations
│ ├── event.ts
│ └── tool-execute.ts
└── tools/ # Custom tool definitions
└── my-tool.tsimport type { Plugin } from "@opencode-ai/plugin"
import { eventHooks } from "./hooks/event"
import { toolHooks } from "./hooks/tool-execute"
import { customTools } from "./tools"
export const MyPlugin: Plugin = async ({ project, client }) => {
return {
...eventHooks({ client }),
...toolHooks({ client }),
tool: customTools,
}
}| Mistake | Fix |
|---|---|
Using | Use |
| Wrong event property names | Check |
| Sync event handler | MUST use |
| Not throwing to block | |
| Forgetting TypeScript types | |
references/toast-notifications.mdreferences/ui-feedback.md| Need | Use |
|---|---|
| Brief alerts, warnings | Toast |
| Detailed stats, multi-line | Inline message |
| Config validation errors | Toast |
| Session completion notice | Toast or inline |
references/testing.mdopencode.json{
"plugin": ["file:///path/to/your/plugin/index.ts"],
}cd /path/to/test-folder
opencode run hiopencodereferences/publishing.mdreferences/update-notifications.md| File | Purpose | When to Read |
|---|---|---|
| Hook signatures (auto-generated) | Step 3-4 |
| Event types (auto-generated) | Step 4 (if using events) |
| Zod tool schemas (auto-generated) | Step 4 (if custom tools) |
| Hook implementation examples | Step 3-4 |
| Code architecture principles | Step 3 (Design) |
| Complete plugin examples | Step 4 |
| Toast popup API | Step 5 (if toasts needed) |
| Inline message API | Step 5 (if inline needed) |
| Testing procedure | Step 6 |
| npm publishing | Step 7 |
| Version toast pattern | Step 7 (for npm plugins) |