{"record":{"id":"2695e803bdeafd62","repo":"ruvnet/ruflo","slug":"config-file-already-exists-targetpath-use-f","errorCode":null,"errorMessage":"Config file already exists: ${targetPath}. Use --force to overwrite.","messagePattern":"Config file already exists: (.+?)\\. Use --force to overwrite\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"v3/@claude-flow/cli/src/services/config-file-manager.ts","lineNumber":125,"sourceCode":"    const config = this.getConfig(cwd);\n    return getNestedValue(config, key);\n  }\n\n  /** Set a nested config value by dot-separated key */\n  set(cwd: string, key: string, value: unknown): void {\n    const config = this.getConfig(cwd);\n    setNestedValue(config, key, value);\n    this.config = config;\n    const targetPath = this.configPath ?? path.resolve(cwd, CONFIG_FILENAMES[0]);\n    this.writeAtomic(targetPath, config);\n    this.configPath = targetPath;\n  }\n\n  /** Create a new config file with defaults */\n  create(cwd: string, overrides?: Record<string, unknown>, force?: boolean): string {\n    const targetPath = path.resolve(cwd, CONFIG_FILENAMES[0]);\n    if (fs.existsSync(targetPath) && !force) {\n      throw new Error(`Config file already exists: ${targetPath}. Use --force to overwrite.`);\n    }\n    const config = { ...DEFAULT_CONFIG, ...overrides };\n    this.writeAtomic(targetPath, config);\n    this.config = config;\n    this.configPath = targetPath;\n    return targetPath;\n  }\n\n  /** Reset config to defaults */\n  reset(cwd: string): string {\n    const targetPath = this.configPath ?? path.resolve(cwd, CONFIG_FILENAMES[0]);\n    this.writeAtomic(targetPath, DEFAULT_CONFIG);\n    this.config = { ...DEFAULT_CONFIG };\n    this.configPath = targetPath;\n    return targetPath;\n  }\n\n  /** Export config to a specific path */","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/services/config-file-manager.ts#L107-L143","documentation":"ConfigFileManager.create refuses to overwrite an existing claude-flow.config.json (resolved from cwd) unless force=true. This is a deliberate guard preventing a re-init from clobbering hand-tuned configuration.","triggerScenarios":"Calling manager.create(cwd) when claude-flow.config.json (or .claude-flow/config.json via CONFIG_FILENAMES[0]) already exists at that path, and force was not passed.","commonSituations":"Running `init` twice in the same project; a CI step re-initializes over a checked-in config; the file was created by an earlier session and the operator forgot it persists.","solutions":["Pass force=true if you intentionally want to overwrite: manager.create(cwd, overrides, true).","Use manager.set(cwd, key, value) to mutate an existing config instead of recreating it.","Call manager.findConfig(cwd) first and skip create() if it returns a path.","Delete the existing file if it is stale."],"exampleFix":"// before\nmanager.create(cwd, overrides); // throws if config exists\n\n// after\nif (!manager.findConfig(cwd)) {\n  manager.create(cwd, overrides);\n} else {\n  manager.set(cwd, 'agents.maxConcurrent', 16);\n}","handlingStrategy":"validation","validationCode":"const existing = manager.findConfig(cwd);\nif (existing) {\n  // mutate instead of recreate, or pass force:true intentionally\n  manager.set(cwd, key, value);\n} else {\n  manager.create(cwd, overrides);\n}","typeGuard":null,"tryCatchPattern":"try {\n  manager.create(cwd, overrides);\n} catch (e) {\n  if ((e as Error).message.startsWith('Config file already exists')) {\n    manager.create(cwd, overrides, /* force */ true);\n  } else throw e;\n}","preventionTips":["Call findConfig(cwd) before create() to detect an existing config.","Prefer set() to mutate an existing config rather than recreating it.","Only pass force:true when you intend to discard the current config.","Treat config files as user-owned state; do not re-init in automated flows without a check."],"tags":["config","filesystem","typescript"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}