From 8ce080358970cab5b54ab0f6178f37d40040d548 Mon Sep 17 00:00:00 2001 From: claude Date: Thu, 31 Jul 2025 13:15:06 +0000 Subject: [PATCH] updated prepare.ts so Claude Code token written --- src/entrypoints/prepare.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/entrypoints/prepare.ts b/src/entrypoints/prepare.ts index 061df53..d7ad271 100644 --- a/src/entrypoints/prepare.ts +++ b/src/entrypoints/prepare.ts @@ -18,6 +18,7 @@ import { createPrompt } from "../create-prompt"; import { createClient } from "../github/api/client"; import { fetchGitHubData } from "../github/data/fetcher"; import { parseGitHubContext } from "../github/context"; +import { setupOAuthCredentials } from "../claude/oauth-setup"; async function run() { try { @@ -27,18 +28,25 @@ async function run() { // Check if OAuth credentials are provided and API key is empty (OAuth mode) if (claudeCredentials && !anthropicApiKey) { - // Parse the credentials to extract the access token + // Write the credentials to the file system for Claude Code try { - const parsedCredentials = JSON.parse(claudeCredentials); - if (parsedCredentials.claudeAiOauth?.accessToken) { - // Output the access token for the base action to use - core.setOutput("claude_oauth_token", parsedCredentials.claudeAiOauth.accessToken); - console.log("OAuth access token extracted for Claude AI Max subscription"); - } else { - throw new Error("Invalid credentials format: missing claudeAiOauth.accessToken"); + await setupOAuthCredentials(claudeCredentials); + console.log("OAuth credentials written to ~/.claude/.credentials.json"); + + // Also extract the token for any other uses + try { + const parsedCredentials = JSON.parse(claudeCredentials); + if (parsedCredentials.claudeAiOauth?.accessToken) { + // Output the access token for the base action to use + core.setOutput("claude_oauth_token", parsedCredentials.claudeAiOauth.accessToken); + console.log("OAuth access token extracted for Claude AI Max subscription"); + } + } catch (parseError) { + // Log but don't fail - credentials are already written + console.log("Could not extract OAuth token for output:", parseError); } } catch (error) { - throw new Error(`Failed to parse OAuth credentials: ${error instanceof Error ? error.message : String(error)}`); + throw new Error(`Failed to setup OAuth credentials: ${error instanceof Error ? error.message : String(error)}`); } }