agentleFS
ongyishenongyishen/agent-skills/skills/opencode-install-plugin/SKILL.md

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.

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
  1. Distinctive:

    Place plugin files in plugin directories:

    line 29
  2. Very specific:

    Create package.json in config directory with dependencies:

    line 38
  3. Very specific:

    Add plugins to opencode.json config:

    line 52
  4. Distinctive:

    Import types for type safety:

    line 93

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 information
  • client: OpenCode SDK client for AI interaction
  • $: Bun's shell API for command execution
  • directory: Current working directory
  • worktree: Git worktree path

Install from Local Files

Place plugin files in plugin directories:

  1. Project-level: .opencode/plugins/
  2. 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.json for external dependencies

Load Order

Plugins load in sequence:

  1. Global config (~/.config/opencode/opencode.json)
  2. Project config (opencode.json)
  3. Global plugin directory (~/.config/opencode/plugins/)
  4. 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 template
  • custom-tools-plugin.ts - Custom tools template
  • package.json - Dependencies template

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.