@@ -13,6 +13,7 @@ class ConfigManager {
1313 this . claudeDir = path . join ( this . homeDir , ".claude" ) ;
1414 this . ccCliDir = path . join ( this . homeDir , ".cc-cli" ) ;
1515 this . settingsPath = path . join ( this . claudeDir , "settings.json" ) ;
16+ this . claudeConfigPath = path . join ( this . claudeDir , "config.json" ) ;
1617
1718 // 查找配置文件路径,优先使用 .cc-cli,兼容 .claude
1819 this . configPath = this . findConfigPath ( ) ;
@@ -190,6 +191,23 @@ class ConfigManager {
190191 }
191192 }
192193
194+ /**
195+ * 读取config.json配置
196+ * @returns {Object } config配置对象
197+ */
198+ async getClaudeConfigJson ( ) {
199+ try {
200+ if ( ! ( await fs . pathExists ( this . claudeConfigPath ) ) ) {
201+ return { } ;
202+ }
203+ const configContent = await fs . readFile ( this . claudeConfigPath , "utf8" ) ;
204+ return JSON . parse ( configContent ) ;
205+ } catch ( error ) {
206+ console . warn ( chalk . yellow ( "⚠️ 读取~/.claude/config.json失败:" ) , error . message ) ;
207+ return { } ;
208+ }
209+ }
210+
193211 /**
194212 * 读取settings.json配置
195213 * @returns {Object } settings配置对象
@@ -207,6 +225,23 @@ class ConfigManager {
207225 }
208226 }
209227
228+ /**
229+ * 保存config.json配置
230+ * @param {Object } config config配置对象
231+ */
232+ async saveClaudeConfigJson ( config ) {
233+ try {
234+ await this . ensureConfigDir ( ) ;
235+ await fs . writeFile (
236+ this . claudeConfigPath ,
237+ JSON . stringify ( config , null , 2 ) ,
238+ "utf8"
239+ ) ;
240+ } catch ( error ) {
241+ throw new Error ( `保存~/.claude/config.json失败: ${ error . message } ` ) ;
242+ }
243+ }
244+
210245 /**
211246 * 保存settings.json配置
212247 * @param {Object } settings settings配置对象
@@ -279,8 +314,17 @@ class ConfigManager {
279314
280315 await this . saveCurrentConfig ( config ) ;
281316
282- // 读取当前settings.json
317+ // 读取当前settings.json 和 config.json
283318 const currentSettings = await this . getSettings ( ) ;
319+ const currentConfigJson = await this . getClaudeConfigJson ( ) ;
320+
321+ // 清空现有的config.json的primaryApiKey配置
322+ if ( currentConfigJson . primaryApiKey ) {
323+ delete currentConfigJson . primaryApiKey ;
324+ }
325+
326+ // 为config.json添加站点名称的配置解决强制登陆问题:https://linux.do/t/topic/999263/13
327+ currentConfigJson . primaryApiKey = config . siteName ;
284328
285329 // 需要删除重置的配置项
286330 if ( currentSettings . env ) {
@@ -313,8 +357,9 @@ class ConfigManager {
313357 // 深度合并配置
314358 const mergedSettings = this . deepMerge ( currentSettings , configToMerge ) ;
315359
316- // 保存合并后的settings.json
360+ // 保存合并后的settings.json 和 config.json
317361 await this . saveSettings ( mergedSettings ) ;
362+ await this . saveClaudeConfigJson ( currentConfigJson ) ;
318363
319364 return config ;
320365 } catch ( error ) {
0 commit comments