We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Loading Plugins

OpenCode automatically loads .ts and .js plugin files from these directories:

  • Project-level: .opencode/plugins/
  • Global: ~/.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);
      }
    });
  },
});

Plugin Dependencies

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.

Assignment

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.