claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

Action uses non-existent model when no model is specified then fails

Open paulyhedral opened this issue 5 months ago • 2 comments

Describe the bug Action falls back to non-existent model when no model is specified.

To Reproduce Steps to reproduce the behavior:

  1. Create workflow that uses this action
  2. Do not specify model in claude_args:
  3. Run workflow

Expected behavior The action should use only models that exist.

Screenshots

  "result": "API Error: 404 {\"type\":\"error\",\"error\":{\"type\":\"not_found_error\",\"message\":\"model: claude-sonnet-4-20250514\"},\"request_id\":\"req_011Cc7Y1xqeS9nphNaytZBrn\"}",

Workflow yml file

        uses: anthropics/claude-code-action@v1
        timeout-minutes: 60
        with:
          anthropic_api_key: XXX
          prompt: XXX

API Provider

[x] Anthropic First-Party API (default) [ ] AWS Bedrock [ ] GCP Vertex

Additional context Add any other context about the problem here.

paulyhedral avatar Jun 16 '26 20:06 paulyhedral

Root cause

When no model is specified, the action passes model: undefined all the way through to the Agent SDK, so the SDK/CLI falls back to its own bundled default model — which in the currently-pinned version resolves to the retired claude-sonnet-4-20250514, hence the 404 not_found_error.

Flow:

  • action.yml defines no model input and never exports ANTHROPIC_MODEL to the run step.
  • src/entrypoints/run.ts → runClaude(..., { model: process.env.ANTHROPIC_MODEL }) → undefined
  • base-action/src/parse-sdk-options.ts → sdkOptions.model = options.model (undefined)
  • base-action/src/run-claude-sdk.ts → query({ options }) → SDK supplies its stale default

Nothing in this repo hardcodes the bad id — it's inherited from the pinned SDK/CLI default, so it silently broke when that snapshot was retired server-side.

Confirmed in the wild

The mutable v1 tag moved to v1.0.149 (Claude Code 2.1.178) on 2026-06-15, which is when this started. A downstream user already hit it and worked around it by pinning --model by hand in their workflow (weside-ai/weside-cli@cee1c50):

- claude_args: "--allowedTools ..."
+ claude_args: "--model claude-sonnet-4-6 --allowedTools ..."

Worth noting their additional finding: with an OAuth token, the 404 retries until the 15-min job timeout, so the run never completes (related to #1386). Every consumer currently has to add --model manually to avoid this.

Proposed fix

Set an explicit default in parseSdkOptions (base-action/src/parse-sdk-options.ts) when the user hasn't supplied one, using a model alias rather than a dated snapshot so it can't rot the same way:

// Fall back to a current model alias when none is supplied, so we never
// inherit a (possibly retired) SDK/CLI default snapshot.
const model = options.model?.trim() || "sonnet";

…and use model in place of options.model when building sdkOptions.

Notes:

  • An explicit --model in claude_args still wins — it's parsed into extraArgs and the CLI gives explicit flags precedence over options.model.
  • The default would be gated to the first-party provider (skip when CLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX / CLAUDE_CODE_USE_FOUNDRY is set), since "sonnet" isn't a valid Bedrock/Vertex/Foundry model id.

This means users no longer need per-repo --model workarounds like the one above.

Test coverage in base-action/test/parse-sdk-options.test.ts: no model → defaults to the alias; explicit options.model preserved; --model in claudeArgs still overrides; Bedrock/Vertex/Foundry → no alias injected.

Question for maintainers

Is delegating the default to the CLI intentional in v1 (e.g. to avoid breaking Bedrock/Vertex model-id formats), or is a first-party default alias acceptable? Happy to open a PR for the gated approach above if so.

farmer-data avatar Jun 22 '26 22:06 farmer-data

Opened a PR with the gated fix I described above: #1432

How it's fixed

The root cause is that with no model anywhere, parseSdkOptions set sdkOptions.model = options.model (undefined), so the SDK/CLI fell back to its bundled default snapshot — the retired claude-sonnet-4-20250514 → 404.

The PR adds a resolveModel() helper in base-action/src/parse-sdk-options.ts that supplies an explicit default when the caller specifies nothing. Notes for maintainers:

  • Alias, not a dated id. Default is the "sonnet" alias (resolved server-side to the current snapshot) rather than a pinned claude-*-YYYYMMDD id, so it can't silently rot the same way the SDK default did.
  • Precedence preserved. Explicit options.model wins → then --model in claudeArgs (kept in extraArgs and passed to the CLI; in that case resolveModel returns undefined so we don't specify the model twice) → then the default alias.
  • Gated to the first-party provider. The default is skipped when CLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX / CLAUDE_CODE_USE_FOUNDRY is set, since "sonnet" isn't a valid Bedrock/Vertex/Foundry model id — those providers continue to resolve their own default.

This removes the need for the per-repo --model workaround.

Test coverage added in base-action/test/parse-sdk-options.test.ts (env-isolated): no model → "sonnet"; explicit options.model preserved/trimmed; --model in claudeArgs still overrides; Bedrock/Vertex/Foundry → no alias injected; explicit model preserved for third-party providers. All 761 tests pass; typecheck and prettier are clean.

Happy to adjust the default alias or the gating approach if you'd prefer something different.

farmer-data avatar Jun 24 '26 23:06 farmer-data