feat(cli): Add --token option to register-account command

Allow manual account registration using a setup token from `claude setup-token`.
The --token option requires --email and creates/updates account credentials
with the provided token.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Lukas May
2026-02-10 09:51:23 +01:00
parent e35927f321
commit 97998459e5

View File

@@ -1091,11 +1091,48 @@ export function createCli(serverHandler?: (port?: number) => Promise<void>): Com
.description('Extract current Claude login and register as an account')
.option('--provider <provider>', 'Provider name', 'claude')
.option('--email <email>', 'Email (for manual registration without auto-extract)')
.action(async (options: { provider: string; email?: string }) => {
.option('--token <token>', 'Setup token from `claude setup-token` (requires --email)')
.action(async (options: { provider: string; email?: string; token?: string }) => {
try {
const client = createDefaultTrpcClient();
if (options.email) {
if (options.token) {
// Token-based registration
if (!options.email) {
console.error('Error: --email is required when using --token');
process.exit(1);
}
const credentials = JSON.stringify({
claudeAiOauth: { accessToken: options.token },
});
const configJson = JSON.stringify({ hasCompletedOnboarding: true });
const existing = await client.listAccounts.query();
const alreadyRegistered = existing.find((a: any) => a.email === options.email);
if (alreadyRegistered) {
await client.updateAccountAuth.mutate({
id: alreadyRegistered.id,
configJson,
credentials,
});
console.log(`Updated credentials for account: ${alreadyRegistered.id}`);
console.log(` Email: ${options.email}`);
console.log(` Token updated (setup token)`);
return;
}
const account = await client.addAccount.mutate({
email: options.email,
provider: options.provider,
configJson,
credentials,
});
console.log(`Registered account: ${account.id}`);
console.log(` Email: ${account.email}`);
console.log(` Provider: ${account.provider}`);
console.log(` Auth: setup token`);
} else if (options.email) {
// Manual registration — guard against duplicates
const existing = await client.listAccounts.query();
const alreadyRegistered = existing.find((a: any) => a.email === options.email);