paperclipai/paperclip · error · Error

Invalid --target value. Use: new | existing

Error message

Invalid --target value. Use: new | existing

What it means

Thrown when `opts.target` lowercased is neither 'new' nor 'existing'. The --target flag selects whether import creates a brand-new company or imports into an existing one. Note target is inferred when omitted (new vs existing based on companyId context), so this throw only fires on an explicit, invalid value.

Source

Thrown at cli/src/commands/client/company.ts:1678

          }
          const ctx = resolveCommandContext(opts);
          const interactiveView = isInteractiveTerminal() && !ctx.json;
          const from = fromPathOrUrl.trim();
          if (!from) {
            throw new Error("Source path or URL is required.");
          }

          const include = resolveImportInclude(opts.include);
          const agents = parseAgents(opts.agents);
          const collision = (opts.collision ?? "rename").toLowerCase() as CompanyCollisionMode;
          if (!["rename", "skip", "replace"].includes(collision)) {
            throw new Error("Invalid --collision value. Use: rename, skip, replace");
          }

          const inferredTarget = opts.target ?? (opts.companyId || ctx.companyId ? "existing" : "new");
          const target = inferredTarget.toLowerCase() as CompanyImportTargetMode;
          if (!["new", "existing"].includes(target)) {
            throw new Error("Invalid --target value. Use: new | existing");
          }

          const existingTargetCompanyId = opts.companyId?.trim() || ctx.companyId;
          const targetPayload =
            target === "existing"
              ? {
                  mode: "existing_company" as const,
                  companyId: existingTargetCompanyId,
                }
              : {
                  mode: "new_company" as const,
                  newCompanyName: opts.newCompanyName?.trim() || null,
                };

          if (targetPayload.mode === "existing_company" && !targetPayload.companyId) {
            throw new Error("Target existing company requires --company-id (or context default companyId).");
          }

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Use `--target new` (create a company) or `--target existing` (import into an existing one).
  2. Omit --target entirely to let the CLI infer it from whether --company-id is present.
  3. Check `paperclipai company import --help` for the canonical values.

Example fix

# before
paperclipai company import ./src --target create
# after
paperclipai company import ./src --target new
Defensive patterns

Strategy: validation

Validate before calling

const TARGET_MODES = ["new", "existing"] as const;
type TargetMode = typeof TARGET_MODES[number];
function normalizeTarget(v: string | undefined, hasCompanyId: boolean): TargetMode {
  const lower = (v ?? (hasCompanyId ? "existing" : "new")).trim().toLowerCase();
  if (!TARGET_MODES.includes(lower as TargetMode)) {
    throw new Error(`Invalid target '${v}'; expected new or existing`);
  }
  return lower as TargetMode;
}

Type guard

function isTargetMode(v: unknown): v is "new" | "existing" {
  return typeof v === "string" && ["new", "existing"].includes(v.toLowerCase());
}

Prevention

When it happens

Trigger: Passing `--target create`, `--target current`, `--target both`, or any value outside the two allowed tokens.

Common situations: Developer assumes 'create' is the verb for new companies; copying flag vocabulary from another CLI; typo from `--target exitsting`.

Related errors


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