

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Plugins
incomplete
2: Loading Plugins
incomplete
3: Install Plugins
incomplete
4: Plugin Transforms
incomplete
5: Plugin Hooks
incomplete
6: Plugin Tools
incomplete
7: Publishing Plugins
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
OpenCode automatically loads .ts and .js plugin files from these directories:
.opencode/plugins/~/.config/opencode/plugins/Project plugins are for team behavior in a given repo; global plugins (i.e., global to your system user account) are personal.
For example, the plugin that maintains an audit log for a project belongs at .opencode/plugins/audit-log.ts:
import { appendFile } from "node:fs/promises";
import { join } from "node:path";
import { Plugin } from "@opencode/plugin";
export default Plugin.define({
id: "bootdev.audit-log",
setup: async (ctx) => {
const logPath = join(ctx.location.directory, "audit.jsonl");
await ctx.tool.hook("execute.after", async (event) => {
const entry = {
timestamp: new Date().toISOString(),
sessionID: event.sessionID,
tool: event.tool,
status: event.status,
};
try {
await appendFile(logPath, JSON.stringify(entry) + "\n");
} catch (error) {
console.error("could not write audit log:", error);
}
});
},
});
Since the plugin code imports from @opencode/plugin, you'll also need to add a package.json file in the .opencode directory with that dependency listed:
{
"name": "course-learn-ai-coding",
"private": true,
"type": "module",
"dependencies": {
"@opencode/plugin": "2.0.3"
}
}
Run bun install from .opencode to install local plugin dependencies. You'll want to .gitignore the node_modules directory.
Use a local plugin to log commands that interact with the playground server.
Tell OpenCode to run and submit the CLI tests from the project root.