Connect OpenCode
Use your own OpenCode agent as a Granular chat engine. Install it in one click, connect a provider such as OpenRouter or Anthropic (or reuse one you added in Granular), then pick its models.
Updated 2026-10-20
OpenCode is a free, open-source AI coding agent. Granular can use it as the engine behind a chat, with any AI provider OpenCode supports, such as OpenRouter, Anthropic or OpenAI. If you've already signed in to OpenRouter or added a provider key in Granular, OpenCode can use that straight away.
Before you start
- One of these:
- An OpenRouter sign-in or a provider key you've already added in Granular (see Sign in with OpenRouter and Connect other AI providers), or
- An account or API key with a provider OpenCode supports, which you connect inside OpenCode.
- OpenCode's own free models don't work inside Granular (see Limits).
- On Windows, the one-click install needs Node.js. If it's missing, Granular says so and links to it.
Set it up
- In the row of controls under the message box, click the button that shows your current connection's name.
- Click Add your AI agent.
- Under Coding agents, click OpenCode. Its tag says Install, Sign in or Ready, and its price tag says Free + model (OpenCode is free; you pay for the AI model you connect to it).
- If OpenCode isn't installed yet, a panel says "OpenCode needs a one-time install". Click Install for me. Granular types the official install command into the chat's Terminal tool so you can watch it run, then carries on by itself once OpenCode is found.
- If OpenCode still needs a provider, it opens in the Terminal tool with the panel Connect a provider to OpenCode. Pick a provider there, then paste its API key or sign in.
- An OpenCode row appears in your Accounts list and the chat switches to it.
If the tag already says Ready, OpenCode is using an account you added in Granular. Point at the row to see which one, for example "Uses your OpenRouter account".
What you'll see
- The OpenCode row in Accounts names the providers OpenCode can use.
- The model button under the message box lists the models OpenCode can reach through those providers. You can search the list and pin favourites. See Pick and pin models.
- OpenCode's own free models appear greyed out, with the reason when you point at them.
- When the agent runs a command, it runs in the chat's Terminal tool where you can see it. File changes go through Granular too, so they show in the chat.
Change or undo it
- Connect another provider: run
opencode auth loginin the chat's Terminal tool and follow OpenCode's steps. - Stop using it in a chat: pick another account from the connection button.
- Hide it: open Settings → AI accounts and click Hide from picker on OpenCode's card. OpenCode stays set up; Granular just stops showing and using it. See Manage your AI accounts.
- Sign out of a provider inside OpenCode: run
opencode auth logoutin a terminal.
Limits
- OpenCode's free models don't work in Granular. OpenCode only lets its free models run when its own command tool is switched on. Granular switches it off so that every command runs in your visible terminal, so those models are shown greyed out. Use a provider of your own instead.
- OpenCode's own command and edit tools are off. The agent uses Granular's terminal and file tools instead, so you can see every command and change.
- Costs depend on the provider OpenCode uses. Granular doesn't charge for OpenCode chats.
- Your OpenCode settings aren't changed. Granular passes its settings, and any key it lends OpenCode, for each reply only. If you've also signed in inside OpenCode, OpenCode's own sign-in is used first.
Troubleshooting
If you see "OpenCode's free models only work inside OpenCode's own app, so Granular can't use them"
Pick a model from a provider you've connected, or connect one by running opencode auth login in the terminal.
If the install finished but Granular can't see OpenCode
Click I've installed it - check again in the install panel. If that doesn't find it, quit Granular completely and open it again.
If the Windows install says it needs Node.js
Install Node.js from the link in the panel, or install OpenCode with Scoop (scoop install opencode) or Chocolatey (choco install opencode), then click I've installed it - check again.