paperclipai/paperclip · error · Error

Target path already exists but is not a registered git workt

Error message

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

What it means

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.

Source

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

      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 67001ec6eb)

Solutions

  1. Remove the stale directory: rm -rf <targetPath>, then retry.
  2. If it is a real git worktree, run `git worktree prune` and re-run with --from <worktree> instead of recreating.
  3. Rename the branch or pass a different selector so the slug does not collide.
  4. Inspect the path: if it contains data you need, back it up before removing.

Example fix

# before: collision
# after
rm -rf .paperclip/worktrees/feat-x && paperclipai worktree ...
Defensive patterns

Strategy: validation

Validate before calling

function targetPathIsClear(targetPath: string): boolean {
  return !fs.existsSync(targetPath);
}

Try / catch

if (fs.existsSync(targetPath)) {
  if (confirmStale) fs.rmSync(targetPath, { recursive: true, force: true });
  else throw new Error('Target path exists: ' + targetPath);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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