D3 · Claude Code › Cluster 2 · Settings & Configuration

2.3 · Environment Variables

Configuring Claude Code via env

CONCEPT Two ways to set an env var — and where they matter

Environment variables configure authentication, provider routing, model choice, timeouts, and telemetry. You can set them two ways, and both feed the same variables:

🔑 The env block in settings.json is the durable, shareable way; a shell export is the ad-hoc, one-terminal way. Managed policy can also pin env vars org-wide.

CONCEPT The variables worth memorising

Grouped by what they control:

VariableGroupPurpose
ANTHROPIC_API_KEYAuthAPI key used when authenticating to the Anthropic API
ANTHROPIC_AUTH_TOKENAuthBearer auth token (sent as Authorization)
ANTHROPIC_MODELModelOverrides the model Claude Code uses
CLAUDE_CODE_USE_BEDROCKProviderRoute through Amazon Bedrock instead of the Anthropic API
CLAUDE_CODE_USE_VERTEXProviderRoute through Google Vertex AI
MAX_THINKING_TOKENSReasoningCap on extended-thinking tokens (0 disables thinking)
BASH_DEFAULT_TIMEOUT_MSToolsDefault timeout for Bash tool commands
DISABLE_TELEMETRYPrivacyTurn off telemetry reporting
DISABLE_AUTOUPDATERUpdatesStop Claude Code from auto-updating
CLAUDE_CODE_API_KEY_HELPER_TTL_MSAuthHow often the apiKeyHelper value is refreshed
NO_COLOR / FORCE_COLORDisplayDisable / force ANSI color output
⚠️ CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_VERTEX are the provider switches. When set, Claude Code authenticates to that cloud (AWS / GCP) instead of the Anthropic API directly, so credentials come from that provider, not ANTHROPIC_API_KEY.

DIAGRAM Which provider does a request hit?

flowchart TD A["claude launches"] --> B{"CLAUDE_CODE_USE_BEDROCK=1?"} B -->|"yes"| BR["Amazon Bedrock
(AWS credentials)"] B -->|"no"| C{"CLAUDE_CODE_USE_VERTEX=1?"} C -->|"yes"| VX["Google Vertex AI
(GCP credentials)"] C -->|"no"| D{"ANTHROPIC_API_KEY set?"} D -->|"yes"| API["Anthropic API
(direct)"] D -->|"no"| LOGIN["Interactive login /
apiKeyHelper output"] classDef prov fill:#cfe2ff,stroke:#3d7bfe,color:#0a3a9a; classDef ok fill:#d4edda,stroke:#28a745,color:#155724; class BR,VX prov; class API,LOGIN ok;

CODE Two ways to set the same variables

Shell exports for a one-off session vs. the durable env block that applies to every launch.

# --- Option A: shell, one session only ---
export ANTHROPIC_MODEL=claude-opus-4-5
export MAX_THINKING_TOKENS=31999
export BASH_DEFAULT_TIMEOUT_MS=120000
claude

# --- Option B: route through Amazon Bedrock instead ---
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
claude
// --- Option C: durable, every session (settings.json) ---
{
  "env": {
    "ANTHROPIC_MODEL": "claude-opus-4-5",
    "MAX_THINKING_TOKENS": "31999",
    "DISABLE_TELEMETRY": "1"
  }
}
🔑 In the env block every value is a string — even numeric ones like "31999" and boolean-ish flags like "1".

TRADE-OFFS Shell export vs. settings.json env

✅ settings.json env

  • Applies to every session automatically
  • Committed & shared (project scope) or org-pinned (managed)
  • Reviewable in version control

⚠️ Shell export

  • Fast, no file edit — great for one-off experiments
  • But: vanishes with the terminal; easy to forget
  • Not shared, so teammates don't get it

EXAM TRAPS

Trap: "ANTHROPIC_MODEL is a settings.json key." → It's an environment variable. The settings.json key for the model is just model (2.2).
Trap: "Set CLAUDE_CODE_USE_BEDROCK and supply ANTHROPIC_API_KEY to use Bedrock." → On Bedrock, auth comes from AWS credentials, not the Anthropic API key. The two provider switches redirect where requests go.
Trap: "MAX_THINKING_TOKENS=0 gives unlimited thinking." → 0 disables extended thinking. A higher number raises the cap.
Trap: "Env values in settings.json can be raw numbers." → They must be quoted strings in JSON.

PRACTICE

Q1 · You want every session in this repo to route through Vertex AI. What do you set, and where's the durable place?

Set CLAUDE_CODE_USE_VERTEX (to "1"). Durably, put it in the env block of .claude/settings.json so it applies on every launch; ad-hoc, you'd export it in your shell.

Q2 · Which variable, set to 0, turns off extended thinking?

MAX_THINKING_TOKENS. Setting it to 0 disables thinking; any positive value caps the thinking-token budget.

Q3 · Name the variable that stops Claude Code from phoning home with telemetry.

DISABLE_TELEMETRY (set to 1). You can put it in the shell or in the settings.json env block.