# OpenCode now runs through Context Mode

October 29, 2026 Agents 6 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

- **Install OpenCode first**, with its own installer: `curl -fsSL https://opencode.ai/install | bash`.
- **Add your Anthropic API key** with `opencode auth login` (pick Anthropic), or set `ANTHROPIC_API_KEY`.
- **Connect it:** `npx @context-mode/cli setup --agent opencode`. It sets 2 keys in `~/.config/opencode/opencode.json`. It writes no API key.
- **Quit OpenCode and run it again.** The console shows these turns as OpenCode.
- **Undo** with `npx @context-mode/cli disconnect --agent opencode`. The file goes back as it was.
- **Limits:** The OpenAI provider and a ChatGPT login are not touched.

## 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

Install Key Setup Restart Check

```
$ 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](https://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](https://opencode.ai/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](https://github.com/anomalyco/opencode/pull/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:

- It shows the key-level change and asks before it writes.
- It copies the file to `<file>.cm-setup-bak-<timestamp>`, then writes atomically.
- It writes nothing if the file does not parse.
- If OpenCode's Anthropic provider already goes somewhere else, it asks before it replaces it, and `disconnect` puts the old one back.
- `--dry-run` shows the change and writes nothing. `--yes` skips the question, but never replaces another base URL; that needs `--replace-base-url`.

### 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](https://contextmode.ai/blog/seven-coding-agents-one-gateway) 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](https://opencode.ai/docs/providers/)). 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

Saving Memory Skills Instructions Recall Protect

```
$ 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.

| Feature | In OpenCode |
| --- | --- |
| [Saving](https://contextmode.ai/docs/how-saving-works) | Yes, every request |
| [Memory](https://contextmode.ai/docs/memory) | Yes, stored for OpenCode |
| [Skills](https://contextmode.ai/docs/skills) | Yes, every request |
| [Instructions](https://contextmode.ai/docs/instructions) | Yes, every request |
| [Recall](https://contextmode.ai/docs/recall) and [Search](https://contextmode.ai/docs/search) | Yes, every request |
| [Active Context](https://contextmode.ai/docs/active-context) | Yes, every request |
| [Session resume](https://contextmode.ai/docs/session-resume) | No |
| "⏺ contextmode" line | Shows 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](https://contextmode.ai/docs/memory).

## Tips

- **OpenCode's OpenAI provider and a ChatGPT login are not touched.** Setup changes only the Anthropic provider.
- **You need your own Anthropic API key.** If OpenCode's Anthropic login is a Claude subscription token, setup warns you first: Anthropic answers a Claude subscription used from another app with a 400. That answer comes from Anthropic, not from Context Mode.
- **The "⏺ contextmode" line** shows in `opencode run`.

## 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](https://console.contextmode.ai/login) to see your workspace.

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

- Console: [console.contextmode.ai](https://console.contextmode.ai) ([start free](https://console.contextmode.ai/login))
- CLI: `npx @context-mode/cli`
- Docs: [Quick start](https://contextmode.ai/docs/quick-start) and [the CLI](https://contextmode.ai/docs/cli)

The other apps, each with its makers' own install: [Claude Desktop](https://contextmode.ai/blog/claude-desktop-context-mode), [the ChatGPT desktop app](https://contextmode.ai/blog/codex-desktop-context-mode), [Pi](https://contextmode.ai/blog/pi-coding-agent-context-mode) and [T3 Code](https://contextmode.ai/blog/t3-code-context-mode). Context Mode is under the Elastic License 2.0 (ELv2).

[Get started free](https://console.contextmode.ai/login) [All posts](https://contextmode.ai/blog)
