[BUG] Vertex AI Environment Variables Ignored

Resolved 💬 5 comments Opened Jul 1, 2025 by rawwerks Closed Aug 20, 2025

Claude Code Bug Report: Vertex AI Environment Variables Ignored

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • 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

  1. Install Claude Code 1.0.38 via npm install -g @anthropic-ai/claude-code
  2. Have Google Cloud SDK configured on the system (e.g., via gcloud auth application-default login)
  3. Set environment variables to disable Vertex AI:

``bash
export CLAUDE_CODE_USE_VERTEX=0
export CLAUDE_CODE_SKIP_VERTEX_AUTH=1
export ANTHROPIC_API_KEY=sk-ant-api03-...
``

  1. 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)

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