paperclipai/paperclip · error · Error

Target existing company requires --company-id (or context de

Error message

Target existing company requires --company-id (or context default companyId).

What it means

Thrown when the import target mode resolves to 'existing_company' but no company ID was found. The ID is sourced from --company-id, then the context profile's companyId. Importing into an existing company requires knowing which one; without it the server cannot route the import.

Source

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

          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).");
          }

          let sourcePayload:
            | { type: "inline"; rootPath?: string | null; files: Record<string, CompanyPortabilityFileEntry> }
            | { type: "github"; url: string };
          let chunkedZip: { zipBytes: Uint8Array; rootPath: string } | null = null;

          const treatAsLocalPath = !isHttpUrl(from) && await pathExists(from);
          const isGithubSource = looksLikeRepoUrl(from) || (isGithubShorthand(from) && !treatAsLocalPath);

          if (isHttpUrl(from) || isGithubSource) {
            if (!looksLikeRepoUrl(from) && !isGithubShorthand(from)) {
              throw new Error(
                "Only GitHub URLs and local paths are supported for import. " +
                "Generic HTTP URLs are not supported. Use a GitHub or GitHub Enterprise URL (https://github.com/... or https://ghe.example.com/...) or a local directory path.",
              );
            }
            sourcePayload = { type: "github", url: normalizeGithubImportSource(from, opts.ref) };

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Pass --company-id explicitly: `paperclipai company import <src> --target existing --company-id <id>`.
  2. Set PAPERCLIP_COMPANY_ID in the environment, or run `paperclipai context set` / `paperclipai connect` to persist a profile companyId.
  3. Switch to `--target new` if you intend to create a company rather than import into one.

Example fix

# before
paperclipai company import ./src --target existing
# after
paperclipai company import ./src --target existing --company-id 550e8400-e29b-41d4-a716-446655440000
Defensive patterns

Strategy: validation

Validate before calling

function resolveExistingCompanyId(flags: { companyId?: string }, ctx: { companyId?: string }): string {
  const id = (flags.companyId?.trim() || ctx.companyId?.trim());
  if (!id) {
    throw new Error("--company-id (or PAPERCLIP_COMPANY_ID / context companyId) is required for --target existing");
  }
  return id;
}

Type guard

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

Prevention

When it happens

Trigger: Running `paperclipai company import <src> --target existing` without --company-id and with no context profile companyId set; the PAPERCLIP_COMPANY_ID env var and context profile are both unset/empty.

Common situations: Fresh CLI install with no `paperclipai connect` / context configured; running in CI without setting the company context; agent API key context not loaded.

Related errors


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