paperclipai/paperclip · error · Error
Target path already exists: ${targetPath}
Error message
Target path already exists: ${targetPath} What it means
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.
Source
Thrown at cli/src/commands/worktree.ts:1823
}
p.outro(pc.green("Worktree database seed complete."));
} catch (error) {
spinner.stop(pc.red("Failed to seed worktree database."));
throw error;
}
}
export async function worktreeMakeCommand(nameArg: string, opts: WorktreeMakeOptions): Promise<void> {
printPaperclipCliBanner();
p.intro(pc.bgCyan(pc.black(" paperclipai worktree:make ")));
const name = resolveWorktreeMakeName(nameArg);
const startPoint = resolveWorktreeStartPoint(opts.startPoint);
const sourceCwd = process.cwd();
const sourceConfigPath = resolveSourceConfigPath(opts);
const targetPath = resolveWorktreeMakeTargetPath(name);
if (existsSync(targetPath)) {
throw new Error(`Target path already exists: ${targetPath}`);
}
mkdirSync(path.dirname(targetPath), { recursive: true });
if (startPoint) {
const [remote] = startPoint.split("/", 1);
try {
execFileSync("git", ["fetch", remote], {
cwd: sourceCwd,
stdio: ["ignore", "pipe", "pipe"],
});
} catch (error) {
throw new Error(
`Failed to fetch from remote "${remote}": ${extractExecSyncErrorMessage(error) ?? String(error)}`,
);
}
}
const worktreeArgs = resolveGitWorktreeAddArgs({View on GitHub (pinned to 67001ec6eb)
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.
Example fix
// before paperclipai worktree:make feat-x # ./feat-x already exists // after rm -rf ./feat-x # or: paperclipai worktree:clean feat-x paperclipai worktree:make feat-x
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from "node:fs";
const targetPath = resolveWorktreeMakeTargetPath(name);
if (existsSync(targetPath)) {
throw new Error(`Refusing to overwrite existing directory ${targetPath}`);
} Type guard
function targetPathFree(p: string): boolean { return !existsSync(p); } Try / catch
try { await worktreeMakeCommand(name, opts); }
catch (err) {
if (/Target path already exists/.test(String((err as Error).message))) {
// pick a new name or clean first
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Re-running make after a failed attempt without cleanup; name collision with an existing sibling directory; CI runner not cleaned between runs.
Related errors
- Branch name is required.
- Invalid branch name "${branchName}": ${extractExecSyncErrorM
- Target path already exists but is not a registered git workt
- ${extractExecSyncErrorMessage(error) ?? String(error)}
- Worktree config already exists at ${paths.configPath} or ins
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/bec02f84ddb998f1.
Report an issue: GitHub.