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. Add --dry-run to preview. Drop --tools opencode to
configure every detected tool (Connect your tools).
The config is read at launch.
Any anthropic/* or openai/* entry routes through the gateway. Your turn appears in Traces
with your name attached.
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, and --revert removes what it owns.
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.
A canonical anthropic or openai block you pinned at your own upstream by hand is
preserved the same way. Connect reads the passthrough headers
(x-anyray-auth-mode, x-anyray-custom-host, x-anyray-provider) and keeps the ones it did not
write, along with your Authorization and key, so your upstream keeps being paid. It says which
lanes it left alone. Run --upstream to move them onto a Connect-managed passthrough instead.
On a preserved custom route, --revert removes only the headers Connect added.
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.
Set it up by hand
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.
| Model prefix | What it spends |
|---|---|
github-copilot/* | Your Copilot subscription |
anthropic/* and openai/* | 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.