fix(env): forward ANTHROPIC_DEFAULT_*_MODEL to Agent SDK sub-call#1263
Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Open
fix(env): forward ANTHROPIC_DEFAULT_*_MODEL to Agent SDK sub-call#1263MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Closes #1258.
The Agent SDK's top-level call inherits
ANTHROPIC_DEFAULT_SONNET_MODEL(andOPUS/HAIKU) fromprocess.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 viaANTHROPIC_DEFAULT_SONNET_MODEL, sub-calls leak literalclaude-sonnet-4-6to 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.tsalready spreadsprocess.envintosdkOptions.env. The top-level call honours the override, so that path works. Sub-calls go through a fresh CLI subprocess that reads~/.claude/settings.jsonfor env, not the parent's process env, so the override is dropped.What
Mirror the three model-alias env vars into
settings.envfromsetupClaudeCodeSettings. The CLI propagatessettings.envto every session it spawns, including sub-calls, via the documented settings layer (Settings.envin the Agent SDK types).settings.enventries always win on conflict; the action only fills in keys the user did not set.settings.envis written when none of the three are present.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.tsin a newmodel-alias env var forwarding (issue #1258)describe block:settings.env.settings.envis created when none are set.settings.envkeys take precedence over env-var values.beforeEach/afterEachsnapshot and restore the three env vars so the suite is hermetic.bun test base-action/test/setup-claude-code-settings.test.tsANTHROPIC_DEFAULT_SONNET_MODEL=@preset/...in workflow env, run the action, observe sub-call requests now hit the preset rather than literalclaude-sonnet-4-6(per the reproduction in Action ignores ANTHROPIC_DEFAULT_SONNET_MODEL for internal Agent SDK sub-calls (regression in v1.0.104 / claude-cli 2.1.118) #1258).