OpenCode now runs through Context Mode

Agents6 min read

Thanks to the OpenCode team for an open agent that lets you choose where its requests go. Today OpenCode connects to Context Mode with one command. You keep OpenCode, your model and your own Anthropic API key. Setup sets 2 keys in OpenCode's own config file, and every request then goes through Saving, Skills, Instructions and Recall, and Memory brings back your facts in each new conversation. Install OpenCode the way its makers do it, then run the Context Mode command.

TL;DR

How to connect OpenCode to Context Mode

This post answers one question: how do you connect OpenCode to Context Mode? Four steps. The first two are OpenCode's own. Pick a step to see the exact command and what it does.

Step
$ curl -fsSL https://opencode.ai/install | bash
# or: npm install -g opencode-ai
# or: brew install anomalyco/tap/opencode

OpenCode's own installer, from opencode.ai/docs.

$ opencode auth login
# pick Anthropic, paste your API key
# or: export ANTHROPIC_API_KEY=...

OpenCode has no Claude sign-in since 1.3.0, so it needs your own Anthropic API key.

$ npx @context-mode/cli setup --agent opencode
OpenCode: ~/.config/opencode/opencode.json
  set provider.anthropic.options.baseURL = https://gateway.contextmode.ai/v1
  set provider.anthropic.options.headers.x-cm-device-key
Write these changes? y
Backup of the original: opencode.json.cm-setup-bak-<timestamp>

It shows the change, asks first, makes a backup, and never prints your key.

# quit OpenCode, then
$ opencode

OpenCode reads its config at start, so a running session keeps the old route.

$ npx @context-mode/cli setup --agent opencode --check
OpenCode: configured (~/.config/opencode/opencode.json)
$ npx @context-mode/cli doctor

Then ask OpenCode anything. Your request shows on the console as OpenCode.

1. Install OpenCode its own way

Use the command OpenCode's makers give in their docs. Pick one:

curl -fsSL https://opencode.ai/install | bash     # or: npm install -g opencode-ai, or: brew install anomalyco/tap/opencode

2. Give OpenCode your Anthropic API key

OpenCode removed the Claude sign-in in 1.3.0 (PR #18186). So it needs your own Anthropic API key. Store it with OpenCode's own command, opencode auth login (pick Anthropic), or set ANTHROPIC_API_KEY. Context Mode setup never writes this key.

3. Run the Context Mode command

npx @context-mode/cli setup --agent opencode

It needs Node 20.12 or later. If this terminal is not signed in yet, run npx @context-mode/cli first: it signs you in and gives this terminal a device key (cmdk_…), stored in ~/.context-mode/credentials.json. Setup then sets 2 keys in OpenCode's own config, ~/.config/opencode/opencode.json. An existing opencode.jsonc is edited in place, with its comments kept.

{ "provider": { "anthropic": { "options": {
  "baseURL": "https://gateway.contextmode.ai/v1",
  "headers": { "x-cm-device-key": "<your device key>" }
} } } }

That is all it changes. Every other key in the file stays. It writes no API key: OpenCode sends your own key, and the gateway passes it on unchanged. The gateway removes the device key before the request goes to Anthropic.

How setup behaves:

4. Quit OpenCode and run it again

OpenCode reads its config at start. Quit it, run opencode again, and ask it anything. In opencode run, a line that starts with "⏺ contextmode" shows with the answer. Your request shows on the console as OpenCode.

Or connect OpenCode with the others in one command

Do you use more than one coding agent? Run the CLI with no arguments. It signs you in, lists the apps it finds (found ones checked), and sets up the ones you pick. OpenCode is in that list. It is not part of --agent all, which covers Claude Code and Codex.

$ npx @context-mode/cli
# pick OpenCode (and any other app) in the list, press Enter
OpenCode     connected (workspace …)
Console: https://console.contextmode.ai
Ready

Each app gets one check request through the gateway before you see Ready. The same picker covers Claude Code, Claude Desktop, Codex, Codex Desktop, T3 Code, OpenCode and Pi. Read one gateway for seven coding agents for the full list.

Does OpenCode work with a gateway?

Yes. OpenCode lets you set a baseURL and headers for each provider in its own config (OpenCode providers docs). Context Mode uses only that. There is no plugin, no wrapper and no fork. We checked it with the real opencode binary, opencode-ai 1.19.4: every request is POST /v1/messages with the device key and your key, and the console names it OpenCode.

What you get in OpenCode

The gateway does not switch features on or off by app. These run on every OpenCode request. Pick a feature to see what it does.

Feature
$ opencode run "run the tests and fix the failing one"
# the test run prints every result
# the model gets the failing test, its error and the summary line
# the passed results stay out of the context

Large tool output (logs, fetched pages, big files) stays out of the model's context. Works on every request.

Example. Monday, in OpenCode:
"We deploy to Render now, not Hetzner."
Thursday, a new OpenCode session:
"Where do we deploy?"
Render. It was Hetzner before.

Rules, decisions and preferences come back in later sessions. Stored for OpenCode, with the session from OpenCode's own session header.

You, in OpenCode:
"use release-notes for this sprint"
# the release-notes skill loads for this turn

Import skills once, for example from GitHub. They run from the gateway, so there is nothing to install on each machine. Works on every request.

// Console: Settings → Instructions
Keep answers short. No wall of text.
Never touch code or technical terms.

Write it once. Every OpenCode request carries it. If your message and the Instructions disagree, your message wins.

You, in OpenCode:
"what did we decide about the quota check?"
# the agent reads the decision back from the archive

Long history is archived, not lost. The agent reads older work back when it needs it. Works on every request.

$ git push origin main
# Claude Code, Codex: blocked by your rule

Protect is enforced on Claude Code and Codex.

FeatureIn OpenCode
SavingYes, every request
MemoryYes, stored for OpenCode
SkillsYes, every request
InstructionsYes, every request
Recall and SearchYes, every request
Active ContextYes, every request
Session resumeNo
"⏺ contextmode" lineShows in opencode run

Memory for OpenCode

With Context Mode, what you told OpenCode last week comes back: "we deploy to Render", "use pnpm", "no default exports". Memory stores these for OpenCode and tells sessions apart by the session id OpenCode sends, so a new session gets the facts from the ones before. When a value changes, the old one is closed, not deleted. Read how Memory works.

Tips

How to undo it

npx @context-mode/cli disconnect --agent opencode

The file goes back as it was. A backup comes first, and it works offline. Check any time with npx @context-mode/cli status: who is signed in, and each agent's setup.

Start now

Install OpenCode, add your Anthropic key, then run one command. Open the Console to see your workspace.

npx @context-mode/cli setup --agent opencode

The other apps, each with its makers' own install: Claude Desktop, the ChatGPT desktop app, Pi and T3 Code. Context Mode is under the Elastic License 2.0 (ELv2).

Get started free

Your coding agent costs less and remembers your project.

Start free: 1,000 requests, every feature, no card. After you sign in, the console gives you one command to connect your coding agent.

Read the docs