# OpenCode

Send a Pushbag notification when OpenCode finishes a turn and give the agent a packaged publishing guide.

OpenCode V2 exposes session activity through server plugins. Subscribe to the idle event to send a message when a session goes quiet. Idle alone does not indicate that tests passed.

## Install the skill

Complete the [CLI quickstart](/docs) on the machine running OpenCode. For notifications alone, use a Notifications key granted access to Personal. Install the packaged skill from your project directory:

```sh
pushbag guide pushbag --install
pushbag notify "OpenCode setup check"
```

The project installation writes `.agents/skills/pushbag/SKILL.md` under the Git root, or the current directory outside Git. The installed guide describes artifact publishing. The plugin below is a separate server-side entrypoint. Use the V2 plugin API for this example. Confirm the setup check appears in Personal. The hook process needs the same CLI on its PATH and access to the saved profile or `PUSHBAG_API_KEY`.

## Configure completion notifications

Add the following to `opencode.json`, merging with any existing configuration.

```json
{
  "plugins": [
    "./plugins/pushbag"
  ]
}
```

For OpenCode V2, create `plugins/pushbag/index.ts` relative to the directory containing `opencode.json`. The server plugin listens for a session becoming idle.

```ts
import { execFile } from "node:child_process";
import { Plugin } from "@opencode/plugin";

export default Plugin.define({
  id: "pushbag",
  setup(context) {
    const controller = new AbortController();
    async function listen() {
      for await (const event of context.event.subscribe({ signal: controller.signal })) {
        if (event.type === "session.idle") {
          execFile("pushbag", ["notify", "OpenCode session idle"], (error) => {
            if (error) console.error(error.message);
          });
        }
      }
    }
    void listen().catch((error) => {
      if (!controller.signal.aborted) console.error(error);
    });
    return () => controller.abort();
  }
});
```

Start a turn in OpenCode and ask it to summarize a file. When it finishes, check Personal in the dashboard or in the Inbox on your phone. See the [OpenCode hook reference](https://opencode.ai/docs/build/plugins/migrate-v1/).


## Identify the project in the notification

Import `basename` from `node:path`. Replace the argument array passed to `execFile` with the following. The plugin context supplies the project directory even when the server starts elsewhere:

```ts
["notify", `OpenCode idle in ${basename(context.location.directory)}`]
```

## Publish a report on idle

For a report-producing session, give the server a Both key with access to Personal. Import `existsSync` from `node:fs` and `join` from `node:path`. Inside the idle branch replace the notification call with:

```ts
const report = join(context.location.directory, "review.html");
if (existsSync(report)) {
  execFile("pushbag", ["upload", report, "--private", "--notify"], (error) => {
    if (error) console.error(error.message);
  });
}
```

Ask OpenCode to create that file, allow the session to become idle and open the resulting version link from Personal. Each idle event can upload another copy while the report exists. Move the file when the review is over.

## Troubleshooting

Use the server process environment when checking the key and PATH. A V1 plugin export cannot run under the V2 API. Check that the configured path points to the directory containing index.ts. Run `command -v pushbag` in the environment that launches the agent. If PATH differs from your shell, use the absolute executable path. Run `pushbag config show` and `pushbag whoami` there to check for a missing key or unexpected account. A Notifications key can send the setup message but lacks upload access. For report uploads use a Both key with a grant for the target channel. See [key presets](/docs/keys).

## Packaged skill example

```sh
pushbag upload report.html --notify
pushbag upload report.html --notify --channel CHANNEL_ID
pushbag upload report.html --notify --title "Report ready" --priority high --json
```
