[PR #5717] feat: If an apiKey is provided, skip Oauth handling. #11545

Open
opened 2026-02-16 18:16:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5717

State: open
Merged: No


Context

My situation is this:

  • I have a personal Claude Code Pro subscription, which is Oauth-ed (just like Claude Code the agent does).
  • My work uses Anthropic Claude Enterprise, with multiple API keys (one key for each client). Those are usually set in the config via provider.anthropic.options.apiKey.

Using fake "profiles" (individually managed custom config files), I'd like to be able to use opencode with either type.

Expected

When configured to use the Anthropic Claude provider, if an (enterprise) apiKey is provided, it should take precedence over the stored Oauth (Claude Code Pro) credentials. If not provided, opencode should use the Oauth credentials.

Actual

Because of the way the configurations merging happens, the Oauth credentials (from ~/.local/share/opencode/auth.json) always "win", and the manually set apiKey is ignored.

This means all usage, even when I provide an enterprise API key, always ends up pointed at my personal Claude Pro subscription.

Solution

If an apiKey is configured & present, assume the user knows better & skip the loading of the Oauth credentials.


Deeper Explanation of Setup/Situation

  • I'm simulating having different "profiles" (one-per-client + a personal) by creating a bunch of custom config files within ~/.config/opencode/my_profiles/<profile-name>.jsonc.
  • In the work-based config files, under the provider.anthropic.options.apiKey path, I supply {file:~/.secrets/<profile-name>.apikey}, with different key paths for each work config.
  • I then launch opencode with: OPENCODE_CONFIG=~/.config/opencode/my_profiles/<profile-name>.jsonc opencode.
  • (Assuming I've renamed/moved the ~/.local/share/opencode/auth.json away) This works great for all the different clients/keys... but because that file is gone, I can no longer use my personal subscription (e.g. OPENCODE_CONFIG=~/.config/opencode/my_profiles/personal.jsonc opencode).
  • (Assuming I move the ~/.local/share/opencode/auth.json back) My personal Claude Pro subscription is back, but now takes over everything, & the client API keys are never used.

This adds a small skip (non-specific to Anthropic/Claude) to the provider code, only if an apiKey is set/present. It includes a new passing test that demonstrates the behavior.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5717 **State:** open **Merged:** No --- ## Context My situation is this: * I have a **personal** Claude Code Pro subscription, which is Oauth-ed (just like Claude Code the agent does). * My work uses **Anthropic Claude Enterprise**, with multiple API keys (one key for each client). Those are usually set in the config via `provider.anthropic.options.apiKey`. Using fake "profiles" (individually managed custom config files), I'd like to be able to use `opencode` with either type. ## Expected When configured to use the `Anthropic Claude` provider, if an (enterprise) `apiKey` is provided, it should take precedence over the stored Oauth (Claude Code Pro) credentials. If not provided, `opencode` should use the Oauth credentials. ## Actual Because of the way the configurations merging happens, the Oauth credentials (from `~/.local/share/opencode/auth.json`) always "win", and the manually set `apiKey` is ignored. This means all usage, even when I provide an enterprise API key, always ends up pointed at my **personal** Claude Pro subscription. ## Solution If an `apiKey` is configured & present, assume the user knows better & skip the loading of the Oauth credentials. --- ## Deeper Explanation of Setup/Situation * I'm simulating having different "profiles" (one-per-client + a personal) by creating a bunch of custom config files within `~/.config/opencode/my_profiles/<profile-name>.jsonc`. * In the work-based config files, under the `provider.anthropic.options.apiKey` path, I supply `{file:~/.secrets/<profile-name>.apikey}`, with different key paths for each work config. * I then launch `opencode` with: `OPENCODE_CONFIG=~/.config/opencode/my_profiles/<profile-name>.jsonc opencode`. * (Assuming I've renamed/moved the `~/.local/share/opencode/auth.json` away) This works great for all the different clients/keys... but because that file is gone, I can no longer use my personal subscription (e.g. `OPENCODE_CONFIG=~/.config/opencode/my_profiles/personal.jsonc opencode`). * (Assuming I move the `~/.local/share/opencode/auth.json` back) My personal Claude Pro subscription is back, but now takes over everything, & the client API keys are never used. --- This adds a small skip (non-specific to Anthropic/Claude) to the provider code, only if an `apiKey` is set/present. It includes a new passing test that demonstrates the behavior.
yindo added the pull-request label 2026-02-16 18:16:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11545