opencode-extensions
Build OpenCode extensions with Bun.js/TypeScript. Use when creating plugins, custom tools, agents, commands, skills, rules (AGENTS.md), or opencode.json configurations. Triggers on requests involving .opencode/ directory, OpenCode SDK, MCP servers, or any OpenCode extension development.
- License 许可
- MPL-2.0
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- opencode-extensions
- updated
- 1773532800000
- description
- Build OpenCode extensions with Bun.js/TypeScript. Use when creating plugins, custom tools, agents, commands, skills, rules (AGENTS.md), or opencode.json configurations. Triggers on requests involving .opencode/ directory, OpenCode SDK, MCP servers, or any OpenCode extension development.
- when_to_use
- Use this skill when you need to extend OpenCode's functionality with custom plugins, tools, agents, commands, or rules; specifically for creating hooks that intercept tool execution, handling session events like idle or errors, adding custom capabilities via the tool API, or configuring global settings in opencode.json.
02 资源文件 26
- 参考文档references/acp.md3.9 KB
- 参考文档references/agents-docs.md14.8 KB
- 参考文档references/agents.md2.4 KB
- 参考文档references/cli.md12.6 KB
- 参考文档references/commands.md6.7 KB
- 参考文档references/config-docs.md15.0 KB
- 参考文档references/config.md2.8 KB
- 参考文档references/custom-tools.md4.3 KB
- 参考文档references/ecosystem.md5.0 KB
- 参考文档references/formatters.md4.4 KB
- 参考文档references/mcp-servers.md11.8 KB
- 参考文档references/models.md6.0 KB
- 参考文档references/network.md2.1 KB
- 参考文档references/permissions.md6.5 KB
- 参考文档references/plugins-docs.md9.1 KB
- 参考文档references/plugins.md2.8 KB
- 参考文档references/providers.md32.9 KB
- 参考文档references/rules.md5.5 KB
- 参考文档references/sdk-docs.md11.5 KB
- 参考文档references/sdk.md3.8 KB
- 参考文档references/server.md13.0 KB
- 参考文档references/share.md3.4 KB
- 参考文档references/skills.md4.8 KB
- 参考文档references/tools.md7.8 KB
- 参考文档references/troubleshooting.md4.9 KB
- 参考文档references/tui.md6.7 KB
03 SKILL.md 正文
OpenCode Extension Development
Build plugins, tools, agents, commands, skills, and configurations for OpenCode using Bun.js and TypeScript.
When to Use
Use this skill when you need to extend OpenCode's functionality with custom plugins, tools, agents, commands, or rules. Specifically use this for:
- Creating hooks that intercept tool execution (e.g.,
tool.execute.before) - Handling session lifecycle events (e.g.,
session.idle,session.error) - Adding custom capabilities via the tool API
- Configuring global settings in
opencode.json - Developing system-wide extensions located in
~/.config/opencode/
Extension Types
| Type | Location | Format |
|---|---|---|
| Plugin | .opencode/plugin/ |
.ts/.js |
| Tool | .opencode/tool/ |
.ts/.js |
| Agent | .opencode/agent/ |
.md or JSON |
| Command | .opencode/command/ |
.md or JSON |
| Skill | .opencode/skill/<n>/SKILL.md |
.md |
| Rules | AGENTS.md |
.md |
| Config | opencode.json |
.json |
Note: Global location is ~/.config/opencode/ instead of .opencode/ for system-wide extensions.
Plugin Development
Plugins extend OpenCode with hooks and custom tools. They are the primary mechanism for intercepting execution flow and managing lifecycle events.
import { type Plugin, tool } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async ({ project, client, $, directory }) => ({
// Event handler
event: async ({ event }) => {
if (event.type === "session.idle") console.log("Done!")
},
// Intercept tool execution
"tool.execute.before": async (input, output) => {
if (input.tool === "read" && output.args.filePath.includes(".env")) {
throw new Error("Cannot read .env files")
}
},
// Add custom tools
tool: {
greet: tool({
description: "Greet a user",
args: { name: tool.schema.string() },
async execute(args) { return `Hello, ${args.name}!` }
})
}
})
Events: session.idle, session.error, session.created, file.edited, message.updated, tool.execute.before, tool.execute.after
For dependencies, create .opencode/package.json with required packages.
Custom Tool Development
Tools are standalone functions defined via the SDK. They appear in the tool list for LLMs to invoke.
import { tool } from "@opencode-ai/plugin"
export default tool({
description: "Tool description for LLM",
args: {
query: tool.schema.string().describe("SQL query"),
limit: tool.schema.number().optional().default(10)
},
async execute(args, context) {
const { agent, sessionID } = context
return `Executed: ${args.query}`
}
})
Naming Convention: Filename becomes tool name. Multiple exports create <file>_<export> tools.
Agent Definition
Agents are defined in Markdown files within .opencode/agent/ or system config.
Create .opencode/agent/reviewer.md:
# Reviewer Agent
You are a code reviewer. Analyze the provided code for bugs, security issues, and best practices.
## Instructions
- Check for null pointer exceptions
- Verify input validation
- Suggest performance improvements
04 同仓库更多 Skills
tax-filing-checklist
Walk through the steps and documents needed to file an individual federal income tax return
patient-vitals-charting
Record patient vital signs consistently and flag values outside the normal reference range
pasta-from-scratch
Make fresh egg pasta dough from scratch, roll it, and cut it into shapes
knife-sharpening
Sharpen and hone kitchen knives to keep an edge safe and effective
first-aid-response
Respond to a first aid emergency using a scene-safety-first, ABC-based (airway, breathing, circulation) approach
contract-review-basics
Review a contract draft for missing terms, ambiguous language, and risky clauses before signing