{"record":{"id":"d9148f31ae29e77b","repo":"paperclipai/paperclip","slug":"target-existing-company-requires-company-id-or","errorCode":null,"errorMessage":"Target existing company requires --company-id (or context default companyId).","messagePattern":"Target existing company requires --company-id \\(or context default companyId\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/company.ts","lineNumber":1694,"sourceCode":"          const target = inferredTarget.toLowerCase() as CompanyImportTargetMode;\n          if (![\"new\", \"existing\"].includes(target)) {\n            throw new Error(\"Invalid --target value. Use: new | existing\");\n          }\n\n          const existingTargetCompanyId = opts.companyId?.trim() || ctx.companyId;\n          const targetPayload =\n            target === \"existing\"\n              ? {\n                  mode: \"existing_company\" as const,\n                  companyId: existingTargetCompanyId,\n                }\n              : {\n                  mode: \"new_company\" as const,\n                  newCompanyName: opts.newCompanyName?.trim() || null,\n                };\n\n          if (targetPayload.mode === \"existing_company\" && !targetPayload.companyId) {\n            throw new Error(\"Target existing company requires --company-id (or context default companyId).\");\n          }\n\n          let sourcePayload:\n            | { type: \"inline\"; rootPath?: string | null; files: Record<string, CompanyPortabilityFileEntry> }\n            | { type: \"github\"; url: string };\n          let chunkedZip: { zipBytes: Uint8Array; rootPath: string } | null = null;\n\n          const treatAsLocalPath = !isHttpUrl(from) && await pathExists(from);\n          const isGithubSource = looksLikeRepoUrl(from) || (isGithubShorthand(from) && !treatAsLocalPath);\n\n          if (isHttpUrl(from) || isGithubSource) {\n            if (!looksLikeRepoUrl(from) && !isGithubShorthand(from)) {\n              throw new Error(\n                \"Only GitHub URLs and local paths are supported for import. \" +\n                \"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.\",\n              );\n            }\n            sourcePayload = { type: \"github\", url: normalizeGithubImportSource(from, opts.ref) };","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/company.ts#L1676-L1712","documentation":"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.","triggerScenarios":"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.","commonSituations":"Fresh CLI install with no `paperclipai connect` / context configured; running in CI without setting the company context; agent API key context not loaded.","solutions":["Pass --company-id explicitly: `paperclipai company import <src> --target existing --company-id <id>`.","Set PAPERCLIP_COMPANY_ID in the environment, or run `paperclipai context set` / `paperclipai connect` to persist a profile companyId.","Switch to `--target new` if you intend to create a company rather than import into one."],"exampleFix":"# before\npaperclipai company import ./src --target existing\n# after\npaperclipai company import ./src --target existing --company-id 550e8400-e29b-41d4-a716-446655440000","handlingStrategy":"validation","validationCode":"function resolveExistingCompanyId(flags: { companyId?: string }, ctx: { companyId?: string }): string {\n  const id = (flags.companyId?.trim() || ctx.companyId?.trim());\n  if (!id) {\n    throw new Error(\"--company-id (or PAPERCLIP_COMPANY_ID / context companyId) is required for --target existing\");\n  }\n  return id;\n}","typeGuard":"function hasResolvedCompanyId(v: { companyId?: string }): v is { companyId: string } {\n  return typeof v.companyId === \"string\" && v.companyId.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Run `paperclipai context set` once to persist a default companyId for existing-company imports.","In CI, export PAPERCLIP_COMPANY_ID explicitly.","Default to --target new in provisioning scripts unless you truly merge into an existing company."],"tags":["cli","validation","import","missing-context","company-id"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}