JuliusBrussee/caveman · error · Error

--provider requires a value

Error message

--provider requires a value

What it means

The CLI's argument parser accepts --provider only when followed by a concrete value. When --provider is the last argument or is immediately followed by another --flag, there is no value to consume, so parseArgs throws this error before any scaffolding happens.

Solutions

  1. Provide a value: `--provider anthropic|openai|google`
  2. Reorder arguments so --provider and its value come before other flags
  3. When using npm create, put CLI args after `--` so npm forwards them intact
  4. Check shell history/script for an empty variable used as the provider value

Example fix

// before
npm create @caveman-ai/agent@latest my-app -- --provider
// after
npm create @caveman-ai/agent@latest my-app -- --provider anthropic
Defensive patterns

Strategy: validation

Validate before calling

const i = argv.indexOf("--provider");
if (i !== -1) {
  const v = argv[i + 1];
  if (!v || v.startsWith("--")) throw new Error("--provider requires a value");
}

Type guard

function hasProviderValue(argv: string[]): boolean {
  const i = argv.indexOf("--provider");
  return i !== -1 && i + 1 < argv.length && !argv[i + 1]!.startsWith("--");
}

Try / catch

try {
  const opts = parseArgs(argv);
} catch (error) {
  if (error instanceof Error && error.message.includes("--provider")) {
    console.error("Usage: ... --provider anthropic|openai|google");
    process.exitCode = 1;
  } else throw error;
}

Prevention

When it happens

Trigger: Running the create command with '--provider' as the final argument (e.g. `npm create @caveman-ai/agent@latest my-app -- --provider`) or passing another flag right after it (e.g. `--provider --no-install`); parseArgs sees the next token is missing or starts with '--' and throws.

Common situations: Copy-pasting a documented command but dropping the value; shell snippets where the value was an unexpanded variable ($PROVIDER empty would still be a positional though — more commonly the flag is last); forgetting npm's `--` separator so npm eats the value itself and --provider ends up adjacent to another flag.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/ada48bfbb8c529a1. Report an issue: GitHub.

Appendix: source

Thrown at packages/create-caveman-agent/src/index.ts:67

    "npm run dev",
    "eval starts unapproved; inspect it, set approved: true, then npm run build",
    "",
  ].join("\n"));
}

function parseArgs(args: string[]): {
  target: string;
  provider?: string;
  install: boolean;
} {
  let provider: string | undefined;
  let install = true;
  const positional: string[] = [];
  for (let index = 0; index < args.length; index++) {
    const value = args[index]!;
    if (value === "--provider") {
      const candidate = args[++index];
      if (!candidate || candidate.startsWith("--")) throw new Error("--provider requires a value");
      provider = candidate;
      continue;
    }
    if (value === "--no-install") {
      install = false;
      continue;
    }
    if (value.startsWith("--")) throw new Error(`unknown option ${value}`);
    positional.push(value);
  }
  if (positional.length !== 1) {
    throw new Error(
      USAGE,
    );
  }
  return {
    target: positional[0]!,
    ...(provider === undefined ? {} : { provider }),

View on GitHub (pinned to 3ee70a1026)