paperclipai/paperclip · warning

Current checkout is the primary repo worktree. Pass --branch

Error message

Current checkout is the primary repo worktree. Pass --branch to create or repair a linked worktree.

What it means

`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.

Source

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

  await runWorktreeReseed(opts);
}

export async function worktreeRepairCommand(opts: WorktreeRepairOptions): Promise<void> {
  printPaperclipCliBanner();
  p.intro(pc.bgCyan(pc.black(" paperclipai worktree repair ")));

  const seedMode = opts.seedMode ?? "minimal";
  if (!isWorktreeSeedMode(seedMode)) {
    throw new Error(`Unsupported seed mode "${seedMode}". Expected one of: minimal, full.`);
  }

  const target = await ensureRepairTargetWorktree({
    selector: nonEmpty(opts.branch) ?? undefined,
    seedMode,
    opts,
  });
  if (!target) {
    p.log.warn("Current checkout is the primary repo worktree. Pass --branch to create or repair a linked worktree.");
    p.outro(pc.yellow("No worktree repaired."));
    return;
  }

  const source = resolveWorktreeRepairSource(opts);
  if (!existsSync(source.configPath)) {
    throw new Error(`Source config not found at ${source.configPath}.`);
  }
  if (path.resolve(source.configPath) === path.resolve(target.configPath)) {
    throw new Error("Source and target Paperclip configs are the same. Use --from-config/--from-instance to point repair at a different source.");
  }

  const targetConfig = existsSync(target.configPath) ? readConfig(target.configPath) : null;
  const targetEnvEntries = readPaperclipEnvEntries(resolvePaperclipEnvFile(target.configPath));
  const targetHasWorktreeEnv = Boolean(
    nonEmpty(targetEnvEntries.PAPERCLIP_HOME) && nonEmpty(targetEnvEntries.PAPERCLIP_INSTANCE_ID),
  );

View on GitHub (pinned to a7e689b3c3)

Solutions

  1. Pass --branch <name> so repair creates or repairs a linked worktree for that branch.
  2. Or cd into the linked worktree you want repaired and re-run the command there.

Example fix

# before
$ paperclipai worktree repair   # run from primary checkout
! Current checkout is the primary repo worktree. Pass --branch ...

# after
$ paperclipai worktree repair --branch feature-x
Defensive patterns

Strategy: validation

Validate before calling

import { execSync } from "node:child_process";
const commonDir = execSync("git rev-parse --git-common-dir").toString().trim();
const gitDir = execSync("git rev-parse --git-dir").toString().trim();
const isPrimaryWorktree = gitDir === commonDir;
if (isPrimaryWorktree && !branchFlag) {
  console.error("Run from a linked worktree or pass --branch");
}

Prevention

When it happens

Trigger: Running `paperclipai worktree repair` from the main repo checkout with no --branch flag.

Common situations: Running repair from the repo root by habit; CI checkout which is always the primary worktree; forgetting that repair targets a linked worktree.

Related errors


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