caflip 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +25 -4
  2. package/dist/cli.js +460 -110
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -124,7 +124,7 @@ After switching, restart the target CLI (Claude Code or Codex) to pick up new au
124
124
  | `caflip [provider] remove [email]` | Remove an account |
125
125
  | `caflip [provider] next` | Rotate to next account |
126
126
  | `caflip [provider] status` | Show current active account |
127
- | `caflip [provider] alias <name> [email]` | Set alias for current or target account |
127
+ | `caflip [provider] alias <name> [account]` | Set alias for current or target account |
128
128
  | `caflip help` | Show help |
129
129
 
130
130
  ### Alias Usage
@@ -133,13 +133,34 @@ After switching, restart the target CLI (Claude Code or Codex) to pick up new au
133
133
  # Set alias for current active account
134
134
  caflip claude alias work
135
135
 
136
- # Set alias for a specific managed account
137
- caflip claude alias work hi.lucienlee@gmail.com
136
+ # Set alias by list number
137
+ caflip codex list
138
+ # 1: me@example.com · team(org-ab12Cd)
139
+ # 2: me@example.com · team(org-xy98Qw)
140
+ caflip codex alias aibor 2
141
+
142
+ # Reuse an existing alias as the target
143
+ caflip claude alias primary work
138
144
 
139
- # Codex alias
145
+ # Email works only when it matches exactly one managed account
140
146
  caflip codex alias work me@company.com
141
147
  ```
142
148
 
149
+ `<account>` accepts:
150
+ - the account number shown in `caflip [provider] list`
151
+ - an existing alias
152
+ - an email, only when that email matches exactly one managed account
153
+
154
+ If the same email exists in multiple workspaces or organizations, use the list number or an existing alias instead.
155
+
156
+ Codex display labels use provider metadata conservatively:
157
+ - workspace plans such as `team` or `business` show `email · plan(orgShortId)`
158
+ - `free` shows `email · free`
159
+ - alias is the primary human-readable name when you need your own team label
160
+
161
+ Claude display labels keep custom organization names, but the default personal name
162
+ `<email>'s Organization` is simplified to `email · Personal`.
163
+
143
164
  `add`, `remove`, and `login` can be used without a provider prefix. In that case, caflip asks you to choose Claude or Codex first, then continues the normal command flow.
144
165
 
145
166
  `remove` target accepts email only. Omit it to choose from the interactive picker after selecting a provider.
package/dist/cli.js CHANGED
@@ -186,8 +186,11 @@ import { existsSync as existsSync9, mkdirSync as mkdirSync6 } from "fs";
186
186
  // src/config.ts
187
187
  import { homedir } from "os";
188
188
  import { join } from "path";
189
+ function getHomeDir() {
190
+ return process.env.HOME ?? homedir();
191
+ }
189
192
  function getBackupDir(provider) {
190
- return join(homedir(), ".caflip-backup", provider);
193
+ return join(getHomeDir(), ".caflip-backup", provider);
191
194
  }
