Docs

Agents

OpenCode

Set up the Comity plugin and MCP server for OpenCode.

On this page

OpenCode has no command-hook config, so Comity integrates through an OpenCode plugin: a TypeScript module that OpenCode loads from .opencode/plugins/ at startup and that forwards its events to comity hook.

Set up

Terminal
cd your-repo
comity init --tools opencode
git add .opencode/plugins/comity.ts opencode.json
git commit -m "Set up Comity for OpenCode"

Start opencode from the repository root. There is no token in the repo: comity login is enough.

What init writes

.opencode/plugins/comity.ts

The bridge plugin (first line // comity-opencode-bridge v1 (comity hook)). It:

  • reports session.created, every prompt (chat.message), tool.execute.before and tool.execute.after for bash, edit, multiedit, write and apply_patch, session.idle (end of a turn) and session.deleted;
  • blocks a tool call Comity denies (OpenCode cancels a tool whose plugin hook throws) and shows Comity's reason to the model;
  • adds the session briefing and prompt context to the next system prompt, and appends post-tool context to the tool's output;
  • runs comity hook --tool opencode per event and allows after 5 seconds or when the CLI is missing.

Reads and searches never leave the process. The file holds no token and no machine path; re-running init rewrites it and comity doctor warns when it is from another CLI version.

opencode.json

JSON
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "comity": {
      "type": "local",
      "command": ["node", "-e", "<launcher>", "mcp"],
      "enabled": true
    }
  }
}

OpenCode starts comity mcp, a local proxy to the Comity server that authenticates with your comity login (or COMITY_TOKEN). The entry is the same on every OS, so the committed file never changes between teammates; it needs Node on PATH (the CLI needs it anyway). <launcher> stands for a one-line Node script that starts comity mcp through your shell, so it finds the npm comity shim on every OS. Your other settings and servers are kept. If the repo only has opencode.jsonc, init writes there.

Verify

Terminal
comity doctor
opencode mcp list

Expect opencode plugin .opencode/plugins/comity.ts is current and opencode mcp comity server in opencode.json; opencode mcp list should show comity connected.

Limits

  • The prompt context uses OpenCode's experimental.chat.system.transform hook; it may change between OpenCode releases.
  • Re-writing opencode.jsonc drops its comments.