paperclipai/paperclip · warning · Error
Safety checks failed. Resolve the issues above or re-run wit
Error message
Safety checks failed. Resolve the issues above or re-run with --force.
What it means
Thrown by the worktree clean/remove command when one or more safety problems were detected AND --force was not passed. Problems are collected first and only enforced here: (a) the branch has unique local commits not present on any remote (would lose work), and (b) the worktree directory has uncommitted changes. Each problem is logged via p.log.error before the throw so the user sees specifics. With --force the same problems are downgraded to warnings and cleanup proceeds.
Source
Thrown at cli/src/commands/worktree.ts:2102
} else {
problems.push(
`Branch "${name}" has commits not found on any other branch or remote. ` +
`Deleting it will lose work. Push it first, or use --force.`,
);
}
}
if (hasTargetDir && worktreePathHasUncommittedChanges(targetPath)) {
problems.push(
`Worktree directory ${targetPath} has uncommitted changes. Commit or stash first, or use --force.`,
);
}
if (problems.length > 0 && !opts.force) {
for (const problem of problems) {
p.log.error(problem);
}
throw new Error("Safety checks failed. Resolve the issues above or re-run with --force.");
}
if (problems.length > 0 && opts.force) {
for (const problem of problems) {
p.log.warning(`Overridden by --force: ${problem}`);
}
}
// ── 3. Clean up (idempotent steps) ──────────────────────────────────
// 3a. Remove the git worktree registration
if (linkedWorktree) {
const worktreeDirExists = existsSync(linkedWorktree.worktree);
const spinner = p.spinner();
if (worktreeDirExists) {
spinner.start(`Removing git worktree at ${linkedWorktree.worktree}...`);
try {
const removeArgs = ["worktree", "remove", linkedWorktree.worktree];
if (opts.force) removeArgs.push("--force");View on GitHub (pinned to 67001ec6eb)
Solutions
- Read the logged problems above the error — each names the exact branch/dir and reason.
- Push unique commits (`git push -u origin <name>`) or commit/stash uncommitted changes in the worktree.
- If you are certain the work is disposable, re-run with `--force` to override (the problems become warnings).
- Re-run clean after the data is safely preserved.
Example fix
// before paperclipai worktree:clean feat-x # uncommitted changes / unique commits // after (preserve first) cd /path/to/feat-x && git add -A && git commit -m "wip" && git push -u origin feat-x paperclipai worktree:clean feat-x # or intentional data loss paperclipai worktree:clean feat-x --force
Defensive patterns
Strategy: validation
Validate before calling
function cleanSafetyOk(opts: { force?: boolean }, problems: string[]): boolean {
return problems.length === 0 || opts.force === true;
} Type guard
function hasUncommittedOrUniqueCommits(targetPath: string, branch: string): boolean {
return worktreePathHasUncommittedChanges(targetPath) || branchHasUniqueCommits(process.cwd(), branch);
} Try / catch
try { await worktreeCleanCommand(name, opts); }
catch (err) {
if (/Safety checks failed/.test(String((err as Error).message))) {
await worktreeCleanCommand(name, { ...opts, force: true }); // user-confirmed destructive
} else throw err;
} Prevention
- Push unique branch commits to a remote before cleaning.
- Commit or stash uncommitted worktree changes first.
- Only use --force when you have confirmed the data is disposable.
When it happens
Trigger: Running `paperclipai worktree:clean <name>` where the branch has unpushed unique commits; cleaning a worktree that has modified/tracked files not yet committed; CI trying to auto-clean a worktree the developer left dirty.
Common situations: Developer did work in the worktree but never pushed; merge conflict resolution left uncommitted state; the branch was never pushed to origin before attempting cleanup.
Related errors
- Failed to fetch from remote "${remote}": ${extractExecSyncEr
- Could not resolve worktree "${selector}". Use a path, a list
- Branch name is required.
- Invalid branch name "${branchName}": ${extractExecSyncErrorM
- Current directory is not inside a git repository.
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/782fdc6c326a3e81.
Report an issue: GitHub.