@@ -216,7 +216,68 @@ export async function applyAuthChoice(params: {
216216 provider : "anthropic" ,
217217 mode : "token" ,
218218 } ) ;
219- } else if ( params . authChoice === "token" || params . authChoice === "oauth" ) {
219+ } else if (
220+ params . authChoice === "setup-token" ||
221+ params . authChoice === "oauth"
222+ ) {
223+ await params . prompter . note (
224+ [
225+ "This will run `claude setup-token` to create a long-lived Anthropic token." ,
226+ "Requires an interactive TTY and a Claude Pro/Max subscription." ,
227+ ] . join ( "\n" ) ,
228+ "Anthropic setup-token" ,
229+ ) ;
230+
231+ if ( ! process . stdin . isTTY ) {
232+ await params . prompter . note (
233+ "`claude setup-token` requires an interactive TTY." ,
234+ "Anthropic setup-token" ,
235+ ) ;
236+ return { config : nextConfig , agentModelOverride } ;
237+ }
238+
239+ const proceed = await params . prompter . confirm ( {
240+ message : "Run `claude setup-token` now?" ,
241+ initialValue : true ,
242+ } ) ;
243+ if ( ! proceed ) return { config : nextConfig , agentModelOverride } ;
244+
245+ const res = await ( async ( ) => {
246+ const { spawnSync } = await import ( "node:child_process" ) ;
247+ return spawnSync ( "claude" , [ "setup-token" ] , { stdio : "inherit" } ) ;
248+ } ) ( ) ;
249+ if ( res . error ) {
250+ await params . prompter . note (
251+ `Failed to run claude: ${ String ( res . error ) } ` ,
252+ "Anthropic setup-token" ,
253+ ) ;
254+ return { config : nextConfig , agentModelOverride } ;
255+ }
256+ if ( typeof res . status === "number" && res . status !== 0 ) {
257+ await params . prompter . note (
258+ `claude setup-token failed (exit ${ res . status } )` ,
259+ "Anthropic setup-token" ,
260+ ) ;
261+ return { config : nextConfig , agentModelOverride } ;
262+ }
263+
264+ const store = ensureAuthProfileStore ( params . agentDir , {
265+ allowKeychainPrompt : true ,
266+ } ) ;
267+ if ( ! store . profiles [ CLAUDE_CLI_PROFILE_ID ] ) {
268+ await params . prompter . note (
269+ `No Claude CLI credentials found after setup-token. Expected ${ CLAUDE_CLI_PROFILE_ID } .` ,
270+ "Anthropic setup-token" ,
271+ ) ;
272+ return { config : nextConfig , agentModelOverride } ;
273+ }
274+
275+ nextConfig = applyAuthProfileConfig ( nextConfig , {
276+ profileId : CLAUDE_CLI_PROFILE_ID ,
277+ provider : "anthropic" ,
278+ mode : "token" ,
279+ } ) ;
280+ } else if ( params . authChoice === "token" ) {
220281 const provider = ( await params . prompter . select ( {
221282 message : "Token provider" ,
222283 options : [ { value : "anthropic" , label : "Anthropic (only supported)" } ] ,
0 commit comments