Documentation Index
Fetch the complete documentation index at: https://ocx.kdco.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Plugins extend OpenCode by hooking into events and customizing behavior. They can add tools, intercept operations, and react to session lifecycle events.Plugin Locations
| Location | Scope |
|---|---|
.opencode/plugin/ | Project-level |
~/.config/opencode/plugin/ | Global |
npm packages in opencode.jsonc | Configured externally |
Adding npm Plugins with OCX
OCX supports adding npm plugins directly using thenpm: protocol:
plugin array in opencode.jsonc. OpenCode installs and loads the plugin at runtime.
Basic Plugin Structure
Context Object Properties
| Property | Description |
|---|---|
project | Current project information |
directory | Current working directory |
worktree | Git worktree path |
client | OpenCode SDK client for AI interaction |
$ | Bun’s shell API for executing commands |
Plugin Dependencies
Add external npm packages viapackage.json in your config directory:
.opencode/package.json
Available Events
Session Events
session.created/session.updated/session.deletedsession.idle— Session completedsession.compacted— Context was compactedsession.error/session.status/session.diff
Tool Events
tool.execute.before— Before tool execution (can modify/abort)tool.execute.after— After tool execution
File Events
file.edited— File was modifiedfile.watcher.updated— File system change detected
Message Events
message.updated/message.removedmessage.part.updated/message.part.removed
Permission Events
permission.updated/permission.replied
TUI Events
tui.prompt.append/tui.command.execute/tui.toast.show
Other Events
command.executed/installation.updated/server.connectedlsp.updated/lsp.client.diagnosticstodo.updated
Plugin Examples
.env Protection
Send Notifications
Custom Tools via Plugin
Compaction Hooks
Load Order
- Global config (
~/.config/opencode/opencode.jsonc) - Project config (
opencode.jsonc) - Global plugin directory (
~/.config/opencode/plugin/) - Project plugin directory (
.opencode/plugin/)
See Also
- Custom Tools — Standalone tool implementations.
- MCP Servers — External tool integration via MCP.
- Creating Registries — Distribute plugins via registries.