Skip to content

[BUG] Vertex AI Environment Variables Ignored #2804

Closed as duplicate
Closed as duplicate

Description

@rawwerks

Claude Code Bug Report: Vertex AI Environment Variables Ignored

Environment

  • Platform (select one):
    • Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other:
  • 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:
    export CLAUDE_CODE_USE_VERTEX=0
    export CLAUDE_CODE_SKIP_VERTEX_AUTH=1
    export ANTHROPIC_API_KEY=sk-ant-api03-...
  4. 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)

Activity

  1. rawwerks commented on Jul 1, 2025

    @rawwerks
    Author

    linking this related issue, which made it very hard to figure out what is going on with auth: #2800

  2. kingychiu commented on Jul 27, 2025

    @kingychiu

    Thanks for sharing. I am using this workaround to switch between VertexAI and a personal account:

    Use VertexAI: export CLAUDE_CODE_USE_VERTEX=1
    Use Personal: unset CLAUDE_CODE_USE_VERTEX

  3. github-actions commented on Aug 16, 2025

    @github-actions

    Found 2 possible duplicate issues:

    1. Cloud Service Authentication Failure in Claude Code CLI - google cloud auth coming from claude code PLEASE fix this! Urgent #5808
    2. Environment variables had to be unset to recognize correct plan #4187

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  4. added
    duplicateThis issue or pull request already exists
    and removed
    bugSomething isn't working
    has reproHas detailed reproduction steps
    api:vertexIssue relates to GCP Vertex
    platform:macosIssue specifically occurs on macOS
    on Aug 20, 2025
  5. github-actions commented on Aug 20, 2025

    @github-actions

    This issue has been automatically closed as a duplicate of #5808.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  6. github-actions commented on Aug 27, 2025

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  7. locked as resolved and limited conversation to collaborators on Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions