11/**
22 * Claude CLI Tools Configuration Manager
3- * Manages .claude/ cli-tools.json (tools) and .claude/ cli-settings.json (settings)
3+ * Manages cli-tools.json (tools) and cli-settings.json (settings)
44 *
5- * Configuration Strategy:
6- * - READ: Project → Global → Default (fallback chain)
7- * - CREATE: Always in ~/.claude/ (global user-level config)
8- * - SAVE: Based on source (project config saves to project, others to global)
5+ * Configuration Strategy (GLOBAL ONLY):
6+ * - READ: Global → Default (no project-level configs)
7+ * - CREATE/SAVE: Always in ~/.claude/ (global user-level config)
98 *
10- * Read priority:
11- * 1. Project workspace: {projectDir}/.claude/ (if exists)
12- * 2. Global: ~/.claude/ (fallback)
9+ * Config location: ~/.claude/cli-tools.json
10+ * Settings location: ~/.claude/cli-settings.json
11+ *
12+ * Note: Project-level configs are NOT used - all config is user-level.
1313 */
1414import * as fs from 'fs' ;
1515import * as path from 'path' ;
@@ -177,50 +177,35 @@ function getGlobalSettingsPath(): string {
177177}
178178
179179/**
180- * Resolve config path with fallback:
181- * 1. Project: {projectDir}/.claude/cli-tools.json
182- * 2. Global: ~/.claude/cli-tools.json
183- * Returns { path, source } where source is 'project' | 'global' | 'default'
180+ * Resolve config path - GLOBAL ONLY
181+ * Config is user-level, stored only in ~/.claude/cli-tools.json
182+ * Returns { path, source } where source is 'global' | 'default'
184183 */
185184function resolveConfigPath ( projectDir : string ) : { path : string ; source : 'project' | 'global' | 'default' } {
186- const projectPath = getProjectConfigPath ( projectDir ) ;
187- if ( fs . existsSync ( projectPath ) ) {
188- return { path : projectPath , source : 'project' } ;
189- }
190-
191185 const globalPath = getGlobalConfigPath ( ) ;
192186 if ( fs . existsSync ( globalPath ) ) {
193187 return { path : globalPath , source : 'global' } ;
194188 }
195189
196- return { path : projectPath , source : 'default' } ;
190+ // Return global path for default (will be created there)
191+ return { path : globalPath , source : 'default' } ;
197192}
198193
199194/**
200- * Resolve settings path with fallback:
201- * 1. Project: {projectDir}/.claude/cli-settings.json
202- * 2. Global: ~/.claude/cli-settings.json
195+ * Resolve settings path - GLOBAL ONLY
196+ * Settings are user-level, stored only in ~/.claude/cli-settings.json
203197 */
204198function resolveSettingsPath ( projectDir : string ) : { path : string ; source : 'project' | 'global' | 'default' } {
205- const projectPath = getProjectSettingsPath ( projectDir ) ;
206- if ( fs . existsSync ( projectPath ) ) {
207- return { path : projectPath , source : 'project' } ;
208- }
209-
210199 const globalPath = getGlobalSettingsPath ( ) ;
211200 if ( fs . existsSync ( globalPath ) ) {
212201 return { path : globalPath , source : 'global' } ;
213202 }
214203
215- return { path : projectPath , source : 'default' } ;
204+ // Return global path for default (will be created there)
205+ return { path : globalPath , source : 'default' } ;
216206}
217207
218- function ensureClaudeDir ( projectDir : string ) : void {
219- const claudeDir = path . join ( projectDir , '.claude' ) ;
220- if ( ! fs . existsSync ( claudeDir ) ) {
221- fs . mkdirSync ( claudeDir , { recursive : true } ) ;
222- }
223- }
208+ // NOTE: ensureClaudeDir removed - config should only be in ~/.claude/, not project directory
224209
225210// ========== Main Functions ==========
226211
@@ -336,10 +321,8 @@ export function ensureClaudeCliTools(projectDir: string, createInProject: boolea
336321}
337322
338323/**
339- * Load CLI tools configuration with fallback:
340- * 1. Project: {projectDir}/.claude/cli-tools.json
341- * 2. Global: ~/.claude/cli-tools.json
342- * 3. Default config
324+ * Load CLI tools configuration from global ~/.claude/cli-tools.json
325+ * Falls back to default config if not found.
343326 *
344327 * Automatically migrates older config versions to v3.0.0
345328 */
@@ -398,27 +381,18 @@ export function loadClaudeCliTools(projectDir: string): ClaudeCliToolsConfig & {
398381}
399382
400383/**
401- * Save CLI tools configuration
402- * - If config was loaded from project, saves to project
403- * - Otherwise saves to global ~/.claude/cli-tools.json
384+ * Save CLI tools configuration to global ~/.claude/cli-tools.json
385+ * Always saves to global directory (user-level config)
404386 */
405387export function saveClaudeCliTools ( projectDir : string , config : ClaudeCliToolsConfig & { _source ?: string } ) : void {
406388 const { _source, ...configToSave } = config ;
407389
408- // Determine save location based on source
409- let configPath : string ;
410- if ( _source === 'project' ) {
411- // Config was loaded from project, save back to project
412- ensureClaudeDir ( projectDir ) ;
413- configPath = getProjectConfigPath ( projectDir ) ;
414- } else {
415- // Default: save to global directory
416- const globalDir = path . join ( os . homedir ( ) , '.claude' ) ;
417- if ( ! fs . existsSync ( globalDir ) ) {
418- fs . mkdirSync ( globalDir , { recursive : true } ) ;
419- }
420- configPath = getGlobalConfigPath ( ) ;
390+ // Always save to global directory
391+ const globalDir = path . join ( os . homedir ( ) , '.claude' ) ;
392+ if ( ! fs . existsSync ( globalDir ) ) {
393+ fs . mkdirSync ( globalDir , { recursive : true } ) ;
421394 }
395+ const configPath = getGlobalConfigPath ( ) ;
422396
423397 try {
424398 fs . writeFileSync ( configPath , JSON . stringify ( configToSave , null , 2 ) , 'utf-8' ) ;
@@ -430,10 +404,8 @@ export function saveClaudeCliTools(projectDir: string, config: ClaudeCliToolsCon
430404}
431405
432406/**
433- * Load CLI settings configuration with fallback:
434- * 1. Project: {projectDir}/.claude/cli-settings.json
435- * 2. Global: ~/.claude/cli-settings.json
436- * 3. Default settings
407+ * Load CLI settings configuration from global ~/.claude/cli-settings.json
408+ * Falls back to default settings if not found.
437409 */
438410export function loadClaudeCliSettings ( projectDir : string ) : ClaudeCliSettingsConfig & { _source ?: string } {
439411 const resolved = resolveSettingsPath ( projectDir ) ;
@@ -469,14 +441,19 @@ export function loadClaudeCliSettings(projectDir: string): ClaudeCliSettingsConf
469441}
470442
471443/**
472- * Save CLI settings configuration to project .claude/cli-settings.json
444+ * Save CLI settings configuration to global ~/.claude/cli-settings.json
445+ * Always saves to global directory (user-level config)
473446 */
474447export function saveClaudeCliSettings ( projectDir : string , config : ClaudeCliSettingsConfig & { _source ?: string } ) : void {
475- ensureClaudeDir ( projectDir ) ;
476- const settingsPath = getProjectSettingsPath ( projectDir ) ;
477-
478448 const { _source, ...configToSave } = config ;
479449
450+ // Always save to global directory
451+ const globalDir = path . join ( os . homedir ( ) , '.claude' ) ;
452+ if ( ! fs . existsSync ( globalDir ) ) {
453+ fs . mkdirSync ( globalDir , { recursive : true } ) ;
454+ }
455+ const settingsPath = getGlobalSettingsPath ( ) ;
456+
480457 try {
481458 fs . writeFileSync ( settingsPath , JSON . stringify ( configToSave , null , 2 ) , 'utf-8' ) ;
482459 console . log ( `[claude-cli-tools] Saved settings to: ${ settingsPath } ` ) ;
0 commit comments