paperclipai/paperclip · error · Error

Worktree selector cannot be empty.

Error message

Worktree selector cannot be empty.

What it means

Thrown by resolveWorktreeEndpointFromSelector after trimming the selector and finding it empty (length 0). The selector identifies a worktree endpoint for merge/seed operations (a path, a listed worktree dir name, a branch name, or 'current'). An empty/whitespace-only selector cannot resolve to anything and is rejected before any filesystem or git lookup.

Source

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

  if (choice.isCurrent) {
    return resolveCurrentWorktreeEndpoint();
  }
  return {
    rootPath: choice.worktree,
    configPath: path.resolve(choice.worktree, ".paperclip", "config.json"),
    label: choice.branchLabel,
    isCurrent: false,
  };
}

function resolveWorktreeEndpointFromSelector(
  selector: string,
  opts?: { allowCurrent?: boolean },
): ResolvedWorktreeEndpoint {
  const trimmed = selector.trim();
  const allowCurrent = opts?.allowCurrent !== false;
  if (trimmed.length === 0) {
    throw new Error("Worktree selector cannot be empty.");
  }

  const currentEndpoint = resolveCurrentWorktreeEndpoint();
  if (allowCurrent && trimmed === "current") {
    return currentEndpoint;
  }

  const choices = toMergeSourceChoices(process.cwd());
  const directPath = path.resolve(trimmed);
  if (existsSync(directPath)) {
    if (allowCurrent && directPath === currentEndpoint.rootPath) {
      return currentEndpoint;
    }
    const configPath = path.resolve(directPath, ".paperclip", "config.json");
    if (!existsSync(configPath)) {
      throw new Error(`Resolved worktree path ${directPath} does not contain .paperclip/config.json.`);
    }
    return {

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Provide a non-empty selector: an absolute/relative path, a worktree directory name, a branch name, or the literal 'current'.
  2. If driving the CLI programmatically, validate the selector is non-empty before invoking.
  3. Use 'current' to target the worktree you're inside.

Example fix

// before
paperclipai worktree:merge-history --source ""
// after
paperclipai worktree:merge-history --source current
Defensive patterns

Strategy: validation

Validate before calling

const trimmed = selector.trim();
if (trimmed.length === 0) throw new Error("Selector required: path, name, branch, or 'current'");

Type guard

function isNonEmptySelector(v: unknown): v is string {
  return typeof v === "string" && v.trim().length > 0;
}

Prevention

When it happens

Trigger: Passing an empty string as the worktree selector argument; a wrapper script passes an unset env var (empty); shell quoting produced an empty token.

Common situations: Programmatic caller forgot to set the selector variable; `paperclipai worktree:<cmd> ""`; selector sourced from a missing env var.

Related errors


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