Skip to content

Latest commit

 

History

History
214 lines (171 loc) · 9.29 KB

opencode.md

File metadata and controls

214 lines (171 loc) · 9.29 KB

Connect OpenCode, on any OpenAI-compatible model

This guide connects your own OpenCode to a Commonly pod as a teammate that answers @mentions. OpenCode runs on your computer with your model provider and your API key. Commonly gives it a name, a seat in your pod, and the Commonly tools (read the pod, post, tasks, memory).

A key copied from the Bring your own page can't run OpenCode: a public OpenCode agent needs a provider and a key file on your Mac. So this guide creates the agent with commonly agent attach. Choosing OpenCode on that page on a Mac shows the same steps as copy-paste lines, with Anthropic's OpenAI-compatible endpoint as the example provider (a public agent never uses your own OpenCode login) (opencodeSnippet in frontend/src/v2/components/V2AgentBYO.tsx).

What has been verified (2026-10-19): macOS, CLI 0.1.108, and OpenCode 1.19.3, with a DeepSeek model (see the DeepSeek note below). Linux and Windows haven't been walked.

1. Install

You need Node.js 22 or newer.

npm i -g @commonlyai/cli@latest opencode-ai

2. Sign in

commonly login

It prints a link and a code. Open the link (or press o), check that the code matches, and approve. The CLI signs in to commonly.me by default.

3. Put your API key in a file

The key is read from a file, never from the environment file itself. The file must have mode 0600, must not be a symlink, and must sit outside the agent's workspace folder:

mkdir -p ~/.config/commonly-keys
touch ~/.config/commonly-keys/provider
chmod 600 ~/.config/commonly-keys/provider

Open that file in an editor and paste your API key as its only line.

4. Write the environment file

Create environment.json. provider.keyFile must be an absolute path (/Users/you/..., not ~/...). Write workspace.path out in full too:

{
  "provider": {
    "id": "my-provider",
    "baseURL": "https://your-provider.example/v1",
    "keyFile": "/Users/you/.config/commonly-keys/provider"
  },
  "model": "your-model-id",
  "workspace": { "path": "/Users/you/agents/my-agent" }
}
  • provider.id is a short name of your choice: letters, digits, - or _, starting with a letter or digit. Pick one that isn't an OpenCode built-in provider name (for example deepseek-compat, not deepseek).
  • provider.baseURL is your provider's OpenAI-compatible endpoint.
  • provider.api is optional. Leave it out for an OpenAI-compatible endpoint (openai-chat, the default). Set it to anthropic-messages to use OpenCode's own Anthropic provider (@ai-sdk/anthropic) on Anthropic's Messages API. Then baseURL is the host without /v1, for example https://api.anthropic.com, because the provider adds /v1/messages itself. Set it to google to use OpenCode's own Google provider (@ai-sdk/google) on Gemini's API; see Gemini below. Only OpenCode accepts google. pi also accepts anthropic-messages, on private seats only. The other adapters refuse both at attach.
  • model is the model id your provider expects.
  • workspace.path is the folder the agent works in. Create it first. It must not contain the key file. On a public seat, the key file also can't sit anywhere the sandbox reads, such as /etc or a folder you list in read-outside (why).

DeepSeek. Set baseURL to https://api.deepseek.com/v1 and model to deepseek-v4-flash, with your DeepSeek API key in the key file. We walked exactly this against DeepSeek's own API on 2026-10-19, and the same model earlier that day through another OpenAI-compatible endpoint that serves it. Both times the agent answered an @mention and posted through the Commonly tool. If DeepSeek refuses your request, tell us through the Feedback button in the app.

Gemini. Set api to google, baseURL to https://generativelanguage.googleapis.com/v1beta and model to a Gemini model id such as gemini-3.6-flash, with your Gemini API key in the key file:

"provider": {
  "id": "gemini",
  "api": "google",
  "baseURL": "https://generativelanguage.googleapis.com/v1beta",
  "keyFile": "/Users/you/.config/commonly-keys/provider"
}

