◉CLAUDE LABJP
●CC 2.1.332 — No new Claude Code release over the weekend. 2.1.332 (11/25) is still current●ANALYTICS — A fix to search counts in the Enterprise Analytics API may raise numbers from 11/17 onward●SONNET 4.5 — Today, 11/30, is Sonnet 4.5's last day on the Claude API. Move to claude-sonnet-5-5●USAGE — Some users report weekly usage jumping right after upgrading to a higher plan●NEW — New: Does what a Project remembers carry over into your everyday chats?●BILLING — More readers are looking for what to check when a payment won't go through●CC 2.1.332 — No new Claude Code release over the weekend. 2.1.332 (11/25) is still current●ANALYTICS — A fix to search counts in the Enterprise Analytics API may raise numbers from 11/17 onward●SONNET 4.5 — Today, 11/30, is Sonnet 4.5's last day on the Claude API. Move to claude-sonnet-5-5●USAGE — Some users report weekly usage jumping right after upgrading to a higher plan●NEW — New: Does what a Project remembers carry over into your everyday chats?●BILLING — More readers are looking for what to check when a payment won't go through
Articles/Claude Code
⟐ Claude Code/2026-04-24Advanced

Claude Code Environment Variables: What Exists, Where to Set It, and Why It Isn't Taking Effect

A rebuilt reference to Claude Code environment variables, checked name by name against the official docs. Where to set a variable (shell or the settings env block), which value wins when two sources disagree, defaults for auth, models, timeouts and logging, a troubleshooting table, and templates for solo, team and CI use (as of November 2026).

Claude Code295environment variables6API28PowerShelloperations33CI/CD19

I had doubled API_TIMEOUT_MS in my shell profile, opened a fresh terminal, and re-run a long diff review. It stopped at exactly the same point as before. echo showed the new value sitting right there in the shell, so for a while I simply stared at it.

The culprit was an old value I had put in the env block of ~/.claude/settings.json months earlier and forgotten. Claude Code writes each env entry into its own process environment, replacing whatever it inherited from the shell. I had been looking in the wrong place the whole time.

This page is rewritten for anyone in the same spot. It walks the order I now use: does the variable exist → where did I set it → which source wins.

One thing I owe you up front: earlier versions of this page listed several variables that are not in the official reference. In November 2026 I went through the official Environment variables page line by line, removed the names that don't exist, and replaced them with the mechanisms that actually do the job. If you used the old version, I'm sorry, and the correction table below should save you some time.

Correcting the record: names that don't exist, and what to use instead

Claude Code gives no error and no warning when it sees a variable name it doesn't know. That is exactly why "is this name in the official list?" is the cheapest first check when something has no effect.

Name in the old versionRealityUse instead
ANTHROPIC_TEMPERATURENot in the official listClaude Code has no temperature variable. Steer output through CLAUDE.md, the model, and effort
CLAUDE_CODE_DEBUG / CLAUDE_CODE_DEBUG_PROMPT / CLAUDE_CODE_DEBUG_API / CLAUDE_CODE_LOG_FILEDon't existDEBUG=1 or claude --debug; output path via CLAUDE_CODE_DEBUG_LOGS_DIR
CLAUDE_CODE_TELEMETRY / CLAUDE_CODE_CRASH_REPORTINGDon't existDISABLE_TELEMETRY / DISABLE_ERROR_REPORTING / CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
CLAUDE_CODE_REQUEST_TIMEOUT / CLAUDE_CODE_TOOL_TIMEOUT / CLAUDE_CODE_RETRY_BASE_MSDon't existAPI_TIMEOUT_MS / BASH_DEFAULT_TIMEOUT_MS / BASH_MAX_TIMEOUT_MS / MCP_TOOL_TIMEOUT
CLAUDE_CODE_REQUIRE_APPROVALDoesn't existPermission modes (permissions.defaultMode in settings, or --permission-mode)
CLAUDE_CODE_SANDBOX / CLAUDE_CODE_PROJECT_SCOPE_STRICTDon't existThe sandbox.enabled setting plus permissions allow / deny rules
CLAUDE_CODE_MAX_PARALLEL_TOOL_CALLSDoesn't existI haven't been able to confirm any official equivalent
ANTHROPIC_SMALL_FAST_MODELExists but DEPRECATEDANTHROPIC_DEFAULT_HAIKU_MODEL

The other misconception was that environment variables sit at the bottom of a single precedence ladder. In practice it differs per variable: ANTHROPIC_MODEL is read before the model setting, and CLAUDE_CODE_EFFORT_LEVEL overrides both --effort and /effort. The next two sections separate "where" from "who wins".

Where to set it: your shell or the settings env block

There are two places. A value you export lasts for that terminal session; a value in a settings file's env block applies every time claude runs, however it was launched.

