{"record":{"id":"e51fe52aa86328af","repo":"paperclipai/paperclip","slug":"current-company-is-not-available-pass-company-i","errorCode":null,"errorMessage":"Current company is not available. Pass --company-id, set PAPERCLIP_COMPANY_ID, set a context profile companyId, or authenticate with an agent API key.","messagePattern":"Current company is not available\\. Pass --company-id, set PAPERCLIP_COMPANY_ID, set a context profile companyId, or authenticate with an agent API key\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/company.ts","lineNumber":2041,"sourceCode":"    if (isBoardAccessRequiredError(error) || isInstanceAdminRequiredError(error)) {\n      throw new Error(\n        \"Creating companies requires board/instance-admin authentication. Agent API keys are scoped to one company; use `paperclipai company list --json` or `paperclipai company current --json` to select the scoped company, or rerun create with a board token/login.\",\n      );\n    }\n    throw error;\n  }\n}\n\nasync function resolveCurrentCompanyId(ctx: { companyId?: string; api: { get<T>(path: string): Promise<T | null> } }): Promise<string> {\n  const fromContext = ctx.companyId?.trim();\n  if (fromContext) return fromContext;\n\n  let agent: AgentMeResponse | null = null;\n  try {\n    agent = await ctx.api.get<AgentMeResponse>(\"/api/agents/me\");\n  } catch (error) {\n    if (error instanceof ApiRequestError && (error.status === 401 || error.status === 403)) {\n      throw new Error(\n        \"Current company is not available. Pass --company-id, set PAPERCLIP_COMPANY_ID, set a context profile companyId, or authenticate with an agent API key.\",\n      );\n    }\n    throw error;\n  }\n\n  const fromAgent = agent?.companyId?.trim();\n  if (fromAgent) return fromAgent;\n  throw new Error(\n    \"Current company is not available. Pass --company-id, set PAPERCLIP_COMPANY_ID, set a context profile companyId, or authenticate with an agent API key.\",\n  );\n}\n\nfunction isBoardAccessRequiredError(error: unknown): error is ApiRequestError {\n  return error instanceof ApiRequestError && error.status === 403 && error.message.toLowerCase().includes(\"board access required\");\n}\n\nfunction isInstanceAdminRequiredError(error: unknown): error is ApiRequestError {","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/company.ts#L2023-L2059","documentation":"Thrown in resolveCurrentCompanyId() when GET /api/agents/me returns 401 or 403. This is the first of two identical-message throws: this one fires specifically on an authentication/authorization failure hitting the agent-me endpoint, meaning the caller has no usable credentials to discover their scoped company.","triggerScenarios":"No API key configured and no --company-id/PAPERCLIP_COMPANY_ID/context companyId set, so the CLI tries /api/agents/me which 401s; an expired or revoked agent token; a malformed Authorization header.","commonSituations":"Fresh CLI install with no connect/context; token revoked server-side; PAPERCLIP_API_KEY pointing at a deleted key; api-base pointing at a server that does not recognize the token.","solutions":["Provide the company explicitly: `--company-id <id>`, or set PAPERCLIP_COMPANY_ID.","Authenticate: run `paperclipai connect` or set a valid PAPERCLIP_API_KEY in the referenced env var.","Run `paperclipai context current` to confirm the active profile and its API key env var."],"exampleFix":"# before\npaperclipai company list\n# after\nexport PAPERCLIP_API_KEY=$(cat ~/.paperclip/board-key)\n# or pin the company id\npaperclipai company list --company-id 550e8400-e29b-41d4-a716-446655440000","handlingStrategy":"validation","validationCode":"// Ensure a company id is resolvable without hitting /api/agents/me when auth may be missing.\nfunction ensureCompanyId(ctx: { companyId?: string }): string {\n  const id = ctx.companyId?.trim();\n  if (!id) {\n    throw new Error(\"No company context: pass --company-id, set PAPERCLIP_COMPANY_ID, or authenticate first.\");\n  }\n  return id;\n}","typeGuard":"import { ApiRequestError } from \"../../client/http.js\";\n\nfunction isAuth401or403(err: unknown): boolean {\n  return err instanceof ApiRequestError && (err.status === 401 || err.status === 403);\n}","tryCatchPattern":"try {\n  agent = await ctx.api.get<AgentMeResponse>(\"/api/agents/me\");\n} catch (err) {\n  if (isAuth401or403(err)) {\n    throw new Error(\"Authentication failed; set PAPERCLIP_API_KEY or pass --company-id.\");\n  }\n  throw err;\n}","preventionTips":["Always set an explicit --company-id or PAPERCLIP_COMPANY_ID in automation.","Run `paperclipai connect` once interactively to persist credentials.","Periodically rotate and verify API keys are still valid server-side."],"tags":["cli","authentication","company-id","missing-context","unauthorized"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}