From 0a803a9aa61982a7262b9a3e70ae22117bb73c0f Mon Sep 17 00:00:00 2001 From: Jonathan Raphaelson Date: Fri, 26 Dec 2025 15:08:45 -0800 Subject: [PATCH] allow creating custom auth providers in order to provide different anthropic credentials depending on the project (eg, when you don't want to use your work's Claude subscription for personal projects), we need a way to utilize this plugin's already existing handling of oauth, and just override the name. After merging, default behavior stays the same, but custom plugins will be able to create custom anthropic sessions. --- index.mjs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/index.mjs b/index.mjs index 3fd75af..3a1c4a9 100644 --- a/index.mjs +++ b/index.mjs @@ -66,12 +66,16 @@ async function exchange(code, verifier) { } /** - * @type {import('@opencode-ai/plugin').Plugin} + * build an anthropic provider plugin with the given name. + * + * @param {string} name the provider's key (eg. 'anthropic', 'anthropic-personal', etc) + * @param {import('@opencode-ai/plugin').PluginInput['client']} client + * @returns {Promise} */ -export async function AnthropicAuthPlugin({ client }) { +export async function makeAnthropicProviderPlugin(name, client) { return { auth: { - provider: "anthropic", + provider: name, async loader(getAuth, provider) { const auth = await getAuth(); if (auth.type === "oauth") { @@ -116,7 +120,7 @@ export async function AnthropicAuthPlugin({ client }) { const json = await response.json(); await client.auth.set({ path: { - id: "anthropic", + id: name, }, body: { type: "oauth", @@ -206,7 +210,7 @@ export async function AnthropicAuthPlugin({ client }) { }, }, { - provider: "anthropic", + provider: name, label: "Manually enter API Key", type: "api", }, @@ -214,3 +218,10 @@ export async function AnthropicAuthPlugin({ client }) { }, }; } + +/** + * @type {import('@opencode-ai/plugin').Plugin} + */ +export async function AnthropicAuthPlugin({ client }) { + return makeAnthropicProviderPlugin("anthropic", client); +} \ No newline at end of file