A minimal starting point for building OpenCode plugins with TypeScript and configuration support.
bun installbun run buildEdit ~/.config/opencode/opencode.json:
{
"plugins": ["/path/to/this/directory"]
}Use
"plugins": ["opencode-plugin-template"]if you publish to npm.
Create a config file at ~/.config/opencode/my-plugin.json:
{
"customSetting": "hello world",
"debug": true
}Or for project-specific settings, create .opencode/my-plugin.json in your project root. Project configs override user configs.
Both .json and .jsonc (with comments) formats are supported.
.
├── src/
│ ├── index.ts # Plugin entry point — exports a Plugin function
│ └── config.ts # Config loading with user + project override support
├── package.json # opencode.plugin = true marks this as a plugin
├── tsconfig.json # TypeScript config targeting ESNext + bundler resolution
├── bunfig.toml # Bun test configuration with coverage
├── .prettierrc # Code formatting rules
└── .husky/ # Git hooks for lint-staged, tests, and gitleaks
- Rename
PLUGIN_NAMEinsrc/config.tsfrom"my-plugin"to your plugin's name. - Update
package.jsonname,description, andauthor. - Add hooks in
src/index.ts— see the OpenCode plugin API docs for available hooks (config,systemTransform,beforeRequest, etc.). - Run
bun run buildafter any changes.
bun run build # Compile TypeScript to dist/
bun test # Run tests with coverage
bun run format # Format code with Prettier
bun run format:check # Check formatting without writingnpm publishUsers can then install via:
{
"plugins": ["your-plugin-name"]
}MIT