{
  "env": {
    "API_TIMEOUT_MS": "1200000",
    "BASH_DEFAULT_TIMEOUT_MS": "300000"
  }
}

No shell processes env values, so ~ and $HOME stay exactly as typed. For path variables such as CLAUDE_CONFIG_DIR, write the absolute path.

FileApplies toGood for
~/.claude/settings.jsonYou, every projectPersonal preferences: timeouts, turning off reporting
.claude/settings.jsonEveryone on the project (checked in)Model pins or MCP timeouts the repo should share
.claude/settings.local.jsonYou, this project onlyLocal experiments
Managed settingsEveryone in the organizationGateway endpoints, telemetry policy

Be aware that project and local settings silently drop some variables. CLAUDE_CONFIG_DIR, CLAUDE_CODE_TMPDIR, HOME, TMPDIR, and the OpenTelemetry exporter variables, among others, are things a checked-out repository shouldn't control, so they only work from your shell, user settings, or managed settings. claude --debug shows the warning when one is dropped.

Who wins when two sources disagree

This is where my night went sideways, so here is the official behavior arranged the way I actually use it:

  • Shell vs settings env: in most sessions the settings file wins, because Claude Code writes each env entry into the process environment over the inherited value
  • Between settings files: normal settings precedence applies, so managed settings override the same variable in user or project settings
  • Against CLI flags and in-session commands: it varies per feature. --model and /model beat ANTHROPIC_MODEL; CLAUDE_CODE_EFFORT_LEVEL beats --effort and /effort
  • Against a dedicated settings key: also per key. ANTHROPIC_MODEL is read first, and the model setting is only used when the variable is unset

When a value won't take, check the settings env blocks first and the shell last. That's the order I've stuck to since.

You can also neutralize a variable you can't unset. If a shell profile you don't control exports a stale CLAUDE_CODE_USE_VERTEX, setting it to an empty string in env makes Claude Code treat it as unset for provider selection:

{
  "env": {
    "CLAUDE_CODE_USE_VERTEX": ""
  }
}

Timing matters too. Shell variables are read once at startup. Settings env values are reapplied to a running session when you save the file, except for features that only read at startup, such as OpenTelemetry. Deleting a line from env doesn't unset it in the running session; that takes effect on the next launch.

Authentication and endpoints

Knowing the order Claude Code uses when several credentials are present is what keeps you from billing the wrong account. As of November 2026 the official order is:

  1. Cloud provider credentials, when CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, or CLAUDE_CODE_USE_FOUNDRY is set
  2. ANTHROPIC_AUTH_TOKEN (sent as Authorization: Bearer, for gateways)
  3. ANTHROPIC_API_KEY (sent as X-Api-Key)
  4. Output of the apiKeyHelper setting
  5. CLAUDE_CODE_OAUTH_TOKEN (a long-lived token from claude setup-token)
  6. Anthropic profile and federation credentials
  7. Subscription credentials from /login

So even if you've signed in with Pro or Max, a leftover ANTHROPIC_API_KEY in your shell is chosen first. In interactive mode you're asked once whether to use the key, and you can change that later with the "Use custom API key" toggle in /config.

# Direct Anthropic API
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
 
# Through a company gateway that authenticates with bearer tokens
export ANTHROPIC_BASE_URL="https://llm-gateway.example.internal"
export ANTHROPIC_AUTH_TOKEN="YOUR_GATEWAY_TOKEN"
 
# Amazon Bedrock (AWS_REGION is optional if your AWS profile sets one)
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION="us-east-1"
 
# Google Cloud's Agent Platform (Vertex AI)
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION="global"
export ANTHROPIC_VERTEX_PROJECT_ID="your-gcp-project"

Rather than keeping an API key in plain text in a shell profile, I'd store it in the macOS Keychain and let apiKeyHelper fetch it. Anything in env sits in the settings file as plain text and is passed to every subprocess Claude Code starts.

# One-time setup
security add-generic-password -a "$USER" -s "anthropic-api-key" -w "YOUR_ANTHROPIC_API_KEY"
{
  "apiKeyHelper": "security find-generic-password -a $USER -s anthropic-api-key -w"
}

apiKeyHelper runs through a shell, so $USER expands here, unlike values in env.

Models and how much the model thinks

VariableWhat it doesWatch out for
ANTHROPIC_MODELThe model to useLoses to --model and /model; beats the model setting
ANTHROPIC_DEFAULT_MODELDefault model for new sessions (v2.1.236+)Has no effect while ANTHROPIC_MODEL is set
ANTHROPIC_DEFAULT_OPUS_MODEL / _SONNET_MODEL / _HAIKU_MODELWhat each alias resolves toThe Haiku one also drives background tasks
CLAUDE_CODE_SUBAGENT_MODELDefault model for subagentsAn agent definition's model, or a model passed at spawn, takes precedence
CLAUDE_CODE_EFFORT_LEVELlow through maxStronger than --effort and /effort; a maxEffortLevel cap still applies
CLAUDE_CODE_MAX_OUTPUT_TOKENSOutput token limitValues above the model's cap are lowered to the cap
MAX_THINKING_TOKENSFixed extended-thinking budgetCapped one below max output; 0 disables

