66 *
77 * Login-per-profile model: Each profile is an isolated Claude instance.
88 * Users login directly in each instance (no credential copying).
9+ *
10+ * Supports dual-mode configuration:
11+ * - Unified YAML format (config.yaml) when CCS_UNIFIED_CONFIG=1 or config.yaml exists
12+ * - Legacy JSON format (profiles.json) as fallback
913 */
1014
1115import { spawn , ChildProcess } from 'child_process' ;
@@ -29,6 +33,8 @@ import {
2933import { detectClaudeCli } from '../utils/claude-detector' ;
3034import { InteractivePrompt } from '../utils/prompt' ;
3135import packageJson from '../../package.json' ;
36+ import { hasUnifiedConfig } from '../config/unified-config-loader' ;
37+ import { isUnifiedConfigEnabled } from '../config/feature-flags' ;
3238
3339interface AuthCommandArgs {
3440 profileName ?: string ;
@@ -66,6 +72,13 @@ class AuthCommands {
6672 this . instanceMgr = new InstanceManager ( ) ;
6773 }
6874
75+ /**
76+ * Check if unified config mode is active
77+ */
78+ private isUnifiedMode ( ) : boolean {
79+ return hasUnifiedConfig ( ) || isUnifiedConfigEnabled ( ) ;
80+ }
81+
6982 /**
7083 * Show help for auth commands
7184 */
@@ -152,8 +165,10 @@ class AuthCommands {
152165 process . exit ( 1 ) ;
153166 }
154167
155- // Check if profile already exists
156- if ( ! force && this . registry . hasProfile ( profileName ) ) {
168+ // Check if profile already exists (check both legacy and unified)
169+ const existsLegacy = this . registry . hasProfile ( profileName ) ;
170+ const existsUnified = this . registry . hasAccountUnified ( profileName ) ;
171+ if ( ! force && ( existsLegacy || existsUnified ) ) {
157172 console . log ( fail ( `Profile already exists: ${ profileName } ` ) ) ;
158173 console . log ( ` Use ${ color ( '--force' , 'command' ) } to overwrite` ) ;
159174 process . exit ( 1 ) ;
@@ -164,15 +179,25 @@ class AuthCommands {
164179 console . log ( info ( `Creating profile: ${ profileName } ` ) ) ;
165180 const instancePath = this . instanceMgr . ensureInstance ( profileName ) ;
166181
167- // Create/update profile entry
168- if ( this . registry . hasProfile ( profileName ) ) {
169- this . registry . updateProfile ( profileName , {
170- type : 'account' ,
171- } ) ;
182+ // Create/update profile entry based on config mode
183+ if ( this . isUnifiedMode ( ) ) {
184+ // Use unified config (config.yaml)
185+ if ( existsUnified ) {
186+ this . registry . touchAccountUnified ( profileName ) ;
187+ } else {
188+ this . registry . createAccountUnified ( profileName ) ;
189+ }
172190 } else {
173- this . registry . createProfile ( profileName , {
174- type : 'account' ,
175- } ) ;
191+ // Use legacy profiles.json
192+ if ( existsLegacy ) {
193+ this . registry . updateProfile ( profileName , {
194+ type : 'account' ,
195+ } ) ;
196+ } else {
197+ this . registry . createProfile ( profileName , {
198+ type : 'account' ,
199+ } ) ;
200+ }
176201 }
177202
178203 console . log ( info ( `Instance directory: ${ instancePath } ` ) ) ;
@@ -458,7 +483,11 @@ class AuthCommands {
458483 process . exit ( 1 ) ;
459484 }
460485
461- if ( ! this . registry . hasProfile ( profileName ) ) {
486+ // Check existence in both legacy and unified
487+ const existsLegacy = this . registry . hasProfile ( profileName ) ;
488+ const existsUnified = this . registry . hasAccountUnified ( profileName ) ;
489+
490+ if ( ! existsLegacy && ! existsUnified ) {
462491 console . log ( fail ( `Profile not found: ${ profileName } ` ) ) ;
463492 process . exit ( 1 ) ;
464493 }
@@ -501,8 +530,13 @@ class AuthCommands {
501530 // Delete instance
502531 this . instanceMgr . deleteInstance ( profileName ) ;
503532
504- // Delete profile
505- this . registry . deleteProfile ( profileName ) ;
533+ // Delete profile from appropriate config
534+ if ( this . isUnifiedMode ( ) && existsUnified ) {
535+ this . registry . removeAccountUnified ( profileName ) ;
536+ }
537+ if ( existsLegacy ) {
538+ this . registry . deleteProfile ( profileName ) ;
539+ }
506540
507541 console . log ( ok ( `Profile removed: ${ profileName } ` ) ) ;
508542 console . log ( '' ) ;
@@ -527,7 +561,12 @@ class AuthCommands {
527561 }
528562
529563 try {
530- this . registry . setDefaultProfile ( profileName ) ;
564+ // Use unified or legacy based on config mode
565+ if ( this . isUnifiedMode ( ) ) {
566+ this . registry . setDefaultUnified ( profileName ) ;
567+ } else {
568+ this . registry . setDefaultProfile ( profileName ) ;
569+ }
531570
532571 console . log ( ok ( `Default profile set: ${ profileName } ` ) ) ;
533572 console . log ( '' ) ;
0 commit comments