Claude Code Bug Report: Vertex AI Environment Variables Ignored
Environment
- Platform (select one):
- Claude CLI version: 1.0.38
- Operating System: macOS 14.x (darwin 23.2.0)
- Terminal: zsh
Bug Description
Claude Code ignores the environment variables CLAUDE_CODE_USE_VERTEX=0 and CLAUDE_CODE_SKIP_VERTEX_AUTH=1 and still attempts to use Google Vertex AI instead of the direct Anthropic API, even when these variables are explicitly set to disable Vertex AI usage.
Steps to Reproduce
- Install Claude Code 1.0.38 via
npm install -g @anthropic-ai/claude-code
- Have Google Cloud SDK configured on the system (e.g., via
gcloud auth application-default login)
- Set environment variables to disable Vertex AI:
export CLAUDE_CODE_USE_VERTEX=0
export CLAUDE_CODE_SKIP_VERTEX_AUTH=1
export ANTHROPIC_API_KEY=sk-ant-api03-...
- Run Claude Code in any mode:
claude or echo "test" | claude -p
Expected Behavior
Claude Code should:
- Recognize that
CLAUDE_CODE_USE_VERTEX=0 means to NOT use Vertex AI
- Use the direct Anthropic API with the provided
ANTHROPIC_API_KEY
- Skip any Google Cloud/Vertex AI credential detection
Actual Behavior
Claude Code:
- Completely ignores the
CLAUDE_CODE_USE_VERTEX=0 and CLAUDE_CODE_SKIP_VERTEX_AUTH=1 settings
- Attempts to use Google Vertex AI despite explicit configuration to disable it
- Fails with error:
No projectId was given and it could not be resolved from credentials. The client should be instantiated with the 'projectId' option or the 'ANTHROPIC_VERTEX_PROJECT_ID' environment variable should be set.
- Never attempts to use the direct Anthropic API
Additional Context
Workaround Discovered
The issue is resolved by completely removing/unsetting the Vertex environment variables rather than setting them to 0. The presence of these variables (regardless of value) seems to trigger Vertex AI detection.
Working configuration:
# Only this line needed - no Vertex variables at all
export ANTHROPIC_API_KEY=sk-ant-api03-...
Root Cause
Claude Code appears to check for the presence of Vertex environment variables rather than their values. Setting CLAUDE_CODE_USE_VERTEX=0 should explicitly disable Vertex AI, but the current implementation seems to interpret any presence of this variable as intent to use Vertex AI.
Debug Output Showing the Issue
[ERROR] Error streaming, falling back to non-streaming mode: No projectId was given and it could not be resolved from credentials. The client should be instantiated with the `projectId` option or the `ANTHROPIC_VERTEX_PROJECT_ID` environment variable should be set.
This error occurs even with CLAUDE_CODE_USE_VERTEX=0 explicitly set.
Impact
Users with Google Cloud SDK configured cannot easily use Claude Code with direct Anthropic API without completely removing Vertex-related environment variables from their shell configuration. This creates an unnecessary barrier for users who want to use the direct Anthropic API while having Google Cloud tools installed.
Suggested Fix
The environment variable checking logic should verify the value of CLAUDE_CODE_USE_VERTEX, not just its presence:
CLAUDE_CODE_USE_VERTEX=0 or CLAUDE_CODE_USE_VERTEX=false → Use Anthropic API
CLAUDE_CODE_USE_VERTEX=1 or CLAUDE_CODE_USE_VERTEX=true → Use Vertex AI
- Variable not set → Default behavior (likely Anthropic API)
Claude Code Bug Report: Vertex AI Environment Variables Ignored
Environment
Bug Description
Claude Code ignores the environment variables
CLAUDE_CODE_USE_VERTEX=0andCLAUDE_CODE_SKIP_VERTEX_AUTH=1and still attempts to use Google Vertex AI instead of the direct Anthropic API, even when these variables are explicitly set to disable Vertex AI usage.Steps to Reproduce
npm install -g @anthropic-ai/claude-codegcloud auth application-default login)claudeorecho "test" | claude -pExpected Behavior
Claude Code should:
CLAUDE_CODE_USE_VERTEX=0means to NOT use Vertex AIANTHROPIC_API_KEYActual Behavior
Claude Code:
CLAUDE_CODE_USE_VERTEX=0andCLAUDE_CODE_SKIP_VERTEX_AUTH=1settingsNo projectId was given and it could not be resolved from credentials. The client should be instantiated with the 'projectId' option or the 'ANTHROPIC_VERTEX_PROJECT_ID' environment variable should be set.Additional Context
Workaround Discovered
The issue is resolved by completely removing/unsetting the Vertex environment variables rather than setting them to
0. The presence of these variables (regardless of value) seems to trigger Vertex AI detection.Working configuration:
Root Cause
Claude Code appears to check for the presence of Vertex environment variables rather than their values. Setting
CLAUDE_CODE_USE_VERTEX=0should explicitly disable Vertex AI, but the current implementation seems to interpret any presence of this variable as intent to use Vertex AI.Debug Output Showing the Issue
This error occurs even with
CLAUDE_CODE_USE_VERTEX=0explicitly set.Impact
Users with Google Cloud SDK configured cannot easily use Claude Code with direct Anthropic API without completely removing Vertex-related environment variables from their shell configuration. This creates an unnecessary barrier for users who want to use the direct Anthropic API while having Google Cloud tools installed.
Suggested Fix
The environment variable checking logic should verify the value of
CLAUDE_CODE_USE_VERTEX, not just its presence:CLAUDE_CODE_USE_VERTEX=0orCLAUDE_CODE_USE_VERTEX=false→ Use Anthropic APICLAUDE_CODE_USE_VERTEX=1orCLAUDE_CODE_USE_VERTEX=true→ Use Vertex AI