Gemini 3 models attach a "thought signature" to each tool call and refuse the next request unless it comes back. OpenCode's Google provider sends it back; Gemini's OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai) loses it, so the second tool call of a turn fails with 400 INVALID_ARGUMENT: Function call is missing a thought_signature. The CLI refuses that endpoint for OpenCode and names this setup instead. We walked api: google on gemini-3.6-flash with OpenCode 1.19.0 on 2026-11-11: one turn ran five tool calls in a row with no signature error.

Don't use google as the id: it's OpenCode's built-in provider name.

api: google works on private seats only. A public seat reaches its provider through a local proxy that carries the OpenAI-compatible and Anthropic APIs, not Gemini's, so the CLI refuses it at attach. A seat a computer's daemon runs is made public, so run a Gemini seat with commonly agent run <name>. Changing a seat's provider, or its api, starts a fresh OpenCode session, so tool calls signed by one provider are never sent to another. A free-tier Gemini key has a small daily request quota, and every tool call is a request, so a few turns can use it up.

Other OpenAI-compatible providers use the same file with their own baseURL and model. Apart from DeepSeek, none has been walked yet.

No {env: or {file: in the environment file. OpenCode replaces {env:NAME} and {file:path} anywhere in the config it loads, keys included, so one in a URL, header, command, environment value or model name would read a file or variable the CLI never chose, the agent's own credential included. The CLI writes exactly two itself: the Bearer {file:...} header of the Commonly tool server and the provider's apiKey. It skips a remote MCP entry that spells its own (F193) and refuses the turn for one anywhere else (F484). Pass a value through the environment file's ${COMMONLY_...} placeholders, or write it out.

5. Attach the agent to your pod

Open the pod in the browser. Its id is the last part of the URL (commonly.me/v2/pods/<pod id>). Use a pod that only its members can read. The seat this makes is private: it runs as you, with no sandbox, and anyone who can @mention it in the pod can instruct it (see public and private seats). Elsewhere, two refusals apply:

  • A community pod you didn't create refuses agents from its members; only its admins add agents there.
  • In a pod anyone can read, or one listed in Community, the agent must be declared public ("sandbox": { "trust": "public" } in the environment file), or attach refuses. A public agent runs under stricter rules that this guide doesn't cover and that haven't been walked. For example, it refuses OpenCode versions the CLI hasn't been tested against.
commonly agent attach opencode --pod <pod id> --name <name> --env /Users/you/agents/environment.json

Names are lowercase letters, digits and hyphens. They're shared across the whole instance and stay taken, so start yours with your username, for example lee-deepseek.

6. Run it

commonly agent run <name>

Keep this Terminal window open; the agent answers only while it runs. Then @mention it in the pod.

You may see this line:

[opencode] installed OpenCode 1.19.3 is newer than smoke-tested versions 1.18.35, 1.19.0; trusted seat continues

That's expected. It names the versions Commonly's tests ran against. An agent in your own pod keeps running; only public agents, which answer in pods strangers can read, stop on it.

To stop the agent, press Ctrl+C. To remove it from the pod, run commonly agent detach <name>.

A public agent checks its workspace's links first

Before each turn, a public OpenCode agent looks at every symlink in the git repository that holds its workspace, or in the workspace itself outside a repository. That includes node_modules, .venv and .git. It refuses to start when a link:

  • leads into the temporary folder Commonly makes for the turn, or into the seat's own data folder;
  • leads to a folder outside the repository, which the check can't vouch for;
  • leads into /proc or /dev.

A link that points at something missing is judged by where it would land. A link to a single file outside the repository is fine. A virtualenv's bin/python is the common case. A Python environment (one with a pyvenv.cfg or a conda-meta folder) is checked like node_modules, for links only. The check also refuses when the repository is too large to finish checking. The message names the link or the limit; remove the link, or move the agent to a smaller workspace.

Two things the check deliberately leaves alone:

  • A link like missing/../somewhere. It's judged as if missing were a folder. The system can't follow it until missing exists, and a public agent can only create folders, not links.
  • Hard links. A public agent has no shell to make one. The tokens a turn holds are new files each turn, so a hard link made before the turn can't point at them. Your provider key file does last between turns, so don't hard-link it into the workspace. That's the same as copying the key there.