Aliases resolve differently per provider. In the official table as of November 2026, sonnet is Sonnet 5.5 on the Anthropic API but Sonnet 4.5 on Amazon Bedrock and Agent Platform. Share one .claude/settings.json with a teammate on Bedrock and the same sonnet runs two different models. When versions need to match, pin a full ID such as claude-opus-5-5, or set ANTHROPIC_DEFAULT_SONNET_MODEL.

export ANTHROPIC_MODEL="sonnet"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5-20251001"
export CLAUDE_CODE_SUBAGENT_MODEL="haiku"
export CLAUDE_CODE_EFFORT_LEVEL="medium"

The ANTHROPIC_MODEL versus ANTHROPIC_DEFAULT_MODEL trap gets its own write-up in Adding ANTHROPIC_DEFAULT_MODEL without removing ANTHROPIC_MODEL doesn't change the starting model.

Timeouts and retries

If you add a value without knowing the default, it's easy to think you shortened something you actually lengthened. Official defaults as of November 2026:

VariableApplies toDefault
API_TIMEOUT_MSEach API attempt, until response headers arrive600000 (10 min)
BASH_DEFAULT_TIMEOUT_MSForeground Bash / PowerShell commands120000 (2 min)
BASH_MAX_TIMEOUT_MSThe ceiling the model may request600000 (10 min)
MCP_TIMEOUTMCP server startup30000 (30 s)
MCP_TOOL_TIMEOUTMCP tool execution100000000 (about 28 h)
CLAUDE_CODE_MAX_RETRIESRetries for failed API requests10

API_TIMEOUT_MS covers the wait for headers, not how long a stream runs afterward. If long responses are what stall, MCP and command timeouts are usually the better first suspects.

MCP is the deepest trap. HTTP, SSE, and claude.ai connector servers also have a 60-second per-request limit, which only rises when MCP_TOOL_TIMEOUT or the per-server timeout is set above 60000. Setting it lower shortens the overall limit but leaves the 60 seconds in place. I wrote up how I ran into that in My MCP timeout setting was ignored and every call died at exactly 60 seconds.

Retries default to 10 but can stop earlier on 529 overloaded errors. In CI, I'd rather cap hangs with BASH_DEFAULT_TIMEOUT_MS and a job-level timeout than by cutting retries, because the log then tells you where it stopped.

Logs, telemetry and history

# Turn on debug logging (same as --debug)
export DEBUG=1
# Change where it's written (a FILE path, despite the name; this alone enables nothing)
export CLAUDE_CODE_DEBUG_LOGS_DIR="$HOME/claude-debug.txt"
 
# Opt out of telemetry and error reporting
export DISABLE_TELEMETRY=1
export DISABLE_ERROR_REPORTING=1
 
# Turn off auto-updates, telemetry, error reporting, release notes and similar traffic at once
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
 
# For throwaway scripted runs: keep prompt history and transcripts off disk
export CLAUDE_CODE_SKIP_PROMPT_HISTORY=1

Two of these behave against intuition. DISABLE_TELEMETRY and DISABLE_ERROR_REPORTING still opt out when set to 0 or false; any non-empty value counts, so unset the variable to turn them back on. And CLAUDE_CODE_DEBUG_LOGS_DIR takes a file path, not a directory, and writes nothing unless DEBUG=1 or --debug is also set. The default location is ~/.claude/debug/<session-id>.txt.

Turning telemetry off also turns off feature-flag fetching, which disables some features. The official page lists which ones, and it's worth reading before you switch it off for a whole organization.

Tools and safety: settings, not variables

The old version said the PowerShell variable makes Claude Code use PowerShell instead of Bash. The real behavior is more specific:

EnvironmentHow CLAUDE_CODE_USE_POWERSHELL_TOOL behaves
Windows without Git BashEnabled automatically; 0 disables
Windows with Git BashOn by default for claude.ai and Console accounts; 1 enables it on Bedrock, Agent Platform and Foundry
Linux, macOS, WSL1 enables it; requires pwsh on PATH

CLAUDE_CODE_SHELL sets the shell the Bash tool uses and accepts a bash or zsh path. Shells like fish aren't supported, and an invalid path is quietly ignored in favor of auto-detection. To turn off only WebFetch, use CLAUDE_CODE_DISABLE_WEB_FETCH=1 (v2.1.285+); WebSearch stays available.

Approval behavior and sandboxing, on the other hand, live in settings:

