{"record":{"id":"bba92fb454d5336e","repo":"paperclipai/paperclip","slug":"target-path-already-exists-but-is-not-a-registered","errorCode":null,"errorMessage":"Target path already exists but is not a registered git worktree: ${targetPath}","messagePattern":"Target path already exists but is not a registered git worktree: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":990,"sourceCode":"      rootPath: existing.worktree,\n      configPath: path.resolve(existing.worktree, \".paperclip\", \"config.json\"),\n      label: existing.branchLabel,\n      branchName: existing.branchLabel === \"(detached)\" ? null : existing.branchLabel,\n      created: false,\n    };\n  }\n\n  const repoRoot = resolvePrimaryGitRepoRoot(cwd);\n  const branchName = validateGitBranchName(repoRoot, input.selector);\n  const targetPath = path.resolve(\n    repoRoot,\n    \".paperclip\",\n    \"worktrees\",\n    resolveRepairWorktreeDirName(branchName),\n  );\n\n  if (existsSync(targetPath)) {\n    throw new Error(`Target path already exists but is not a registered git worktree: ${targetPath}`);\n  }\n\n  mkdirSync(path.dirname(targetPath), { recursive: true });\n\n  const spinner = p.spinner();\n  spinner.start(`Creating git worktree for ${branchName}...`);\n  try {\n    execFileSync(\"git\", resolveGitWorktreeAddArgs({\n      branchName,\n      targetPath,\n      branchExists: localBranchExists(repoRoot, branchName),\n    }), {\n      cwd: repoRoot,\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    });\n    spinner.stop(`Created git worktree at ${targetPath}.`);\n  } catch (error) {\n    spinner.stop(pc.red(\"Failed to create git worktree.\"));","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L972-L1008","documentation":"Thrown by the worktree resolver when the computed target path (.paperclip/worktrees/<slug>) already exists on disk, but resolveExistingGitWorktree did not recognize it as a registered worktree for the selector. This prevents the resolver from clobbering a pre-existing directory with a new git worktree.","triggerScenarios":"A previous worktree creation failed partway leaving the directory behind; a manually-created directory collides with the computed slug; the worktree was removed with rm but its directory was recreated; two branches slug to the same name after normalization.","commonSituations":"Interrupted init leaving stale dirs; branch names that normalize identically (e.g. 'feat/foo' and 'feat-foo'); leftover dirs from a deleted worktree; manual experimentation in .paperclip/worktrees.","solutions":["Remove the stale directory: rm -rf <targetPath>, then retry.","If it is a real git worktree, run `git worktree prune` and re-run with --from <worktree> instead of recreating.","Rename the branch or pass a different selector so the slug does not collide.","Inspect the path: if it contains data you need, back it up before removing."],"exampleFix":"# before: collision\n# after\nrm -rf .paperclip/worktrees/feat-x && paperclipai worktree ...","handlingStrategy":"validation","validationCode":"function targetPathIsClear(targetPath: string): boolean {\n  return !fs.existsSync(targetPath);\n}","typeGuard":null,"tryCatchPattern":"if (fs.existsSync(targetPath)) {\n  if (confirmStale) fs.rmSync(targetPath, { recursive: true, force: true });\n  else throw new Error('Target path exists: ' + targetPath);\n}","preventionTips":["Clean stale .paperclip/worktrees dirs after failed inits.","Use distinct branch slugs to avoid collisions.","Run `git worktree prune` before creating new worktrees."],"tags":["worktree","git","filesystem","conflict"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}