{"record":{"id":"bec02f84ddb998f1","repo":"paperclipai/paperclip","slug":"target-path-already-exists-targetpath","errorCode":null,"errorMessage":"Target path already exists: ${targetPath}","messagePattern":"Target path already exists: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1823,"sourceCode":"    }\n    p.outro(pc.green(\"Worktree database seed complete.\"));\n  } catch (error) {\n    spinner.stop(pc.red(\"Failed to seed worktree database.\"));\n    throw error;\n  }\n}\n\nexport async function worktreeMakeCommand(nameArg: string, opts: WorktreeMakeOptions): Promise<void> {\n  printPaperclipCliBanner();\n  p.intro(pc.bgCyan(pc.black(\" paperclipai worktree:make \")));\n\n  const name = resolveWorktreeMakeName(nameArg);\n  const startPoint = resolveWorktreeStartPoint(opts.startPoint);\n  const sourceCwd = process.cwd();\n  const sourceConfigPath = resolveSourceConfigPath(opts);\n  const targetPath = resolveWorktreeMakeTargetPath(name);\n  if (existsSync(targetPath)) {\n    throw new Error(`Target path already exists: ${targetPath}`);\n  }\n\n  mkdirSync(path.dirname(targetPath), { recursive: true });\n  if (startPoint) {\n    const [remote] = startPoint.split(\"/\", 1);\n    try {\n      execFileSync(\"git\", [\"fetch\", remote], {\n        cwd: sourceCwd,\n        stdio: [\"ignore\", \"pipe\", \"pipe\"],\n      });\n    } catch (error) {\n      throw new Error(\n        `Failed to fetch from remote \"${remote}\": ${extractExecSyncErrorMessage(error) ?? String(error)}`,\n      );\n    }\n  }\n\n  const worktreeArgs = resolveGitWorktreeAddArgs({","sourceCodeStart":1805,"sourceCodeEnd":1841,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L1805-L1841","documentation":"Thrown at the very start of worktreeMakeCommand before any git operation runs: resolveWorktreeMakeTargetPath(name) produced a directory path that already exists on disk. worktree:make creates a NEW git worktree + Paperclip instance, so a pre-existing target directory is treated as a hard stop to avoid overwriting unrelated content.","triggerScenarios":"Running `paperclipai worktree:make <name>` when `<name>` directory already exists in the resolved target location; a previous make crashed after mkdir but before git worktree add; a directory with the same name was created manually.","commonSituations":"Re-running make after a failed attempt without cleanup; name collision with an existing sibling directory; CI runner not cleaned between runs.","solutions":["Remove or rename the existing directory at the path shown in the error, then re-run.","Use a different worktree name to avoid the collision.","If the directory is a leftover from a failed make, run `paperclipai worktree:clean <name>` to tear it down properly first."],"exampleFix":"// before\npaperclipai worktree:make feat-x   # ./feat-x already exists\n// after\nrm -rf ./feat-x   # or: paperclipai worktree:clean feat-x\npaperclipai worktree:make feat-x","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nconst targetPath = resolveWorktreeMakeTargetPath(name);\nif (existsSync(targetPath)) {\n  throw new Error(`Refusing to overwrite existing directory ${targetPath}`);\n}","typeGuard":"function targetPathFree(p: string): boolean { return !existsSync(p); }","tryCatchPattern":"try { await worktreeMakeCommand(name, opts); }\ncatch (err) {\n  if (/Target path already exists/.test(String((err as Error).message))) {\n    // pick a new name or clean first\n  } else throw err;\n}","preventionTips":["Choose unique worktree names.","Run `worktree:clean <name>` before re-making the same name.","Check `ls` for the target directory before make in automated flows."],"tags":["worktree","validation","git","filesystem"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}