paperclipai/paperclip · error

Target path already exists but is not a registered git…

Error message

Target path already exists but is not a registered git worktree: ${targetPath}

What it means

Repair-safety guard: the target directory for a repaired worktree already exists on disk but is not registered in `git worktree list`, meaning it is an unrelated directory the repair flow must not overwrite or adopt.

Solutions

  1. Choose a different target path, or register/remove the existing directory at that path.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cli/src/commands/worktree.ts:990 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-08-18). Data as JSON: /api/errors/bba92fb454d5336e. Report an issue: GitHub.

Appendix: source

Thrown at cli/src/commands/worktree.ts:1006

      rootPath: existing.worktree,
      configPath: path.resolve(existing.worktree, ".paperclip", "config.json"),
      label: existing.branchLabel,
      branchName: existing.branchLabel === "(detached)" ? null : existing.branchLabel,
      created: false,
    };
  }

  const repoRoot = resolvePrimaryGitRepoRoot(cwd);
  const branchName = validateGitBranchName(repoRoot, input.selector);
  const targetPath = path.resolve(
    repoRoot,
    ".paperclip",
    "worktrees",
    resolveRepairWorktreeDirName(branchName),
  );

  if (existsSync(targetPath)) {
    throw new Error(`Target path already exists but is not a registered git worktree: ${targetPath}`);
  }

  mkdirSync(path.dirname(targetPath), { recursive: true });

  const spinner = p.spinner();
  spinner.start(`Creating git worktree for ${branchName}...`);
  try {
    execFileSync("git", resolveGitWorktreeAddArgs({
      branchName,
      targetPath,
      branchExists: localBranchExists(repoRoot, branchName),
    }), {
      cwd: repoRoot,
      stdio: ["ignore", "pipe", "pipe"],
    });
    spinner.stop(`Created git worktree at ${targetPath}.`);
  } catch (error) {
    spinner.stop(pc.red("Failed to create git worktree."));

View on GitHub (pinned to 01ad858492)