Skip to main content

OpenCode

Point OpenCode's providers at the gateway with one anyray-connect command.

What's specific to OpenCode

PropertyValue
TypeClient tool (points at the gateway)
Configured byanyray-connect --tools opencode
What changesAn Anyray provider block in ~/.config/opencode/opencode.json, plus the global plugins/anyrayTrim.js output carrier
AttributionPer-user key + x-anyray-metadata, written into the provider block
ScopeChat and agent via the routed providers — OpenCode's built-in ChatGPT OAuth is left untouched

Everything shared — self-hosting, how the gateway reaches providers — is documented once in the gateway.

Connect it

npx anyray-connect --gateway http://<gateway>:8787 --tools opencode

This merges an Anyray provider into opencode.json, preserving every other provider and option (it backs the file up first; --revert removes only the keys it added). Enroll with --enroll <link> (or --sso) first; Connect makes no changes without a valid personal ark_… key. Use --dry-run to preview. Restart OpenCode afterward.

Omit --tools opencode to configure all detected tools. See Connect your tools.

Tool-output trimming

OpenCode's supported tool.execute.after plugin hook exposes the completed string output before OpenCode stores it in the session. Connect installs a small global carrier at ~/.config/opencode/plugins/anyrayTrim.js. The carrier invokes the same __anyray-hook runtime used by Claude Code and Cursor, then replaces the source output only when that runtime returns a smaller result. The OpenCode source mode does not write raw-output tees or the disk-backed verdict cache, so adding this carrier never creates a new plaintext content store outside ANYRAY_CONTENT_MODE. Failures keep the original output.

The carrier is installed only when the Connect binary is at a durable path. Connect reports when it has to skip the carrier, and gateway-side optimization remains active. --revert removes the carrier only when the file is owned by Connect; a user file at the same path is left untouched.

Copilot subscription seat

If you connect with a GitHub Copilot plan, Connect also adds a github-copilot provider that routes through the gateway's Copilot seat (/v1/copilot/<plan>/header). OpenCode's supported options.headers setting carries x-anyray-api-key separately from its GitHub bearer, so the personal gateway credential never appears in the URL. Pick the github-copilot/* models in OpenCode — e.g. github-copilot/claude-sonnet-4.5 — to spend your Copilot subscription. The anthropic/* and openai/* entries are the direct providers (api-key mode, separate billing), not your Copilot plan.

The route uses GitHub's generic Copilot API host. Set ANYRAY_COPILOT_PLAN=individual|business|enterprise only if your organization enforces a plan-specific host.

Manual setup

If anyray-connect can't write the config automatically, it prints these steps:

1
Open the config
Edit ~/.config/opencode/opencode.json (create it if absent).
2
Add the Anyray provider
Under provider, set the openai (and/or anthropic) entry's options.baseURL to http://<gateway>:8787/v1 and options.apiKey to your personal ark_… gateway key. For github-copilot, keep its GitHub authentication, set the Copilot seat base URL printed by Connect, and put the personal key in options.headers.x-anyray-api-key.
3
Restart
Save the file and restart OpenCode.
ChatGPT subscription can't be routed

OpenCode's built-in ChatGPT Pro/Plus OAuth runs through its own Codex backend, which is hard-coded to chatgpt.com and ignores provider.baseURL — Connect leaves that lane untouched. Use the Codex app/CLI/IDE for ChatGPT subscription pass-through. OpenCode's Anthropic provider is api-key only, so a personal Claude subscription routes through Claude Code, not OpenCode.