opencode-install-plugin
Skill0 starsChanged 10 months agoMITView on GitHub
Manage and create OpenCode plugins for extending OpenCode capabilities. Use when users need to install plugins from local files or npm packages, create custom plugins with hooks and events, add custom tools to OpenCode, configure plugin dependencies, or understand plugin load order and lifecycle.
- Reads credentials
In this repositoryOne other file it gives its agents.
- senior-dotnetSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Place plugin files in plugin directories:
- Very specific: line 38
Create package.json in config directory with dependencies:
- Very specific: line 52
Add plugins to opencode.json config:
- Distinctive: line 93
Import types for type safety:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
OpenCode Plugin Management
Quick Start
OpenCode plugins extend functionality by hooking into events and customizing behavior. Choose your task:
- Install plugin: See Install from Local Files or Install from npm
- Create plugin: See Create a Plugin
- Add custom tools: See Add Custom Tools
- Use hooks/events: See events.md for complete event list
- View examples: See examples.md for common patterns
Plugin Context Object
Plugins receive { project, client, $, directory, worktree }:
project: Current project informationclient: OpenCode SDK client for AI interaction$: Bun's shell API for command executiondirectory: Current working directoryworktree: Git worktree path
Install from Local Files
Place plugin files in plugin directories:
- Project-level:
.opencode/plugins/ - Global:
~/.config/opencode/plugins/
Files are auto-loaded at startup.
Add Dependencies
Create package.json in config directory with dependencies:
{
"dependencies": {
"package-name": "^1.0.0"
}
}OpenCode runs bun install at startup. See package.json template.
Install from npm
Add plugins to opencode.json config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-helicone-session", "opencode-wakatime", "@my-org/custom-plugin"]
}Both regular and scoped packages supported. Browse available plugins at OpenCode ecosystem.
Installation Process
- npm plugins: Auto-installed via Bun at startup, cached in
~/.cache/opencode/node_modules/ - Local plugins: Loaded directly, require
package.jsonfor external dependencies
Load Order
Plugins load in sequence:
- Global config (
~/.config/opencode/opencode.json) - Project config (
opencode.json) - Global plugin directory (
~/.config/opencode/plugins/) - Project plugin directory (
.opencode/plugins/)
Duplicate npm packages (same name/version) load once. Local + npm plugins with similar names load separately.
Create a Plugin
Basic Structure
export const MyPlugin = async ({ project, client, $, directory, worktree }) => {
console.log("Plugin initialized!")
return {
// Hook implementations
}
}TypeScript Support
Import types for type safety:
import type { Plugin } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
return {
// Type-safe hooks
}
}Use Templates
Copy from assets/templates/basic-plugin.ts to start.
Add Custom Tools
Plugins can register custom tools using the tool helper:
import { type Plugin, tool } from "@opencode-ai/plugin"
export const CustomToolsPlugin: Plugin = async (ctx) => {
return {
tool: {
myTool: tool({
description: "What the tool does",
args: {
foo: tool.schema.string(),
},
async execute(args, ctx) {
return `Result: ${args.foo}`
},
}),
},
}
}See custom-tools-plugin.ts template and examples.md.
Common Hook Patterns
Tool Interception
"tool.execute.before": async (input, output) => {
if (input.tool === "read" && output.args.filePath.includes(".env")) {
throw new Error("Do not read .env files")
}
}Event Monitoring
event: async ({ event }) => {
if (event.type === "session.idle") {
await $`osascript -e 'display notification "Session completed!"'`
}
}Logging
await client.app.log({
service: "my-plugin",
level: "info",
message: "Plugin initialized",
extra: { key: "value" },
})Levels: debug, info, warn, error.
Resources
events.md
Complete list of all plugin events organized by category (Command, File, LSP, Message, Session, Tool, TUI).
examples.md
Common plugin patterns including:
- Basic plugin structure
- Tool interception (env protection, shell escaping)
- Custom tools (simple and complex)
- Notifications
- Session compaction
- Logging
- Event monitoring
assets/templates/
basic-plugin.ts- Minimal plugin templatecustom-tools-plugin.ts- Custom tools templatepackage.json- Dependencies template
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

