{"record":{"id":"c2c9de6365a07d26","repo":"paperclipai/paperclip","slug":"current-checkout-is-the-primary-repo-worktree-pas","errorCode":null,"errorMessage":"Current checkout is the primary repo worktree. Pass --branch to create or repair a linked worktree.","messagePattern":"Current checkout is the primary repo worktree\\. Pass --branch to create or repair a linked worktree\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/src/commands/worktree.ts","lineNumber":4404,"sourceCode":"  await runWorktreeReseed(opts);\n}\n\nexport async function worktreeRepairCommand(opts: WorktreeRepairOptions): Promise<void> {\n  printPaperclipCliBanner();\n  p.intro(pc.bgCyan(pc.black(\" paperclipai worktree repair \")));\n\n  const seedMode = opts.seedMode ?? \"minimal\";\n  if (!isWorktreeSeedMode(seedMode)) {\n    throw new Error(`Unsupported seed mode \"${seedMode}\". Expected one of: minimal, full.`);\n  }\n\n  const target = await ensureRepairTargetWorktree({\n    selector: nonEmpty(opts.branch) ?? undefined,\n    seedMode,\n    opts,\n  });\n  if (!target) {\n    p.log.warn(\"Current checkout is the primary repo worktree. Pass --branch to create or repair a linked worktree.\");\n    p.outro(pc.yellow(\"No worktree repaired.\"));\n    return;\n  }\n\n  const source = resolveWorktreeRepairSource(opts);\n  if (!existsSync(source.configPath)) {\n    throw new Error(`Source config not found at ${source.configPath}.`);\n  }\n  if (path.resolve(source.configPath) === path.resolve(target.configPath)) {\n    throw new Error(\"Source and target Paperclip configs are the same. Use --from-config/--from-instance to point repair at a different source.\");\n  }\n\n  const targetConfig = existsSync(target.configPath) ? readConfig(target.configPath) : null;\n  const targetEnvEntries = readPaperclipEnvEntries(resolvePaperclipEnvFile(target.configPath));\n  const targetHasWorktreeEnv = Boolean(\n    nonEmpty(targetEnvEntries.PAPERCLIP_HOME) && nonEmpty(targetEnvEntries.PAPERCLIP_INSTANCE_ID),\n  );\n","sourceCodeStart":4386,"sourceCodeEnd":4422,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/cli/src/commands/worktree.ts#L4386-L4422","documentation":"`paperclipai worktree repair` resolves its target via ensureRepairTargetWorktree({ selector: opts.branch }). With no --branch and the current checkout already being the repository's primary worktree, there is no linked worktree to repair, so the command warns and exits ('No worktree repaired.') without touching anything. Repair is deliberately scoped to linked worktrees so the primary checkout's instance is never reseeded by accident.","triggerScenarios":"Running `paperclipai worktree repair` from the main repo checkout with no --branch flag.","commonSituations":"Running repair from the repo root by habit; CI checkout which is always the primary worktree; forgetting that repair targets a linked worktree.","solutions":["Pass --branch <name> so repair creates or repairs a linked worktree for that branch.","Or cd into the linked worktree you want repaired and re-run the command there."],"exampleFix":"# before\n$ paperclipai worktree repair   # run from primary checkout\n! Current checkout is the primary repo worktree. Pass --branch ...\n\n# after\n$ paperclipai worktree repair --branch feature-x","handlingStrategy":"validation","validationCode":"import { execSync } from \"node:child_process\";\nconst commonDir = execSync(\"git rev-parse --git-common-dir\").toString().trim();\nconst gitDir = execSync(\"git rev-parse --git-dir\").toString().trim();\nconst isPrimaryWorktree = gitDir === commonDir;\nif (isPrimaryWorktree && !branchFlag) {\n  console.error(\"Run from a linked worktree or pass --branch\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --branch <name> when scripting worktree repair.","Run repair from inside the linked worktree when repairing an existing one.","Never expect repair to operate on the primary checkout — the guard is intentional."],"tags":["cli","worktree","git","repair"],"backgroundTag":"git-worktree-target-missing","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}