Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions packages/web/src/content/docs/plugins.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Plugins
description: Write your own plugins to extend OpenCode.
description: Write your own plugins to extend MiMo Code.
---

Plugins allow you to extend OpenCode by hooking into various events and customizing behavior. You can create plugins to add new features, integrate with external services, or modify OpenCode's default behavior.
Plugins allow you to extend MiMo Code by hooking into various events and customizing behavior. You can create plugins to add new features, integrate with external services, or modify MiMo Code's default behavior.

For examples, check out the [plugins](/docs/ecosystem#plugins) created by the community.

Expand All @@ -19,8 +19,8 @@ There are two ways to load plugins.

Place JavaScript or TypeScript files in the plugin directory.

- `.opencode/plugins/` - Project-level plugins
- `~/.config/opencode/plugins/` - Global plugins
- `.mimocode/plugins/` - Project-level plugins
- `~/.config/mimocode/plugins/` - Global plugins

Files in these directories are automatically loaded at startup.

Expand All @@ -30,7 +30,7 @@ Files in these directories are automatically loaded at startup.

Specify npm packages in your config file.

```json title="opencode.json"
```json title="mimocode.json"
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-helicone-session", "opencode-wakatime", "@my-org/custom-plugin"]
Expand All @@ -45,7 +45,7 @@ Browse available plugins in the [ecosystem](/docs/ecosystem#plugins).

### How plugins are installed

**npm plugins** are installed automatically using Bun at startup. Packages and their dependencies are cached in `~/.cache/opencode/node_modules/`.
**npm plugins** are installed automatically using Bun at startup. Packages and their dependencies are cached in `~/.cache/mimocode/node_modules/`.

**Local plugins** are loaded directly from the plugin directory. To use external packages, you must create a `package.json` within your config directory (see [Dependencies](#dependencies)), or publish the plugin to npm and [add it to your config](/docs/config#plugins).

Expand All @@ -55,10 +55,10 @@ Browse available plugins in the [ecosystem](/docs/ecosystem#plugins).

Plugins are loaded from all sources and all hooks run in sequence. The load order is:

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/`)
1. Global config (`~/.config/mimocode/mimocode.json`)
2. Project config (`mimocode.json`)
3. Global plugin directory (`~/.config/mimocode/plugins/`)
4. Project plugin directory (`.mimocode/plugins/`)

Duplicate npm packages with the same name and version are loaded once. However, a local plugin and an npm plugin with similar names are both loaded separately.

Expand All @@ -75,17 +75,17 @@ functions. Each function receives a context object and returns a hooks object.

Local plugins and custom tools can use external npm packages. Add a `package.json` to your config directory with the dependencies you need.

```json title=".opencode/package.json"
```json title=".mimocode/package.json"
{
"dependencies": {
"shescape": "^2.1.0"
}
}
```

OpenCode runs `bun install` at startup to install these. Your plugins and tools can then import them.
MiMo Code runs `bun install` at startup to install these. Your plugins and tools can then import them.

```ts title=".opencode/plugins/my-plugin.ts"
```ts title=".mimocode/plugins/my-plugin.ts"
import { escape } from "shescape"

export const MyPlugin = async (ctx) => {
Expand All @@ -103,7 +103,7 @@ export const MyPlugin = async (ctx) => {

### Basic structure

```js title=".opencode/plugins/example.js"
```js title=".mimocode/plugins/example.js"
export const MyPlugin = async ({ project, client, $, directory, worktree }) => {
console.log("Plugin initialized!")

Expand All @@ -118,7 +118,7 @@ The plugin function receives:
- `project`: The current project information.
- `directory`: The current working directory.
- `worktree`: The git worktree path.
- `client`: An opencode SDK client for interacting with the AI.
- `client`: A MiMo Code SDK client for interacting with the AI.
- `$`: Bun's [shell API](https://bun.com/docs/runtime/shell) for executing commands.

---
Expand Down Expand Up @@ -210,21 +210,21 @@ Plugins can subscribe to events as seen below in the Examples section. Here is a

## Examples

Here are some examples of plugins you can use to extend opencode.
Here are some examples of plugins you can use to extend MiMo Code.

---

### Send notifications

Send notifications when certain events occur:

```js title=".opencode/plugins/notification.js"
```js title=".mimocode/plugins/notification.js"
export const NotificationPlugin = async ({ project, client, $, directory, worktree }) => {
return {
event: async ({ event }) => {
// Send notification on session completion
if (event.type === "session.idle") {
await $`osascript -e 'display notification "Session completed!" with title "opencode"'`
await $`osascript -e 'display notification "Session completed!" with title "MiMo Code"'`
}
},
}
Expand All @@ -234,16 +234,16 @@ export const NotificationPlugin = async ({ project, client, $, directory, worktr
We are using `osascript` to run AppleScript on macOS. Here we are using it to send notifications.

:::note
If you’re using the OpenCode desktop app, it can send system notifications automatically when a response is ready or when a session errors.
If you’re using the MiMo Code desktop app, it can send system notifications automatically when a response is ready or when a session errors.
:::

---

### .env protection

Prevent opencode from reading `.env` files:
Prevent MiMo Code from reading `.env` files:

```javascript title=".opencode/plugins/env-protection.js"
```javascript title=".mimocode/plugins/env-protection.js"
export const EnvProtection = async ({ project, client, $, directory, worktree }) => {
return {
"tool.execute.before": async (input, output) => {
Expand All @@ -261,7 +261,7 @@ export const EnvProtection = async ({ project, client, $, directory, worktree })

Inject environment variables into all shell execution (AI tools and user terminals):

```javascript title=".opencode/plugins/inject-env.js"
```javascript title=".mimocode/plugins/inject-env.js"
export const InjectEnvPlugin = async () => {
return {
"shell.env": async (input, output) => {
Expand All @@ -276,9 +276,9 @@ export const InjectEnvPlugin = async () => {

### Custom tools

Plugins can also add custom tools to opencode:
Plugins can also add custom tools to MiMo Code:

```ts title=".opencode/plugins/custom-tools.ts"
```ts title=".mimocode/plugins/custom-tools.ts"
import { type Plugin, tool } from "@mimo-ai/plugin"

export const CustomToolsPlugin: Plugin = async (ctx) => {
Expand All @@ -299,13 +299,13 @@ export const CustomToolsPlugin: Plugin = async (ctx) => {
}
```

The `tool` helper creates a custom tool that opencode can call. It takes a Zod schema function and returns a tool definition with:
The `tool` helper creates a custom tool that MiMo Code can call. It takes a Zod schema function and returns a tool definition with:

- `description`: What the tool does
- `args`: Zod schema for the tool's arguments
- `execute`: Function that runs when the tool is called

Your custom tools will be available to opencode alongside built-in tools.
Your custom tools will be available to MiMo Code alongside built-in tools.

:::note
If a plugin tool uses the same name as a built-in tool, the plugin tool takes precedence.
Expand All @@ -317,7 +317,7 @@ If a plugin tool uses the same name as a built-in tool, the plugin tool takes pr

Use `client.app.log()` instead of `console.log` for structured logging:

```ts title=".opencode/plugins/my-plugin.ts"
```ts title=".mimocode/plugins/my-plugin.ts"
export const MyPlugin = async ({ client }) => {
await client.app.log({
body: {
Expand All @@ -338,7 +338,7 @@ Levels: `debug`, `info`, `warn`, `error`. See [SDK documentation](https://openco

Customize the context included when a session is compacted:

```ts title=".opencode/plugins/compaction.ts"
```ts title=".mimocode/plugins/compaction.ts"
import type { Plugin } from "@mimo-ai/plugin"

export const CompactionPlugin: Plugin = async (ctx) => {
Expand All @@ -362,7 +362,7 @@ The `experimental.session.compacting` hook fires before the LLM generates a cont

You can also replace the compaction prompt entirely by setting `output.prompt`:

```ts title=".opencode/plugins/custom-compaction.ts"
```ts title=".mimocode/plugins/custom-compaction.ts"
import type { Plugin } from "@mimo-ai/plugin"

export const CustomCompactionPlugin: Plugin = async (ctx) => {
Expand Down