{"record":{"id":"2c5e71d70a6ae270","repo":"paperclipai/paperclip","slug":"company-id-is-required-pass-company-id-set-pap","errorCode":null,"errorMessage":"Company ID is required. Pass --company-id, set PAPERCLIP_COMPANY_ID, or set context profile companyId via `paperclipai context set`.","messagePattern":"Company ID is required\\. Pass --company-id, set PAPERCLIP_COMPANY_ID, or set context profile companyId via `paperclipai context set`\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/common.ts","lineNumber":68,"sourceCode":"  opts?: { requireCompany?: boolean },\n): ResolvedClientContext {\n  const context = readContext(options.context);\n  const { name: profileName, profile } = resolveProfile(context, options.profile);\n\n  const apiBase = resolveApiBase(options, profile);\n\n  const resolvedApiKey = resolveApiKey(options, profile);\n  const explicitApiKey = resolvedApiKey.value;\n  const storedBoardCredential = explicitApiKey ? null : getStoredBoardCredential(apiBase);\n  const apiKey = explicitApiKey || storedBoardCredential?.token;\n\n  const companyId =\n    options.companyId?.trim() ||\n    process.env.PAPERCLIP_COMPANY_ID?.trim() ||\n    profile.companyId;\n\n  if (opts?.requireCompany && !companyId) {\n    throw new Error(\n      \"Company ID is required. Pass --company-id, set PAPERCLIP_COMPANY_ID, or set context profile companyId via `paperclipai context set`.\",\n    );\n  }\n\n  // Agent-authenticated mutations (checkout, release, interactions, PATCH of an\n  // in-progress issue) require the X-Paperclip-Run-Id header (the server returns\n  // \"401 Agent run id required\" without it). Source it from --run-id, else the\n  // PAPERCLIP_RUN_ID env the adapter/embodiment context already exports.\n  const runId = options.runId?.trim() || process.env.PAPERCLIP_RUN_ID?.trim() || undefined;\n\n  const api = new PaperclipApiClient({\n    apiBase,\n    apiKey,\n    runId,\n    recoverAuth: explicitApiKey || !canAttemptInteractiveBoardAuth()\n      ? undefined\n      : async ({ error }) => {\n          const requestedAccess = error.message.includes(\"Instance admin required\")","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/common.ts#L50-L86","documentation":"Thrown by resolveCommandContext() in common.ts when opts.requireCompany is true and no companyId can be resolved from --company-id, the PAPERCLIP_COMPANY_ID env var, or the active context profile's companyId. Company scope is a control-plane invariant for company-scoped commands; the CLI refuses to call the API without one rather than implicitly acting on the wrong/default company.","triggerScenarios":"Any command marked requireCompany (e.g. `agent local-cli`, and other company-scoped subcommands) invoked without --company-id, without PAPERCLIP_COMPANY_ID exported, and without a companyId set in the current context profile via `paperclipai context set`.","commonSituations":"First run of a company-scoped command before configuring context. Multiple companies and the user forgot to select one. CI runner lacking PAPERCLIP_COMPANY_ID. Profile switched away from one that had companyId.","solutions":["Pass it inline: `--company-id cmp_xxx`.","Or export it: `export PAPERCLIP_COMPANY_ID=cmp_xxx`.","Or persist it in the profile: `paperclipai context set --profile default --company-id cmp_xxx` (then it applies to every command using that profile).","Confirm --profile selection if you have multiple profiles with different companies."],"exampleFix":"// before\npaperclipai agent local-cli agt_1\n// after (pick one)\npaperclipai agent local-cli agt_1 --company-id cmp_xxx\nexport PAPERCLIP_COMPANY_ID=cmp_xxx\npaperclipai context set --company-id cmp_xxx","handlingStrategy":"validation","validationCode":"function resolveCompanyId(opts: { companyId?: string }, profile: { companyId?: string }): string {\n  const id = opts.companyId?.trim() || process.env.PAPERCLIP_COMPANY_ID?.trim() || profile.companyId?.trim();\n  if (!id) {\n    throw new Error('Company ID required. Set one of: --company-id, $PAPERCLIP_COMPANY_ID, or context profile companyId.');\n  }\n  return id;\n}","typeGuard":"function isCompanyId(v: string): v is `${'cmp_'}` is too narrow — instead:\nfunction looksLikeCompanyId(v: unknown): boolean {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try { resolveCommandContext(opts, { requireCompany: true }); }\ncatch (err) {\n  const msg = err instanceof Error ? err.message : '';\n  if (msg.startsWith('Company ID is required.')) {\n    console.error('Set a company: paperclipai context set --company-id cmp_xxx  (or pass --company-id / export PAPERCLIP_COMPANY_ID)');\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Run `paperclipai context set --company-id <id>` once per machine to make companyId ambient.","In CI, always export PAPERCLIP_COMPANY_ID.","When switching instances, update the profile or pass --company-id explicitly.","For library callers, pass { requireCompany: true } early so the error fires before any network call."],"tags":["cli","company-scope","config","validation","context"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}