{"record":{"id":"fb8cb94854d934a8","repo":"yamadashy/repomix","slug":"skill-directory-already-exists-skilldir-use","errorCode":null,"errorMessage":"Skill directory already exists: ${skillDir}. Use --force to overwrite.","messagePattern":"Skill directory already exists: (.+?)\\. Use --force to overwrite\\.","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/cli/prompts/skillPrompts.ts","lineNumber":130,"sourceCode":"  force: boolean,\n  deps = {\n    access: fs.access,\n    rm: fs.rm,\n    stat: fs.stat,\n  },\n): Promise<void> => {\n  try {\n    await deps.access(skillDir);\n    // Path exists - check if it's a directory\n    const stats = await deps.stat(skillDir);\n    if (!stats.isDirectory()) {\n      throw new RepomixError(`Skill output path exists but is not a directory: ${skillDir}`);\n    }\n    // Directory exists\n    if (force) {\n      await deps.rm(skillDir, { recursive: true, force: true });\n    } else {\n      throw new RepomixError(`Skill directory already exists: ${skillDir}. Use --force to overwrite.`);\n    }\n  } catch (error) {\n    // Re-throw if it's not a \"file not found\" error\n    if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') {\n      throw error;\n    }\n    // Directory doesn't exist - good to go\n  }\n};\n\n/**\n * Resolve skill output path and prepare directory for non-interactive mode.\n * Returns the resolved skill directory path.\n */\nexport const resolveAndPrepareSkillDir = async (skillOutput: string, cwd: string, force: boolean): Promise<string> => {\n  const skillDir = path.isAbsolute(skillOutput) ? skillOutput : path.resolve(cwd, skillOutput);\n  await prepareSkillDir(skillDir, force);\n  return skillDir;","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/cli/prompts/skillPrompts.ts#L112-L148","documentation":"Also in prepareSkillDir (non-interactive skill generation): if the target path exists and IS a directory but `force` is false, Repomix refuses to overwrite and throws this error telling you to use --force. Only an ENOENT (path does not exist) is treated as success; any other error — including this one — propagates. This protects existing skill content from being silently rm -rf'd by regeneration.","triggerScenarios":"Running skill generation non-interactively with an output path whose directory already exists (from a previous generation or manual creation) without passing --force. resolveAndPrepareSkillDir -> prepareSkillDir detects access()+isDirectory() and force=false.","commonSituations":"Re-running skill generation for a skill you generated before; CI reruns without force; directory pre-created by scaffolding tools or a repo checkout.","solutions":["Re-run with `--force` to delete the existing skill directory and regenerate it (confirm the contents are disposable first).","Delete or move the existing directory manually, then re-run without --force.","Choose a different output path/skill name if you want to keep both versions.","In scripts, gate on existence first if you need to avoid ever passing --force blindly."],"exampleFix":"# before\nrepomix --skill --output .claude/skills/my-skill\n# Error: Skill directory already exists...\n\n# after\nrepomix --skill --output .claude/skills/my-skill --force","handlingStrategy":"validation","validationCode":"import fs from 'node:fs/promises';\nlet exists = false;\ntry { await fs.access(skillDir); exists = true; } catch {}\nif (exists && !force) {\n  console.error(`${skillDir} already exists; pass --force to overwrite.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await resolveAndPrepareSkillDir(skillOutput, cwd, force);\n} catch (e) {\n  if (e instanceof RepomixError && e.message.includes('Skill directory already exists')) {\n    console.error('Re-run with --force or remove the directory first.');\n  } else throw e;\n}","preventionTips":["Add --force in CI/scripts only when the target directory is disposable.","Back up the existing skill directory if its contents matter.","Use fresh output paths when generating variants.","Gate reruns on a version/checksum so regeneration only happens when content changed."],"tags":["filesystem","skill-generation","overwrite-conflict","cli"],"backgroundTag":"output-already-exists","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}