Skip to content

fix(env): forward ANTHROPIC_DEFAULT_*_MODEL to Agent SDK sub-call#1263

Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:fix/issue-1258-forward-model-aliases
Open

fix(env): forward ANTHROPIC_DEFAULT_*_MODEL to Agent SDK sub-call#1263
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:fix/issue-1258-forward-model-aliases

Conversation

@MukundaKatta
Copy link
Copy Markdown

@MukundaKatta MukundaKatta commented Apr 26, 2026

Why

Closes #1258.

The Agent SDK's top-level call inherits ANTHROPIC_DEFAULT_SONNET_MODEL (and OPUS/HAIKU) from process.env, but spawned sub-call subprocesses (Task tool, sub-agents) drop them and fall back to the SDK's hardcoded default. With a non-Anthropic preset configured via ANTHROPIC_DEFAULT_SONNET_MODEL, sub-calls leak literal claude-sonnet-4-6 to the proxy and silently bill the user for Sonnet calls they did not request - see the issue's smoking-gun OpenRouter generation log.

The action.yml already forwards these env vars to the bun process, and parse-sdk-options.ts already spreads process.env into sdkOptions.env. The top-level call honours the override, so that path works. Sub-calls go through a fresh CLI subprocess that reads ~/.claude/settings.json for env, not the parent's process env, so the override is dropped.

What

Mirror the three model-alias env vars into settings.env from setupClaudeCodeSettings. The CLI propagates settings.env to every session it spawns, including sub-calls, via the documented settings layer (Settings.env in the Agent SDK types).

  • User-provided settings.env entries always win on conflict; the action only fills in keys the user did not set.
  • Empty/unset env vars are skipped - no settings.env is written when none of the three are present.
  • All three (ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL) are handled in the same loop.

Tested

Added five unit tests under base-action/test/setup-claude-code-settings.test.ts in a new model-alias env var forwarding (issue #1258) describe block:

  • All three env vars mirrored into settings.env.
  • Only the env vars that are set get forwarded.
  • No settings.env is created when none are set.
  • User-provided settings.env keys take precedence over env-var values.
  • Empty env var values are skipped.

beforeEach/afterEach snapshot and restore the three env vars so the suite is hermetic.

The Agent SDK's top-level call inherits ANTHROPIC_DEFAULT_SONNET_MODEL
(and OPUS/HAIKU) from process.env, but spawned sub-call subprocesses
(Task tool, sub-agents) drop them and fall back to the SDK's hardcoded
default. With a non-Anthropic preset configured via
ANTHROPIC_DEFAULT_SONNET_MODEL, sub-calls leak literal
`claude-sonnet-4-6` to the proxy and silently bill the user for Sonnet
calls they did not request.

Mirror the model-alias env vars into settings.env from setupClaude
CodeSettings so the CLI propagates them to every session via the
documented settings layer. User-provided settings.env entries take
precedence; only missing keys are filled in.

Closes anthropics#1258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action ignores ANTHROPIC_DEFAULT_SONNET_MODEL for internal Agent SDK sub-calls (regression in v1.0.104 / claude-cli 2.1.118)

1 participant