OpenCode
One anyray-connect command points OpenCode's providers at the gateway. Its built-in ChatGPT OAuth is left untouched.
Connect
npx anyray-connect@latest --gateway http://<gateway>:8787 --tools opencode
Enroll first with --enroll <link> or --sso. Connect makes no changes without a valid personal
ark_… client key. Use --dry-run to preview, and restart OpenCode
afterward. Omit --tools opencode to configure every detected tool
(Connect your tools).
Connect merges Anyray-owned provider and MCP entries into the existing config (opencode.jsonc,
opencode.json, or config.json). It preserves comments, every other provider, and unrelated
settings, and writes the per-user key plus x-anyray-metadata into the provider block.
It backs up the file first. --revert removes Connect-owned entries, restores a migrated custom
provider from the backup, and on a preserved custom route removes only headers Connect added.
What happens to an existing custom gateway provider
A custom provider already pointed at this gateway serving only Claude models is migrated
onto the managed anthropic block, which is the request dialect where the optimizer earns most.
The custom block is removed, its model references are rewritten to anthropic/*, and the
pre-apply backup keeps the original.
Any other custom gateway route is preserved: identity, URL, models, key, and headers stay
untouched. Connect only adds missing x-anyray-api-key and x-anyray-metadata headers, and
creates no parallel provider blocks. A foreign MCP server named anyray is also left alone.
Tool-output trimming
OpenCode's supported tool.execute.after plugin hook exposes completed tool output before it is
stored in the session. Connect installs a small global carrier at
~/.config/opencode/plugins/anyrayTrim.js that runs the same __anyray-hook runtime Claude Code
and Cursor use. It replaces the output only when the runtime returns a smaller result.
Failures keep the original output. This mode writes no raw-output tees and no disk-backed verdict cache, so no new plaintext content store appears outside the content mode.
The carrier installs only when the Connect binary is at a durable path. Connect reports when it
skips it, and gateway-side optimization stays active. --revert removes the carrier only when
Connect owns the file.
Manual setup
If anyray-connect cannot write the config automatically, it prints these steps.
~/.config/opencode/. Create opencode.json only when none exists.provider, set the openai or anthropic entry's options.baseURL to http://<gateway>:8787/v1 and options.apiKey to your personal ark_… 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.Copilot subscription seat
Connecting with a GitHub Copilot plan 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 to spend your Copilot subscription. The anthropic/* and
openai/* entries are the direct providers, in api-key mode with separate billing.
The route uses GitHub's generic Copilot API host. Set ANYRAY_COPILOT_PLAN to your plan's name
(individual, business, enterprise, team, or whichever tier GitHub lists) only if your org
enforces a plan-specific host. The value is the label in api.<plan>.githubcopilot.com. Leave it
unset to use the generic host.
OpenCode's built-in ChatGPT Pro and Plus OAuth runs through its own Codex backend, which is
hard-coded to chatgpt.com and ignores provider.baseURL, so Connect leaves that lane untouched.
Use the Codex app, CLI, or IDE for ChatGPT subscription pass-through. OpenCode's Anthropic provider
is api-key only, so a personal Claude subscription routes through Claude Code.