{"record":{"id":"3c36941bb45271ae","repo":"paperclipai/paperclip","slug":"anthropic-api-key-is-required-in-the-cli-process-e","errorCode":null,"errorMessage":"ANTHROPIC_API_KEY is required in the CLI process environment","messagePattern":"ANTHROPIC_API_KEY is required in the CLI process environment","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/managed-agent.ts","lineNumber":70,"sourceCode":"function record(value: unknown): Record<string, unknown> {\n  return value && typeof value === \"object\" && !Array.isArray(value)\n    ? (value as Record<string, unknown>)\n    : {};\n}\n\nfunction required(value: string | undefined, label: string): string {\n  const normalized = value?.trim() ?? \"\";\n  if (!normalized) throw new Error(`${label} is required`);\n  return normalized;\n}\n\nexport function validateManagedAgentSetup(\n  options: ManagedAgentSetupOptions,\n  env: NodeJS.ProcessEnv = process.env,\n): ValidatedSetup {\n  const anthropicApiKey = env.ANTHROPIC_API_KEY?.trim();\n  if (!anthropicApiKey) {\n    throw new Error(\"ANTHROPIC_API_KEY is required in the CLI process environment\");\n  }\n  if (!options.acknowledgeRetention) {\n    throw new Error(\n      \"Pass --acknowledge-retention to enable the stateful beta Managed Agents service\",\n    );\n  }\n\n  const profileKey = required(options.profileKey, \"--profile-key\");\n  const displayName = required(options.displayName, \"--display-name\");\n  const apiKeySecretId = required(options.apiKeySecretId, \"--api-key-secret-id\");\n  const model = required(options.model, \"--model\");\n  if (model !== CLAUDE_MANAGED_QUALIFIED_MODEL) {\n    throw new Error(\n      `--model must be the qualified Managed Agents model ${CLAUDE_MANAGED_QUALIFIED_MODEL}`,\n    );\n  }\n  if (!UUID_RE.test(apiKeySecretId)) {\n    throw new Error(\"--api-key-secret-id must be a UUID\");","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/paperclipai/paperclip/blob/5716fe907e596ce73501408fc6efdb19fb61edf2/cli/src/commands/managed-agent.ts#L52-L88","documentation":"`validateManagedAgentSetup` reads `ANTHROPIC_API_KEY` from the CLI process environment and throws this when it is absent or blank. The Managed Agents beta calls Anthropic's API directly from the CLI, so a key in the local process env is mandatory; a key stored only as a Paperclip secret is not sufficient for setup.","triggerScenarios":"Running any managed-agent command (setup, probe, etc.) in a shell where ANTHROPIC_API_KEY is unset, empty, or whitespace-only; invoking validateManagedAgentSetup with a custom `env` object that lacks the key; running under CI/schedulers that sanitize the environment.","commonSituations":"New machine or container without the env var exported; `.env` files not loaded into the process environment; using a different var name like ANTHROPIC_API_TOKEN; dotenv loaded in a subshell but not the one running the CLI.","solutions":["Export the key before running: export ANTHROPIC_API_KEY=sk-ant-...","Pass it inline: ANTHROPIC_API_KEY=sk-ant-... paperclip managed-agent ...","If using a .env file, ensure it is actually loaded into the process (e.g. with dotenv-cli), not just present on disk","Verify with `printenv ANTHROPIC_API_KEY` in the same shell that runs the CLI"],"exampleFix":"// before\n$ paperclip managed-agent setup ...\n// Error: ANTHROPIC_API_KEY is required in the CLI process environment\n// after\n$ export ANTHROPIC_API_KEY=sk-ant-...\n$ paperclip managed-agent setup ...","handlingStrategy":"validation","validationCode":"if (!process.env.ANTHROPIC_API_KEY?.trim()) {\n  throw new Error(\"Set ANTHROPIC_API_KEY in the environment before running managed-agent commands\");\n}","typeGuard":"function hasAnthropicKey(env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & { ANTHROPIC_API_KEY: string } {\n  return typeof env.ANTHROPIC_API_KEY === \"string\" && env.ANTHROPIC_API_KEY.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runCommand();\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"ANTHROPIC_API_KEY is required\")) {\n    console.error(\"Export ANTHROPIC_API_KEY=sk-ant-... and retry\"); process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Export ANTHROPIC_API_KEY in shell profiles or CI secret env, not just .env files on disk","Use dotenv-cli or similar to inject .env values into the actual process","Verify with `printenv ANTHROPIC_API_KEY` in the same shell that runs the CLI","Use the exact variable name; do not alias to ANTHROPIC_API_TOKEN"],"tags":["cli","environment","authentication","anthropic"],"backgroundTag":"missing-env-var","analyzedSha":"5716fe907e596ce73501408fc6efdb19fb61edf2","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}