192
195
  function getSequenceFile(provider) {
193
196
  return join(getBackupDir(provider), "sequence.json");
@@ -248,6 +251,43 @@ async function writeJsonAtomic(filePath, data) {
248
251
  }
249
252
 
250
253
  // src/accounts.ts
254
+ function getShortOrganizationId(organizationId) {
255
+ return organizationId.slice(0, 10);
256
+ }
257
+ function normalizeClaudeOrganizationName(email, organizationName) {
258
+ if (!organizationName) {
259
+ return null;
260
+ }
261
+ if (organizationName === `${email}'s Organization`) {
262
+ return "Personal";
263
+ }
264
+ return organizationName;
265
+ }
266
+ function getManagedAccountLabel(account) {
267
+ const provider = account.identity?.provider;
268
+ const organizationId = account.identity?.organizationId;
269
+ const organizationName = provider === "claude" ? normalizeClaudeOrganizationName(account.email, account.display?.organizationName) : account.display?.organizationName;
270
+ const planType = account.display?.planType;
271
+ if (provider === "codex") {
272
+ if (planType === "free") {
273
+ return `${account.email} · free`;
274
+ }
275
+ const orgShortId = organizationId ? getShortOrganizationId(organizationId) : null;
276
+ if (planType && orgShortId) {
277
+ return `${account.email} · ${planType}(${orgShortId})`;
278
+ }
279
+ if (orgShortId) {
280
+ return `${account.email} · ${orgShortId}`;
281
+ }
282
+ if (planType) {
283
+ return `${account.email} · ${planType}`;
284
+ }
285
+ }
286
+ if (organizationName) {
287
+ return `${account.email} · ${organizationName}`;
288
+ }
289
+ return account.email;
290
+ }
251
291
  async function initSequenceFile(path) {
252
292
  if (existsSync2(path))
253
293
  return;
@@ -260,7 +300,34 @@ async function initSequenceFile(path) {
260
300
  await writeJsonAtomic(path, data);
261
301
  }
262
302
  async function loadSequence(path) {
263
- return JSON.parse(readFileSync2(path, "utf-8"));
303
+ const raw = JSON.parse(readFileSync2(path, "utf-8"));
304
+ const accounts = Object.fromEntries(Object.entries(raw.accounts).map(([num, account]) => {
305
+ const display = account.display ?? {
306
+ email: account.email,
307
+ accountName: null,
308
+ organizationName: null,
309
+ planType: null,
310
+ role: null,
311
+ label: account.email
312
+ };
313
+ display.label = getManagedAccountLabel({
314
+ email: account.email,
315
+ display,
316
+ identity: account.identity
317
+ });
318
+ return [
319
+ num,
320
+ {
321
+ ...account,
322
+ display,
323
+ legacyUuid: account.legacyUuid ?? (account.identity ? undefined : account.uuid)
324
+ }
325
+ ];
326
+ }));
327
+ return {
328
+ ...raw,
329
+ accounts
330
+ };
264
331
  }
265
332
  function getNextAccountNumber(seq) {
266
333
  const keys = Object.keys(seq.accounts).map(Number);
@@ -268,8 +335,11 @@ function getNextAccountNumber(seq) {
268
335
  return 1;
269
336
  return Math.max(...keys) + 1;
270
337
  }
271
- function accountExists(seq, email) {
272
- return Object.values(seq.accounts).some((a) => a.email === email);
338
+ function accountExists(seq, identifier) {
339
+ if (typeof identifier === "string") {
340
+ return Object.values(seq.accounts).some((a) => a.email === identifier);
341
+ }
342
+ return resolveManagedAccount(seq, identifier) !== null;
273
343
  }
274
344
  function addAccountToSequence(seq, info) {
275
345
  const num = getNextAccountNumber(seq);
@@ -282,6 +352,15 @@ function addAccountToSequence(seq, info) {
282
352
  if (info.alias) {
283
353
  account.alias = info.alias;
284
354
  }
355
+ if (info.display) {
356
+ account.display = info.display;
357
+ }
358
+ if (info.identity) {
359
+ account.identity = info.identity;
360
+ }
361
+ if (info.providerMetadata) {
362
+ account.providerMetadata = info.providerMetadata;
363
+ }
285
364
  return {
286
365
  ...seq,
287
366
  accounts: { ...seq.accounts, [numStr]: account },
@@ -321,15 +400,35 @@ function getPostRemovalAction(original, updated, removedAccountNum) {
321
400
  targetAccountNumber: String(updated.activeAccountNumber)
322
401
  };
323
402
  }
324
- function resolveManagedAccountNumberForEmail(seq, currentEmail) {
325
- if (!currentEmail || currentEmail === "none") {
403
+ function resolveManagedAccountNumber(seq, currentAccount) {
404
+ const resolved = resolveManagedAccount(seq, currentAccount);
405
+ return resolved === null ? null : Number(resolved);
406
+ }
407
+ function resolveManagedAccount(seq, currentAccount) {
408
+ if (!currentAccount?.email || currentAccount.email === "none") {
326
409
  return null;
327
410
  }
328
- const accountNum = resolveAccountIdentifier(seq, currentEmail);
329
- if (!accountNum) {
411
+ if (currentAccount.uniqueKey) {
412
+ for (const [accountNum2, account2] of Object.entries(seq.accounts)) {
413
+ if (account2.identity?.uniqueKey === currentAccount.uniqueKey) {
414
+ return accountNum2;
415
+ }
416
+ }
417
+ }
418
+ const emailMatches = Object.entries(seq.accounts).filter(([, account2]) => {
419
+ if (account2.email !== currentAccount.email) {
420
+ return false;
421
+ }
422
+ if (!currentAccount.provider) {
423
+ return true;
424
+ }
425
+ return !account2.identity || account2.identity.provider === currentAccount.provider;
426
+ });
427
+ if (emailMatches.length !== 1) {
330
428
  return null;
331
429
  }
332
- return Number(accountNum);
430
+ const [accountNum, account] = emailMatches[0];
431
+ return account.identity ? null : accountNum;
333
432
  }
334
433
  function getNextInSequence(seq) {
335
434
  const currentIndex = seq.sequence.indexOf(seq.activeAccountNumber);
@@ -347,27 +446,29 @@ function resolveAccountIdentifier(seq, identifier) {
347
446
  }
348
447
  return null;
349
448
  }
350
- for (const [num, account] of Object.entries(seq.accounts)) {
351
- if (account.email === identifier)
352
- return num;
449
+ const emailMatches = Object.entries(seq.accounts).filter(([, account]) => account.email === identifier);
450
+ if (emailMatches.length === 1) {
451
+ return emailMatches[0][0];
353
452
  }
354
453
  return null;
355
454
  }
356
- function resolveAliasTargetAccount(seq, options) {
357
- if (options.identifier) {
358
- if (/^\d+$/.test(options.identifier)) {
359
- return null;
360
- }
361
- for (const [num, account] of Object.entries(seq.accounts)) {
362
- if (account.email === options.identifier)
363
- return num;
364
- }
365
- return null;
455
+ function resolveAccountTarget(seq, identifier) {
456
+ if (/^\d+$/.test(identifier)) {
457
+ const resolved = resolveAccountIdentifier(seq, identifier);
458
+ return resolved ? { status: "resolved", accountNum: resolved } : { status: "missing" };
366
459
  }
367
- if (!options.currentEmail || options.currentEmail === "none") {
368
- return null;
460
+ const aliasMatch = findAccountByAlias(seq, identifier);
461
+ if (aliasMatch) {
462
+ return { status: "resolved", accountNum: aliasMatch };
463
+ }
464
+ const emailMatches = Object.entries(seq.accounts).filter(([, account]) => account.email === identifier).map(([accountNum]) => accountNum);
465
+ if (emailMatches.length === 1) {
466
+ return { status: "resolved", accountNum: emailMatches[0] };
467
+ }
468
+ if (emailMatches.length > 1) {
469
+ return { status: "ambiguous", matches: emailMatches };
369
470
  }
370
- return resolveAccountIdentifier(seq, options.currentEmail);
471
+ return { status: "missing" };
371
472
  }
372
473
  function getDisplayAccountNumber(seq, accountNum) {
373
474
  const idx = seq.sequence.indexOf(Number(accountNum));
@@ -510,8 +611,11 @@ function isProcessAlive(pid) {
510
611
  import { homedir as homedir2 } from "os";
511
612
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "fs";
512
613
  import { join as join4 } from "path";
614
+ function getHomeDir2() {
615
+ return process.env.HOME ?? homedir2();
616
+ }
513
617
  function getBackupDir2(provider) {
514
- return join4(homedir2(), ".caflip-backup", provider);
618
+ return join4(getHomeDir2(), ".caflip-backup", provider);
515
619
  }
516
620
  function getSequenceFile2(provider) {
517
621
  return join4(getBackupDir2(provider), "sequence.json");
@@ -554,14 +658,14 @@ function detectPlatform() {
554
658
  return "unknown";
555
659
  }
556
660
  }
557
- function getClaudeConfigDir(env = process.env, home = homedir2()) {
661
+ function getClaudeConfigDir(env = process.env, home = env.HOME ?? homedir2()) {
558
662
  const customDir = env.CLAUDE_CONFIG_DIR?.trim();
559
663
  if (customDir) {
560
664
  return customDir;
561
665
  }
562
666
  return join4(home, ".claude");
563
667
  }
564
- function getClaudeConfigPath(env = process.env, home = homedir2()) {
668
+ function getClaudeConfigPath(env = process.env, home = env.HOME ?? homedir2()) {
565
669
  const customDir = env.CLAUDE_CONFIG_DIR?.trim();
566
670
  if (customDir) {
567
671
  return join4(customDir, ".claude.json");
@@ -617,7 +721,7 @@ function validateAlias(alias) {
617
721
  // package.json
618
722
  var package_default = {
619
723
  name: "caflip",
620
- version: "0.3.3",
724
+ version: "0.4.1",
621
725
  type: "module",
622
726
  bin: {
623
727
  caflip: "bin/caflip"
@@ -2258,6 +2362,45 @@ var dist_default5 = createPrompt((config, done) => {
2258
2362
  `).trimEnd();
2259
2363
  return `${lines}${cursorHide}`;
2260
2364
  });
2365
+ // src/accounts.ts
2366
+ function getShortOrganizationId2(organizationId) {
2367
+ return organizationId.slice(0, 10);
2368
+ }
2369
+ function normalizeClaudeOrganizationName2(email, organizationName) {
2370
+ if (!organizationName) {
2371
+ return null;
2372
+ }
2373
+ if (organizationName === `${email}'s Organization`) {
2374
+ return "Personal";
2375
+ }
2376
+ return organizationName;
2377
+ }
2378
+ function getManagedAccountLabel2(account) {
2379
+ const provider = account.identity?.provider;
2380
+ const organizationId = account.identity?.organizationId;
2381
+ const organizationName = provider === "claude" ? normalizeClaudeOrganizationName2(account.email, account.display?.organizationName) : account.display?.organizationName;
2382
+ const planType = account.display?.planType;
2383
+ if (provider === "codex") {
2384
+ if (planType === "free") {
2385
+ return `${account.email} · free`;
2386
+ }
2387
+ const orgShortId = organizationId ? getShortOrganizationId2(organizationId) : null;
2388
+ if (planType && orgShortId) {
2389
+ return `${account.email} · ${planType}(${orgShortId})`;
2390
+ }
2391
+ if (orgShortId) {
2392
+ return `${account.email} · ${orgShortId}`;
2393
+ }
2394
+ if (planType) {
2395
+ return `${account.email} · ${planType}`;
2396
+ }
2397
+ }
2398
+ if (organizationName) {
2399
+ return `${account.email} · ${organizationName}`;
2400
+ }
2401
+ return account.email;
2402
+ }
2403
+
2261
2404
  // src/interactive.ts
2262
2405
  class PromptCancelledError extends Error {
2263
2406
  constructor() {
@@ -2303,13 +2446,13 @@ async function wrapPromptCancellation(fn) {
2303
2446
  cleanup();
2304
2447
  }
2305
2448
  }
2306
- function formatAccount(num, email, alias, isActive) {
2307
- let label = `${num}: ${email}`;
2449
+ function formatAccount(num, label, alias, isActive) {
2450
+ let formatted = `${num}: ${label}`;
2308
2451
  if (alias)
2309
- label += ` [${alias}]`;
2452
+ formatted += ` [${alias}]`;
2310
2453
  if (isActive)
2311
- label += " (active)";
2312
- return label;
2454
+ formatted += " (active)";
2455
+ return formatted;
2313
2456
  }
2314
2457
  async function pickAccount(seq, message = "Switch to account:", promptSelect = dist_default5, extraChoices = []) {
2315
2458
  const choices = [
@@ -2321,7 +2464,7 @@ async function pickAccount(seq, message = "Switch to account:", promptSelect = d
2321
2464
  }
2322
2465
  const isActive = num === seq.activeAccountNumber;
2323
2466
  return {
2324
- name: formatAccount(String(index + 1), account.email, account.alias, isActive),
2467
+ name: formatAccount(String(index + 1), getManagedAccountLabel2(account), account.alias, isActive),
2325
2468
  value: numStr
2326
2469
  };
2327
2470
  }),
@@ -2482,14 +2625,14 @@ function activeSecretToolAttrs() {
2482
2625
  function backupSecretToolAttrs(accountNum, email) {
2483
2626
  return ["service", "ccflip", "account", accountNum, "email", email];
2484
2627
  }
2485
- function getClaudeCredentialsDir(env = process.env, home = homedir3()) {
2628
+ function getClaudeCredentialsDir(env = process.env, home = env.HOME ?? homedir3()) {
2486
2629
  const customDir = env.CLAUDE_CONFIG_DIR?.trim();
2487
2630
  if (customDir) {
2488
2631
  return customDir;
2489
2632
  }
2490
2633
  return join5(home, ".claude");
2491
2634
  }
2492
- function getClaudeCredentialsPath(env = process.env, home = homedir3()) {
2635
+ function getClaudeCredentialsPath(env = process.env, home = env.HOME ?? homedir3()) {
2493
2636
  return join5(getClaudeCredentialsDir(env, home), ".credentials.json");
2494
2637
  }
2495
2638
  async function secretToolLookup(attrs) {
@@ -2818,7 +2961,21 @@ function getClaudeCurrentAccount() {
2818
2961
  return null;
2819
2962
  }
2820
2963
  const accountId = typeof content?.oauthAccount?.accountUuid === "string" ? content.oauthAccount.accountUuid : undefined;
2821
- return { email, accountId };
2964
+ const organizationId = typeof content?.oauthAccount?.organizationUuid === "string" ? content.oauthAccount.organizationUuid : undefined;
2965
+ const organizationName = typeof content?.oauthAccount?.organizationName === "string" ? content.oauthAccount.organizationName : undefined;
2966
+ const workspaceRole = typeof content?.oauthAccount?.workspaceRole === "string" ? content.oauthAccount.workspaceRole : undefined;
2967
+ const organizationRole = typeof content?.oauthAccount?.organizationRole === "string" ? content.oauthAccount.organizationRole : undefined;
2968
+ const accountName = typeof content?.oauthAccount?.displayName === "string" ? content.oauthAccount.displayName : undefined;
2969
+ return {
2970
+ email,
2971
+ accountId,
2972
+ organizationId,
2973
+ organizationName,
2974
+ role: workspaceRole ?? organizationRole,
2975
+ accountName,
2976
+ uniqueKey: accountId && organizationId ? `claude:${accountId}:${organizationId}` : undefined,
2977
+ identityStatus: accountId && organizationId ? "resolved" : "partial"
2978
+ };
2822
2979
  }
2823
2980
  function getClaudeCurrentAccountEmail() {
2824
2981
  return getClaudeCurrentAccount()?.email ?? "none";
@@ -3012,35 +3169,50 @@ async function deleteCodexAccountAuthBackup(accountNum, email, credentialsDir) {
3012
3169
  const backupPath = join6(credentialsDir, `.codex-auth-${accountNum}-${email}.json`);
3013
3170
  rmSync4(backupPath, { force: true });
3014
3171
  }
3015
- function getCodexCurrentAccount() {
3172
+ function resolveCodexCurrentAccount() {
3016
3173
  const authPath = getCodexAuthPath();
3017
3174
  if (!existsSync7(authPath)) {
3018
- return null;
3175
+ return { account: null, ambiguousOrganization: false };
3019
3176
  }
3020
3177
  try {
3021
3178
  const authObj = JSON.parse(readFileSync7(authPath, "utf-8"));
3022
3179
  const idToken = authObj.tokens?.id_token;
3023
3180
  if (!idToken) {
3024
- return null;
3181
+ return { account: null, ambiguousOrganization: false };
3025
3182
  }
3026
3183
  const payload = decodeJwtPayload(idToken);
3027
3184
  if (!payload) {
3028
- return null;
3185
+ return { account: null, ambiguousOrganization: false };
3029
3186
  }
3030
3187
  const email = typeof payload.email === "string" ? payload.email : null;
3031
3188
  if (!email) {
3032
- return null;
3189
+ return { account: null, ambiguousOrganization: false };
3033
3190
  }
3034
3191
  const authPayload = payload["https://api.openai.com/auth"];
3035
3192
  const accountId = authPayload?.chatgpt_account_id ?? authObj.tokens?.account_id;
3193
+ const organizations = Array.isArray(authPayload?.organizations) ? authPayload.organizations : [];
3194
+ const organization = organizations.find((candidate) => candidate.is_default === true) ?? (organizations.length === 1 ? organizations[0] : undefined);
3195
+ const ambiguousOrganization = organizations.length > 1 && !organization;
3036
3196
  return {
3037
- email,
3038
- accountId
3197
+ ambiguousOrganization,
3198
+ account: {
3199
+ email,
3200
+ accountId,
3201
+ organizationId: organization?.id,
3202
+ organizationName: organization?.title,
3203
+ planType: authPayload?.chatgpt_plan_type,
3204
+ role: organization?.role,
3205
+ uniqueKey: accountId && organization?.id ? `codex:${accountId}:${organization.id}` : undefined,
3206
+ identityStatus: ambiguousOrganization ? "ambiguous" : accountId && organization?.id ? "resolved" : "partial"
3207
+ }
3039
3208
  };
3040
3209
  } catch {
3041
- return null;
3210
+ return { account: null, ambiguousOrganization: false };
3042
3211
  }
3043
3212
  }
3213
+ function getCodexCurrentAccount() {
3214
+ return resolveCodexCurrentAccount().account;
3215
+ }
3044
3216
  function readCodexAuthFile() {
3045
3217
  const authPath = getCodexAuthPath();
3046
3218
  if (!existsSync7(authPath)) {
@@ -3085,17 +3257,28 @@ async function verifyCodexLogin(commandRunner = runCapturedCommand) {
3085
3257
  }
3086
3258
  };
3087
3259
  }
3088
- const currentAccount = getCodexCurrentAccount();
3260
+ const { account: currentAccount, ambiguousOrganization } = resolveCodexCurrentAccount();
3089
3261
  if (!currentAccount?.email) {
3090
3262
  return {
3091
3263
  ok: false,
3092
3264
  reason: "codex auth file did not resolve a current account email"
3093
3265
  };
3094
3266
  }
3267
+ if (ambiguousOrganization) {
3268
+ return {
3269
+ ok: false,
3270
+ reason: "codex login resolved an ambiguous workspace context: multiple organizations without a default workspace"
3271
+ };
3272
+ }
3095
3273
  return {
3096
3274
  ok: true,
3097
3275
  email: currentAccount.email,
3098
- details: currentAccount.accountId ? { accountId: currentAccount.accountId } : undefined
3276
+ details: {
3277
+ accountId: currentAccount.accountId,
3278
+ organizationId: currentAccount.organizationId,
3279
+ organizationName: currentAccount.organizationName,
3280
+ planType: currentAccount.planType
3281
+ }
3099
3282
  };
3100
3283
  }
3101
3284
  var codexLoginAdapter = {
@@ -3186,12 +3369,115 @@ function setupDirectories() {
3186
3369
  mkdirSync6(dir, { recursive: true, mode: 448 });
3187
3370
  }
3188
3371
  }
3372
+ function getCurrentAccountIdentity() {
3373
+ return activeProvider.getCurrentAccount();
3374
+ }
3189
3375
  function getCurrentAccount() {
3190
- return activeProvider.getCurrentAccountEmail();
3376
+ return getCurrentAccountIdentity()?.email ?? "none";
3191
3377
  }
3192
3378
  function getProviderLabel() {
3193
3379
  return activeProvider.name === "codex" ? "Codex" : "Claude Code";
3194
3380
  }
3381
+ function hasMultipleProviderEmailMatches(seq, email, provider) {
3382
+ return Object.values(seq.accounts).filter((account) => {
3383
+ if (account.email !== email) {
3384
+ return false;
3385
+ }
3386
+ return !account.identity || account.identity.provider === provider;
3387
+ }).length > 1;
3388
+ }
3389
+ function resolveCurrentManagedAccountForSwitch(seq, currentIdentity, currentEmail) {
3390
+ if (currentIdentity) {
3391
+ const resolved = resolveManagedAccount(seq, currentIdentity);
3392
+ if (resolved) {
3393
+ return resolved;
3394
+ }
3395
+ const providerEmailMatchCount = Object.values(seq.accounts).filter((account) => {
3396
+ if (account.email !== currentIdentity.email) {
3397
+ return false;
3398
+ }
3399
+ return !account.identity || account.identity.provider === activeProvider.name;
3400
+ }).length;
3401
+ if (currentIdentity.identityStatus === "ambiguous") {
3402
+ throw new Error(`Cannot determine which managed account is currently active for ${currentIdentity.email}.`);
3403
+ }
3404
+ if (currentIdentity.email !== "none" && providerEmailMatchCount > 0) {
3405
+ throw new Error(`Cannot determine which managed account is currently active for ${currentIdentity.email}.`);
3406
+ }
3407
+ return null;
3408
+ }
3409
+ if (currentEmail === "none") {
3410
+ return null;
3411
+ }
3412
+ return resolveAccountIdentifier(seq, currentEmail);
3413
+ }
3414
+ function getAccountDisplayLabel(account) {
3415
+ return getManagedAccountLabel(account);
3416
+ }
3417
+ function getCurrentAccountDisplayLabel(currentAccount) {
3418
+ if (!currentAccount) {
3419
+ return "none";
3420
+ }
3421
+ return getManagedAccountLabel({
3422
+ email: currentAccount.email,
3423
+ display: {
3424
+ email: currentAccount.email,
3425
+ accountName: currentAccount.accountName ?? null,
3426
+ organizationName: currentAccount.organizationName ?? null,
3427
+ planType: currentAccount.planType ?? null,
3428
+ role: currentAccount.role ?? null,
3429
+ label: ""
3430
+ },
3431
+ identity: {
3432
+ provider: activeProvider.name,
3433
+ accountId: currentAccount.accountId ?? null,
3434
+ organizationId: currentAccount.organizationId ?? null,
3435
+ uniqueKey: ""
3436
+ }
3437
+ });
3438
+ }
3439
+ function buildManagedAccountDetails(currentAccount) {
3440
+ if (!currentAccount) {
3441
+ return {
3442
+ email: "none",
3443
+ uuid: "",
3444
+ display: {
3445
+ email: "none",
3446
+ accountName: null,
3447
+ organizationName: null,
3448
+ planType: null,
3449
+ role: null,
3450
+ label: "none"
3451
+ },
3452
+ identity: undefined,
3453
+ providerMetadata: undefined
3454
+ };
3455
+ }
3456
+ return {
3457
+ email: currentAccount.email,
3458
+ uuid: currentAccount.accountId ?? currentAccount.uniqueKey ?? "",
3459
+ display: {
3460
+ email: currentAccount.email,
3461
+ accountName: currentAccount.accountName ?? null,
3462
+ organizationName: currentAccount.organizationName ?? null,
3463
+ planType: currentAccount.planType ?? null,
3464
+ role: currentAccount.role ?? null,
3465
+ label: getCurrentAccountDisplayLabel(currentAccount)
3466
+ },
3467
+ identity: currentAccount.uniqueKey ? {
3468
+ provider: activeProvider.name,
3469
+ accountId: currentAccount.accountId ?? null,
3470
+ organizationId: currentAccount.organizationId ?? null,
3471
+ uniqueKey: currentAccount.uniqueKey
3472
+ } : undefined,
3473
+ providerMetadata: {
3474
+ organizationName: currentAccount.organizationName ?? null,
3475
+ planType: currentAccount.planType ?? null,
3476
+ role: currentAccount.role ?? null,
3477
+ accountName: currentAccount.accountName ?? null
3478
+ }
3479
+ };
3480
+ }
3195
3481
  function showProviderRequiredError(command) {
3196
3482
  console.error(`Error: ${command} requires provider prefix.`);
3197
3483
  console.error(`Try: caflip claude ${command} or caflip codex ${command}`);
@@ -3268,8 +3554,7 @@ async function resolveCliContext(parsed, deps = { resolveProviderForCommand }) {
3268
3554
  };
3269
3555
  }
3270
3556
  async function syncSequenceActiveAccount(seq) {
3271
- const currentEmail = getCurrentAccount();
3272
- const resolvedActive = resolveManagedAccountNumberForEmail(seq, currentEmail);
3557
+ const resolvedActive = resolveManagedAccountNumber(seq, getCurrentAccountIdentity());
3273
3558
  if (seq.activeAccountNumber !== resolvedActive) {
3274
3559
  seq.activeAccountNumber = resolvedActive;
3275
3560
  seq.lastUpdated = new Date().toISOString();
@@ -3289,22 +3574,26 @@ async function registerCurrentActiveAccount(options) {
3289
3574
  if (options?.expectedEmail && currentEmail !== options.expectedEmail) {
3290
3575
  throw new Error(`Active ${getProviderLabel()} account changed during login verification: expected ${options.expectedEmail}, got ${currentEmail}`);
3291
3576
  }
3577
+ if (currentAccount?.identityStatus === "ambiguous") {
3578
+ throw new Error(`${getProviderLabel()} current account is in an ambiguous workspace context. Please pick a single workspace first, then retry.`);
3579
+ }
3292
3580
  setupDirectories();
3293
3581
  await initSequenceFile(activeSequenceFile);
3294
3582
  const seq = await loadSequence(activeSequenceFile);
3295
3583
  await syncSequenceActiveAccount(seq);
3584
+ const currentAccountNum = resolveManagedAccount(seq, currentAccount);
3585
+ const currentDetails = buildManagedAccountDetails(currentAccount);
3296
3586
  if (options?.alias) {
3297
3587
  const result = validateAlias(options.alias);
3298
3588
  if (!result.valid) {
3299
3589
  throw new Error(result.reason);
3300
3590
  }
3301
3591
  const existingAliasTarget = findAccountByAlias(seq, options.alias);
3302
- const currentAccountNum = resolveAccountIdentifier(seq, currentEmail);
3303
3592
  if (existingAliasTarget && existingAliasTarget !== currentAccountNum) {
3304
3593
  throw new Error(`Alias "${options.alias}" is already in use`);
3305
3594
  }
3306
3595
  }
3307
- const existingAccountNum = resolveAccountIdentifier(seq, currentEmail);
3596
+ const existingAccountNum = currentAccountNum;
3308
3597
  if (existingAccountNum) {
3309
3598
  if (!options?.updateIfExists) {
3310
3599
  console.log(`Account ${currentEmail} is already managed.`);
@@ -3333,7 +3622,11 @@ async function registerCurrentActiveAccount(options) {
3333
3622
  ...seq.accounts,
3334
3623
  [existingAccountNum]: {
3335
3624
  ...seq.accounts[existingAccountNum],
3625
+ email: currentEmail,
3336
3626
  uuid,
3627
+ identity: currentDetails.identity ?? seq.accounts[existingAccountNum].identity,
3628
+ display: currentDetails.display,
3629
+ providerMetadata: currentDetails.providerMetadata ?? seq.accounts[existingAccountNum].providerMetadata,
3337
3630
  ...options?.alias ? { alias: options.alias } : {}
3338
3631
  }
3339
3632
  }
@@ -3352,7 +3645,10 @@ async function registerCurrentActiveAccount(options) {
3352
3645
  const updated = addAccountToSequence(seq, {
3353
3646
  email: currentEmail,
3354
3647
  uuid,
3355
- alias: options?.alias
3648
+ alias: options?.alias,
3649
+ identity: currentDetails.identity,
3650
+ display: currentDetails.display,
3651
+ providerMetadata: currentDetails.providerMetadata
3356
3652
  });
3357
3653
  const accountNum = String(updated.activeAccountNumber);
3358
3654
  await activeProvider.writeAccountAuth(accountNum, currentEmail, creds, activeCredentialsDir);
@@ -3366,6 +3662,22 @@ async function registerCurrentActiveAccount(options) {
3366
3662
  email: currentEmail
3367
3663
  };
3368
3664
  }
3665
+ async function refreshCurrentManagedBackup(currentAccountNum, currentEmail, credentialsDir, configsDir) {
3666
+ if (currentEmail === "none" || !currentAccountNum) {
3667
+ return currentAccountNum;
3668
+ }
3669
+ const currentCreds = await activeProvider.readActiveAuth();
3670
+ if (currentCreds) {
3671
+ await activeProvider.writeAccountAuth(currentAccountNum, currentEmail, currentCreds, credentialsDir);
3672
+ }
3673
+ if (activeProvider.usesAccountConfig) {
3674
+ const currentConfig = await activeProvider.readActiveConfig();
3675
+ if (currentConfig) {
3676
+ await activeProvider.writeAccountConfig(currentAccountNum, currentEmail, currentConfig, configsDir);
3677
+ }
3678
+ }
3679
+ return currentAccountNum;
3680
+ }
3369
3681
  function getLoginPassthroughArgs(args) {
3370
3682
  const passthroughIdx = args.indexOf("--");
3371
3683
  if (passthroughIdx === -1) {
@@ -3380,17 +3692,27 @@ function getLoginPassthroughArgs(args) {
3380
3692
  return args.slice(passthroughIdx + 1);
3381
3693
  }
3382
3694
  async function performSwitch(seq, targetAccount, options) {
3695
+ const targetProvider = seq.accounts[targetAccount].identity?.provider;
3696
+ if (targetProvider) {
3697
+ setActiveProvider(targetProvider);
3698
+ }
3699
+ const providerName = targetProvider ?? activeProvider.name;
3700
+ const sequenceFile = getSequenceFile(providerName);
3701
+ const credentialsDir = getCredentialsDir(providerName);
3702
+ const configsDir = getConfigsDir(providerName);
3383
3703
  const targetEmail = seq.accounts[targetAccount].email;
3384
- const currentEmail = options?.currentEmail ?? getCurrentAccount();
3385
- const currentAccount = currentEmail === "none" ? null : resolveAccountIdentifier(seq, currentEmail);
3386
- if (currentEmail === targetEmail) {
3704
+ const observedCurrentIdentity = getCurrentAccountIdentity();
3705
+ const currentIdentity = options?.currentEmail && observedCurrentIdentity && observedCurrentIdentity.email !== options.currentEmail ? null : observedCurrentIdentity;
3706
+ const currentEmail = options?.currentEmail ?? currentIdentity?.email ?? "none";
3707
+ const currentAccount = resolveCurrentManagedAccountForSwitch(seq, currentIdentity, currentEmail);
3708
+ if (currentAccount === targetAccount) {
3387
3709
  const account = seq.accounts[targetAccount];
3388
3710
  const aliasStr2 = account.alias ? ` [${account.alias}]` : "";
3389
3711
  const displayLabel2 = getDisplayAccountLabel(seq, targetAccount);
3390
3712
  if (seq.activeAccountNumber !== Number(targetAccount)) {
3391
3713
  seq.activeAccountNumber = Number(targetAccount);
3392
3714
  seq.lastUpdated = new Date().toISOString();
3393
- await writeJsonAtomic2(activeSequenceFile, seq);
3715
+ await writeJsonAtomic2(sequenceFile, seq);
3394
3716
  }
3395
3717
  console.log(`Already using ${displayLabel2} (${account.email})${aliasStr2}`);
3396
3718
  return;
@@ -3401,20 +3723,9 @@ async function performSwitch(seq, targetAccount, options) {
3401
3723
  if (currentEmail !== "none" && !sanitizeEmailForFilename(currentEmail)) {
3402
3724
  throw new Error("Current account email is not safe for storage");
3403
3725
  }
3404
- if (currentEmail !== "none" && currentAccount) {
3405
- const currentCreds = await activeProvider.readActiveAuth();
3406
- if (currentCreds) {
3407
- await activeProvider.writeAccountAuth(currentAccount, currentEmail, currentCreds, activeCredentialsDir);
3408
- }
3409
- if (activeProvider.usesAccountConfig) {
3410
- const currentConfig = await activeProvider.readActiveConfig();
3411
- if (currentConfig) {
3412
- await activeProvider.writeAccountConfig(currentAccount, currentEmail, currentConfig, activeConfigsDir);
3413
- }
3414
- }
3415
- }
3416
- const targetCreds = await activeProvider.readAccountAuth(targetAccount, targetEmail, activeCredentialsDir);
3417
- const targetConfig = activeProvider.readAccountConfig(targetAccount, targetEmail, activeConfigsDir);
3726
+ await refreshCurrentManagedBackup(currentAccount, currentEmail, credentialsDir, configsDir);
3727
+ const targetCreds = await activeProvider.readAccountAuth(targetAccount, targetEmail, credentialsDir);
3728
+ const targetConfig = activeProvider.readAccountConfig(targetAccount, targetEmail, configsDir);
3418
3729
  if (!targetCreds) {
3419
3730
  throw new Error(`Missing backup data for ${getDisplayAccountLabel(seq, targetAccount)}`);
3420
3731
  }
@@ -3427,10 +3738,23 @@ async function performSwitch(seq, targetAccount, options) {
3427
3738
  }
3428
3739
  seq.activeAccountNumber = Number(targetAccount);
3429
3740
  seq.lastUpdated = new Date().toISOString();
3430
- await writeJsonAtomic2(activeSequenceFile, seq);
3741
+ await writeJsonAtomic2(sequenceFile, seq);
3431
3742
  const alias = seq.accounts[targetAccount].alias;
3432
3743
  const aliasStr = alias ? ` [${alias}]` : "";
3433
3744
  const displayLabel = getDisplayAccountLabel(seq, targetAccount);
3745
+ const refreshedAccount = activeProvider.getCurrentAccount();
3746
+ if (refreshedAccount) {
3747
+ const refreshedDetails = buildManagedAccountDetails(refreshedAccount);
3748
+ seq.accounts[targetAccount] = {
3749
+ ...seq.accounts[targetAccount],
3750
+ email: refreshedDetails.email,
3751
+ uuid: refreshedDetails.uuid,
3752
+ display: refreshedDetails.display,
3753
+ identity: refreshedDetails.identity ?? seq.accounts[targetAccount].identity,
3754
+ providerMetadata: refreshedDetails.providerMetadata ?? seq.accounts[targetAccount].providerMetadata
3755
+ };
3756
+ await writeJsonAtomic2(sequenceFile, seq);
3757
+ }
3434
3758
  console.log(`Switched to ${displayLabel} (${targetEmail})${aliasStr}`);
3435
3759
  console.log(`
3436
3760
  Please restart ${getProviderLabel()} to use the new authentication.
@@ -3454,15 +3778,16 @@ async function getManagedAccountLinesForActiveProvider() {
3454
3778
  }
3455
3779
  const seq = await loadSequence(activeSequenceFile);
3456
3780
  await syncSequenceActiveAccount(seq);
3457
- const currentEmail = getCurrentAccount();
3781
+ const currentAccount = getCurrentAccountIdentity();
3782
+ const activeAccountNum = resolveManagedAccount(seq, currentAccount);
3458
3783
  return seq.sequence.map((num, index) => {
3459
3784
  const numStr = String(num);
3460
3785
  const account = seq.accounts[numStr];
3461
3786
  if (!account) {
3462
3787
  throw new Error(`Corrupt sequence data: missing account entry for id ${numStr}`);
3463
3788
  }
3464
- const isActive = account.email === currentEmail;
3465
- let line = ` ${index + 1}: ${account.email}`;
3789
+ const isActive = activeAccountNum === numStr;
3790
+ let line = ` ${index + 1}: ${getAccountDisplayLabel(account)}`;
3466
3791
  if (account.alias)
3467
3792
  line += ` [${account.alias}]`;
3468
3793
  if (isActive)
@@ -3471,14 +3796,12 @@ async function getManagedAccountLinesForActiveProvider() {
3471
3796
  });
3472
3797
  }
3473
3798
  async function cmdAdd(alias) {
3474
- const result = await registerCurrentActiveAccount({ alias, updateIfExists: false });
3475
- if (result.action === "unchanged") {
3476
- return;
3477
- }
3799
+ const result = await registerCurrentActiveAccount({ alias, updateIfExists: true });
3478
3800
  const seq = await loadSequence(activeSequenceFile);
3479
3801
  const displayLabel = getDisplayAccountLabel(seq, result.accountNum);
3480
3802
  const aliasStr = alias ? ` [${alias}]` : "";
3481
- console.log(`Added ${displayLabel}: ${result.email}${aliasStr}`);
3803
+ const verb = result.action === "updated" ? "Updated" : "Added";
3804
+ console.log(`${verb} ${displayLabel}: ${result.email}${aliasStr}`);
3482
3805
  }
3483
3806
  async function cmdLogin(args) {
3484
3807
  const passthroughArgs = getLoginPassthroughArgs(args);
@@ -3566,6 +3889,8 @@ async function cmdStatus(options) {
3566
3889
  console.log(JSON.stringify({
3567
3890
  provider: activeProvider.name,
3568
3891
  email: summary.email === "none" ? null : summary.email,
3892
+ label: summary.email === "none" ? null : summary.label,
3893
+ organizationName: summary.organizationName,
3569
3894
  alias: summary.alias,
3570
3895
  managed: summary.managed
3571
3896
  }));
@@ -3574,32 +3899,36 @@ async function cmdStatus(options) {
3574
3899
  if (summary.email === "none") {
3575
3900
  console.log("none");
3576
3901
  } else if (summary.alias) {
3577
- console.log(`${summary.email} [${summary.alias}]`);
3902
+ console.log(`${summary.label} [${summary.alias}]`);
3578
3903
  } else {
3579
- console.log(summary.email);
3904
+ console.log(summary.label);
3580
3905
  }
3581
3906
  console.log(`managed accounts: ${summary.managedCount}`);
3582
3907
  }
3583
3908
  async function getStatusSummaryForActiveProvider() {
3584
- const email = getCurrentAccount();
3909
+ const currentAccount = getCurrentAccountIdentity();
3910
+ const email = currentAccount?.email ?? "none";
3585
3911
  let alias = null;
3586
3912
  let managed = false;
3587
3913
  let managedCount = 0;
3914
+ let label = getCurrentAccountDisplayLabel(currentAccount);
3915
+ let organizationName = currentAccount?.organizationName ?? null;
3588
3916
  if (email !== "none" && existsSync9(activeSequenceFile)) {
3589
3917
  const seq = await loadSequence(activeSequenceFile);
3590
3918
  managedCount = Object.keys(seq.accounts).length;
3591
- for (const account of Object.values(seq.accounts)) {
3592
- if (account.email === email) {
3593
- managed = true;
3594
- alias = account.alias ?? null;
3595
- break;
3596
- }
3919
+ const matchedAccountNum = resolveManagedAccount(seq, currentAccount);
3920
+ if (matchedAccountNum) {
3921
+ const account = seq.accounts[matchedAccountNum];
3922
+ managed = true;
3923
+ alias = account.alias ?? null;
3924
+ label = getAccountDisplayLabel(account);
3925
+ organizationName = account.display?.organizationName ?? organizationName;
3597
3926
  }
3598
3927
  } else if (existsSync9(activeSequenceFile)) {
3599
3928
  const seq = await loadSequence(activeSequenceFile);
3600
3929
  managedCount = Object.keys(seq.accounts).length;
3601
3930
  }
3602
- return { email, alias, managed, managedCount };
3931
+ return { email, alias, managed, managedCount, label, organizationName };
3603
3932
  }
3604
3933
  async function withActiveProvider(provider, fn) {
3605
3934
  const previousProvider = activeProvider.name;
@@ -3650,9 +3979,9 @@ async function cmdStatusAllProviders() {
3650
3979
  if (summary.email === "none") {
3651
3980
  console.log(" none");
3652
3981
  } else if (summary.alias) {
3653
- console.log(` ${summary.email} [${summary.alias}]`);
3982
+ console.log(` ${summary.label} [${summary.alias}]`);
3654
3983
  } else {
3655
- console.log(` ${summary.email}`);
3984
+ console.log(` ${summary.label}`);
3656
3985
  }
3657
3986
  console.log(` managed accounts: ${summary.managedCount}`);
3658
3987
  }
@@ -3666,19 +3995,31 @@ async function cmdAlias(alias, identifier) {
3666
3995
  throw new Error(result.reason);
3667
3996
  }
3668
3997
  const seq = await loadSequence(activeSequenceFile);
3669
- if (identifier && /^\d+$/.test(identifier)) {
3670
- throw new Error("Alias target must be an email, not a number");
3671
- }
3672
3998
  const currentEmail = getCurrentAccount();
3673
- const accountNum = resolveAliasTargetAccount(seq, { identifier, currentEmail });
3674
- if (!accountNum) {
3675
- if (identifier) {
3999
+ const currentIdentity = getCurrentAccountIdentity();
4000
+ let accountNum = null;
4001
+ if (identifier) {
4002
+ const target = resolveAccountTarget(seq, identifier);
4003
+ if (target.status === "ambiguous") {
4004
+ throw new Error(`Multiple managed accounts match ${identifier}. Use account number or alias.`);
4005
+ }
4006
+ if (target.status === "missing") {
3676
4007
  throw new Error(`Account not found: ${identifier}`);
3677
- } else if (currentEmail === "none") {
4008
+ }
4009
+ accountNum = target.accountNum;
4010
+ } else {
4011
+ accountNum = resolveManagedAccount(seq, currentIdentity);
4012
+ if (!accountNum && currentIdentity?.email && currentIdentity.email !== "none") {
4013
+ if (hasMultipleProviderEmailMatches(seq, currentIdentity.email, activeProvider.name)) {
4014
+ throw new Error(`Multiple managed accounts match ${currentIdentity.email}. Use account number or alias.`);
4015
+ }
4016
+ }
4017
+ }
4018
+ if (!accountNum) {
4019
+ if (currentEmail === "none") {
3678
4020
  throw new Error(`No active ${getProviderLabel()} account found. Please log in first.`);
3679
- } else {
3680
- throw new Error(`Current account is not managed: ${currentEmail}`);
3681
4021
  }
4022
+ throw new Error(`Current account is not managed: ${currentEmail}`);
3682
4023
  }
3683
4024
  const updated = setAlias(seq, accountNum, alias);
3684
4025
  await writeJsonAtomic2(activeSequenceFile, updated);
@@ -3686,7 +4027,9 @@ async function cmdAlias(alias, identifier) {
3686
4027
  console.log(`Alias "${alias}" set for ${getDisplayAccountLabel(updated, accountNum)} (${account.email})`);
3687
4028
  }
3688
4029
  async function cmdInteractiveSwitch() {
3689
- const currentEmail = getCurrentAccount();
4030
+ const currentIdentity = getCurrentAccountIdentity();
4031
+ const currentEmail = currentIdentity?.email ?? "none";
4032
+ const currentLabel = getCurrentAccountDisplayLabel(currentIdentity);
3690
4033
  const hasSequence = existsSync9(activeSequenceFile);
3691
4034
  const seq = hasSequence ? await loadSequence(activeSequenceFile) : null;
3692
4035
  if (seq) {
@@ -3695,7 +4038,7 @@ async function cmdInteractiveSwitch() {
3695
4038
  if (!seq || seq.sequence.length === 0) {
3696
4039
  const emptyStateChoices = [
3697
4040
  {
3698
- name: `+ Add current logged-in account${currentEmail === "none" ? "" : ` (${currentEmail})`}`,
4041
+ name: `+ Add current logged-in account${currentEmail === "none" ? "" : ` (${currentLabel})`}`,
3699
4042
  value: ADD_CURRENT_ACCOUNT_CHOICE
3700
4043
  },
3701
4044
  { name: "Back", value: "__back__" }
@@ -3707,8 +4050,8 @@ async function cmdInteractiveSwitch() {
3707
4050
  await cmdAdd();
3708
4051
  return;
3709
4052
  }
3710
- const shouldOfferAddCurrent = currentEmail !== "none" && !accountExists(seq, currentEmail);
3711
- const extraChoices = shouldOfferAddCurrent ? [{ name: `+ Add current logged-in account (${currentEmail})`, value: ADD_CURRENT_ACCOUNT_CHOICE }] : [];
4053
+ const shouldOfferAddCurrent = currentEmail !== "none" && currentIdentity?.identityStatus !== "ambiguous" && !accountExists(seq, currentIdentity ?? currentEmail);
4054
+ const extraChoices = shouldOfferAddCurrent ? [{ name: `+ Add current logged-in account (${currentLabel})`, value: ADD_CURRENT_ACCOUNT_CHOICE }] : [];
3712
4055
  const selected = await pickAccount(seq, `caflip v${package_default.version} \u2014 Switch ${getProviderLabel()} account:`, undefined, extraChoices);
3713
4056
  if (selected === ADD_CURRENT_ACCOUNT_CHOICE) {
3714
4057
  await cmdAdd();
@@ -3738,7 +4081,7 @@ Commands:
3738
4081
  <provider> remove [<email>] Remove an account
3739
4082
  <provider> next Rotate to next account
3740
4083
  <provider> status [--json] Show current active account
3741
- <provider> alias <name> [<email>] Set alias for current or target account
4084
+ <provider> alias <name> [<account>] Set alias for current or target account
3742
4085
  help Show this help
3743
4086
 
3744
4087
  Examples:
@@ -3751,6 +4094,8 @@ Examples:
3751
4094
  caflip claude Pick Claude account interactively
3752
4095
  caflip claude work Switch Claude account by alias
3753
4096
  caflip claude add --alias personal Add current Claude account with alias
4097
+ caflip claude alias work Alias the current Claude account as "work"
4098
+ caflip claude alias work 2 Alias Claude Account-2 as "work"
3754
4099
  caflip claude login Run Claude login and register session
3755
4100
  caflip claude login -- --email me@example.com --sso
3756
4101
  Pass provider-specific flags after --
@@ -3758,8 +4103,13 @@ Examples:
3758
4103
  caflip codex list List managed Codex accounts
3759
4104
  caflip codex login -- --device-auth Run Codex login and register session
3760
4105
  caflip codex add --alias work Add current Codex account with alias
3761
- caflip codex alias work user@company.com
3762
- Set Codex alias for target email`);
4106
+ caflip codex alias work 2
4107
+ Set Codex alias for target account
4108
+
4109
+ Alias targets:
4110
+ <account> can be a list number, an existing alias, or an email when it matches exactly one managed account.
4111
+ Codex labels show workspace plans as email \xB7 plan(orgShortId); free shows email \xB7 free.
4112
+ Claude simplifies the default personal label to email \xB7 Personal.`);
3763
4113
  }
3764
4114
  async function executeProviderCommand(command, args, provider, runWithLock) {
3765
4115
  switch (command) {
@@ -3801,7 +4151,7 @@ async function executeProviderCommand(command, args, provider, runWithLock) {
3801
4151
  break;
3802
4152
  case "alias": {
3803
4153
  if (!args[1]) {
3804
- console.error(`Usage: caflip ${provider} alias <name> [<email>]`);
4154
+ console.error(`Usage: caflip ${provider} alias <name> [<account>]`);
3805
4155
  process.exit(1);
3806
4156
  }
3807
4157
  await runWithLock(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caflip",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "caflip": "bin/caflip"