Environment Variables

export vs Shell RC Files

Why your Claude Code config disappears when you open a new terminal

The Problem

You ran export commands, everything worked, then you opened a new terminal and it broke.

Terminal 1: run export commands
Claude Code works!
Open new Terminal 2
Claude Code: auth error

How Shells Work

Temporary export in terminal

You type export FOO=bar
Lives in this shell process's memory
Shell closes = gone forever

Persistent in ~/.zshrc

You add export FOO=bar to file
Saved on disk in your home directory
Every new shell reads it on startup

Think of it like this

export in terminal Added to ~/.zshrc
Analogy Writing on a whiteboard Writing in a notebook
Survives reboot? No Yes
New terminal? Gone Auto-loaded
VS Code terminals? Not inherited Inherited
Use case Quick test Permanent config

The Three Variables You Need

These tell Claude Code to use our Vertex AI endpoint

# Which vars and why:

CLAUDE_CODE_USE_VERTEX=1
# Use Vertex AI instead of direct API

CLOUD_ML_REGION=global
# Which Vertex region to hit

ANTHROPIC_VERTEX_PROJECT_ID=coe-airs-vertex
# The shared CoE project with Claude models

The Fix: Add to Shell RC

Pick your shell and run this:

macOS default

zsh → ~/.zshrc

# Run this once:
$ cat <<'EOF' >> ~/.zshrc
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=coe-airs-vertex
EOF

# Then reload:
$ source ~/.zshrc
Linux / WSL

bash → ~/.bashrc

# Run this once:
$ cat <<'EOF' >> ~/.bashrc
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=coe-airs-vertex
EOF

# Then reload:
$ source ~/.bashrc

Alternative: VS Code Settings

If you only use Claude Code inside VS Code, this also works

// In VS Code settings.json:

"claudeCode.environmentVariables": [
  {"name": "CLAUDE_CODE_USE_VERTEX", "value": "1"},
  {"name": "CLOUD_ML_REGION", "value": "global"},
  {"name": "ANTHROPIC_VERTEX_PROJECT_ID", "value": "coe-airs-vertex"}
]

This only applies to VS Code terminals. If you use Claude Code from a standalone terminal, use the shell RC method.

Verify It Worked

Open a brand new terminal and run:

# 1. Check all three vars are set:

$ echo $CLAUDE_CODE_USE_VERTEX
1

$ echo $CLOUD_ML_REGION
global

$ echo $ANTHROPIC_VERTEX_PROJECT_ID
coe-airs-vertex

# 2. Actually run Claude Code and send a prompt:

$ claude
# Type anything. If it responds, you're good.
# If you get auth errors, your GCP ADC is the issue, not the env vars.

Key It must be a new terminal. The old one still has them from your export.

Pro Tips

YOLO Mode

Skip permission prompts in labs

$ claude --dangerously-skip-permissions

Claude Code normally asks before running commands, editing files, etc. In a lab environment this gets tedious fast. YOLO mode lets it execute without asking. Don't use this on production code.

VS Code Tip

Install extension, use terminal

The VS Code Claude Code extension auth flow can be finicky. Much easier approach:

1. Install the Claude Code VS Code extension
2. Open the VS Code integrated terminal
3. Run claude from the terminal
4. Auth works through your shell env — no extension auth pain

Common Mistakes

Recap

Step What to do
1 Check your shell: echo $SHELL
2 Add the 3 export lines to ~/.zshrc or ~/.bashrc
3 Run source on that file
4 Open a new terminal and echo each var to verify
5 Run claude and submit a prompt — if it responds, you're good

Questions?