{
  "permissions": {
    "defaultMode": "acceptEdits",
    "deny": ["Read(./.env)", "Read(./secrets/**)"]
  },
  "sandbox": {
    "enabled": true
  }
}

Permission modes are default, acceptEdits, plan, auto, dontAsk, and bypassPermissions. sandbox.enabled turns on Bash sandboxing on macOS, Linux, and WSL2. If an allow rule seems to be ignored, When an allow rule seems to be ignored walks through the layers to check.

Troubleshooting table

SymptomLikely causeHow to checkFix
Changing an exported value changes nothingThe same variable is in a settings env blockgrep -n '"env"' -A10 ~/.claude/settings.json .claude/settings*.jsonKeep it in one place. If the shell should win, remove it from env and relaunch
Nothing happens at allThe name isn't in the official list (typo or invented name)Search the official Environment variables pageUse the real name, or the settings key
Only values in project env are ignoredA variable project settings can't setLook for the warning in claude --debugMove it to the shell, user settings, or managed settings
Console is billed even after /loginANTHROPIC_API_KEY ranks higher in auth orderLogin method in /status; env | grep ANTHROPICUnset it, or turn off Use custom API key in /config
Setting telemetry to 0 doesn't turn it back onDISABLE_TELEMETRY treats any non-empty value as opt-outenv | grep DISABLE_Unset the variable
Same settings, different model than a teammateAliases resolve differently per providerCompare the model in each person's /statusPin a full model ID or ANTHROPIC_DEFAULT_*_MODEL
Value missing when launched from VS Code or the desktop appThat launch path doesn't read your shell profileCompare echo in the integrated terminal and the appPut it in ~/.claude/settings.json env, which doesn't depend on the launch path

One footnote on that last row: when the Claude Desktop app or a self-hosted runner starts the session, the launch environment it builds takes precedence, and a settings env value is ignored for any variable that environment already sets. If a value won't take through the app, check the app's own environment settings too.

Templates by use case

Solo development (~/.claude/settings.json)

{
  "env": {
    "API_TIMEOUT_MS": "900000",
    "BASH_DEFAULT_TIMEOUT_MS": "300000",
    "DISABLE_ERROR_REPORTING": "1"
  },
  "apiKeyHelper": "security find-generic-password -a $USER -s anthropic-api-key -w",
  "permissions": { "defaultMode": "acceptEdits" }
}

I leave the model out of this file and pick it per task with /model. When the model lives in env, I tend to forget it's there every time I use /model.

Shared team settings (.claude/settings.json)

{
  "env": {
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
    "MCP_TIMEOUT": "60000",
    "MCP_TOOL_TIMEOUT": "180000"
  },
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)"]
  }
}

Endpoints and credentials don't belong here. Anyone who checks out the repo reads this file, so gateway URLs and telemetry policy go in managed settings, and credentials stay in each person's own environment.

CI (GitHub Actions)

env:
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  ANTHROPIC_MODEL: claude-haiku-4-5-20251001
  BASH_DEFAULT_TIMEOUT_MS: "180000"
  CLAUDE_CODE_MAX_RETRIES: "3"
  CLAUDE_CODE_SKIP_PROMPT_HISTORY: "1"
  DISABLE_TELEMETRY: "1"

claude -p starts in default mode, so tools that need approval won't run. Grant what the job needs explicitly with --allowedTools or allow rules. If CI runs on a subscription rather than an API key, store a CLAUDE_CODE_OAUTH_TOKEN from claude setup-token in secrets instead of ANTHROPIC_API_KEY.

The next thing that usually breaks

Once the variables are sorted out, the next snag is usually a misspelled settings key. Like variable names, unknown keys are silently ignored. A one-letter typo in a settings.json key is silently ignored by Claude Code shows how to catch them with /doctor. If billing is the worry, When Console was billing me despite a Pro plan may also help.

If you do one thing after reading this, open your ~/.claude/settings.json and take stock of what's sitting in env. For me, the answer to "why isn't this setting working" has almost always been there.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⟐ Claude Code2026-11-06
Claude Code Shipped 21 Releases in Four Weeks. I Counted Before Deciding How Often to Update
Should you check Claude Code updates every day or once a week? I counted npm's publish history with a standard-library Python script and used the last 28 days of counts and gaps to set a rhythm.
⟐ Claude Code2026-10-24
The Settings File I Kept Saying Yes To Had a Rule That Let Any Python Through — Auditing Allow Rules After the 2.1.309 Changelog
Claude Code 2.1.309 is full of permission-check and sandbox fixes. Here is a script that audits the allow rules in settings.local.json, and how to fix a prefix wildcard on an interpreter.
⟐ Claude Code2026-10-22
When Only claude -p Refuses to Log In: Check the Credential Order Before You Re-Login
Interactive Claude Code works but claude -p or a script is refused? Here is where to look before running /login again, following the credential order in the official docs.