Claude Code environment variables: the list, and which wins
The environment variables Claude Code reads, by group: API key, OAuth token, base URL, models, Bedrock, timeouts, telemetry, proxy, and shell vs settings.json.
Claude Code reads dozens of environment variables; the ones most people need are ANTHROPIC_API_KEY and CLAUDE_CODE_OAUTH_TOKEN (sign-in), ANTHROPIC_BASE_URL with ANTHROPIC_AUTH_TOKEN (a gateway), ANTHROPIC_MODEL and the ANTHROPIC_DEFAULT_*_MODEL family (models), CLAUDE_CODE_USE_BEDROCK or CLAUDE_CODE_USE_VERTEX (cloud providers), and API_TIMEOUT_MS, BASH_DEFAULT_TIMEOUT_MS, CLAUDE_CODE_MAX_OUTPUT_TOKENS, DISABLE_TELEMETRY and DISABLE_AUTOUPDATER (behaviour). Export them in the shell before you run claude, or put them in the env object of ~/.claude/settings.json so every session gets them; when both set the same variable, the settings file wins in most sessions. One catch matters more than the rest: an exported ANTHROPIC_API_KEY is used instead of your Claude Pro or Max login once approved, and always in claude -p, so that usage is billed to the API. As of Claude Code 2.1.332, November 28, 2026.
Setting a variable: the shell or settings.json
In the shell, set it before you start Claude Code. It lasts for that terminal session:
# macOS, Linux, WSL
export API_TIMEOUT_MS="1200000"
claude
# Windows PowerShell
$env:API_TIMEOUT_MS = "1200000"
claude
# Windows CMD
set API_TIMEOUT_MS=1200000
claudeCopiedTo keep it, Anthropic’s environment variables reference adds the export line to ~/.bashrc or ~/.zshrc, and on Windows runs setx API_TIMEOUT_MS "1200000" (CMD) or [Environment]::SetEnvironmentVariable with "User" (PowerShell), then opens a new terminal. Claude Code reads the shell once, at startup, so a running session does not see a later export.
In a settings file, the env object takes string values and applies to every session and to the commands Claude Code starts:
{
"env": {
"API_TIMEOUT_MS": "1200000",
"BASH_DEFAULT_TIMEOUT_MS": "300000",
"DISABLE_AUTOUPDATER": "1"
}
}CopiedWhich file you put it in sets who it reaches: your user file, the project’s shared file, its local file or managed settings, as laid out in the Claude Code settings.json guide. The rules that catch people out, all from the settings reference’s env entry:
- The file beats the shell. “A value here overwrites the same variable exported in your shell,” and between files the higher-precedence one applies. The exception is a session that Claude Desktop or a self-hosted runner starts: there the environment it builds wins, and Claude Code ignores a file value for a variable that environment already sets.
- A file can set but not remove. To cancel something a shell profile exports, set it to an empty string, such as
"CLAUDE_CODE_USE_VERTEX": "". Claude Code treats the empty value as unset for choosing a provider; the commands it runs still inherit the empty value. - No shell expansion.
~and$HOMEstay as typed, so a path such asCLAUDE_CONFIG_DIRmust be written in full:"/home/you/.claude-work". - Saved changes apply live. Unlike the shell, a saved change to the merged
envreaches a running session, except for features read only at startup such as OpenTelemetry. Deleting a variable from the file takes effect only at the next launch. - Project files wait, and some variables are refused.
envvalues from a project’s.claude/settings.jsonorsettings.local.jsonapply after you trust the workspace, or at once under-p; ones Claude Code classes as safe, such as model choice, timeouts and feature toggles, apply at startup from any file. Project and local files can never setCLAUDE_CONFIG_DIR,CLAUDE_CODE_TMPDIR,HOME,CLAUDE_CODE_OAUTH_TOKENor the variables that turn telemetry export on; each is dropped with a warning thatclaude --debugshows. - Values are plain text. Anything in
envsits readable in the file and reaches every subprocess. Keep keys out of a committed project file; for an API key the reference points atapiKeyHelperinstead.
On a server this decides a lot. A cron job or a systemd unit does not read ~/.bashrc, and Claude Code’s background agents run under a supervisor that, in the network configuration docs’ words, “inherits the environment of whichever shell starts it first.” Variables in ~/.claude/settings.json reach all of them. Secrets are the exception: put a key in the job’s own environment or a helper, not in a settings file.
On and off variables take 1, true, yes or on, and 0, false, no or off, in any case. Five are different and switch on with any non-empty value, 0 included: CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, DISABLE_TELEMETRY, DISABLE_ERROR_REPORTING, CLAUDE_CODE_TMUX_TRUECOLOR and IS_DEMO. Setting DISABLE_TELEMETRY=0 still turns telemetry off; unset it instead. Numbers accept 2e3 and 64_000 spellings.
Sign-in and gateway variables
| Variable | What it does |
|---|---|
ANTHROPIC_API_KEY | A Claude Console API key, sent as the X-Api-Key header. Used instead of a Pro, Max, Ultra, Team or Enterprise login once you approve it |
ANTHROPIC_AUTH_TOKEN | A value for the Authorization header, sent with Bearer in front; for a gateway or proxy that takes bearer tokens |
ANTHROPIC_BASE_URL | Sends requests to a proxy or gateway instead of Anthropic’s API. Since 2.1.196, Remote Control is off when it points anywhere but api.anthropic.com |
ANTHROPIC_CUSTOM_HEADERS | Extra request headers, Name: Value, one per line |
CLAUDE_CODE_OAUTH_TOKEN | A subscription token from claude setup-token, for scripts and CI. Ignored in project and local settings |
ANTHROPIC_PROFILE | The Anthropic profile to sign in with, such as one from ant auth login |
CLAUDE_CODE_API_KEY_HELPER_TTL_MS | How often, in milliseconds, credentials from an apiKeyHelper command are refreshed |
When more than one credential is present, the authentication docs pick in this order:
1. Cloud provider, when CLAUDE_CODE_USE_BEDROCK / _VERTEX / _FOUNDRY is set
2. ANTHROPIC_AUTH_TOKEN
3. ANTHROPIC_API_KEY
4. apiKeyHelper (a setting, not a variable)
5. CLAUDE_CODE_OAUTH_TOKEN
6. Anthropic profiles and federation credentials
7. Your /login subscription sign-inCopiedSo a key left in a shell profile outranks the Claude plan you are logged in with. In an interactive session Claude Code asks once whether to use it and remembers the answer (the “Use custom API key” toggle in /config changes it later); claude -p uses it without asking. Either way the usage is billed per token to the Console account behind the key, and if that account has no credit you get a credit-balance error while your plan sits unused. To go back to the plan:
unset ANTHROPIC_API_KEY # this shell only; also remove it from ~/.bashrc or ~/.zshrc
env -u ANTHROPIC_API_KEY claude # one run without itCopiedThen check /status, which marks the credential not in use when a login and a key are both configured. Because a settings env block writes its values into Claude Code’s environment over the shell’s, look there too if unset changes nothing. Getting and capping a key is in the Claude Code API key guide, and running scripts on the plan instead is claude setup-token. Note that --bare mode does not read CLAUDE_CODE_OAUTH_TOKEN; it needs a key or a helper.
If you set a key or token in the shell, keep it out of your shell history by reading it at a silent prompt (bash or zsh) rather than typing it after export; only the read command is recorded, and the key lasts until that terminal closes:
read -rs ANTHROPIC_API_KEY && export ANTHROPIC_API_KEY # paste, then Enter
claudeCopiedA gateway takes ANTHROPIC_BASE_URL plus ANTHROPIC_AUTH_TOKEN; worked set-ups for OpenRouter and for a local router are in OpenRouter in Claude Code and Claude Code Router.
Model variables
| Variable | What it does |
|---|---|
ANTHROPIC_MODEL | The model to use: an alias such as sonnet or a full ID such as claude-sonnet-5-5 |
ANTHROPIC_DEFAULT_MODEL | The model new sessions start on (2.1.236 or later) |
ANTHROPIC_DEFAULT_OPUS_MODEL | The model ID the opus alias means, and what opusplan uses in Plan Mode |
ANTHROPIC_DEFAULT_SONNET_MODEL | The model ID behind sonnet, and opusplan outside Plan Mode |
ANTHROPIC_DEFAULT_HAIKU_MODEL | The model ID behind haiku, also used for background work. Replaces the deprecated ANTHROPIC_SMALL_FAST_MODEL |
ANTHROPIC_DEFAULT_FABLE_MODEL | The model ID behind fable |
CLAUDE_CODE_SUBAGENT_MODEL | The default model for subagents that are not given one another way |
ANTHROPIC_CUSTOM_MODEL_OPTION | Adds one extra entry to the /model picker, such as a gateway’s model name |
The order on the model configuration page: /model in the session, then --model, then ANTHROPIC_MODEL, then the model key in a settings file, then ANTHROPIC_DEFAULT_MODEL. The ANTHROPIC_DEFAULT_*_MODEL variables take full IDs, or your provider’s form of them, such as us.anthropic.claude-opus-4-8 on Bedrock. On Google Cloud and Microsoft Foundry they matter now: Sonnet 4.5 retires there on November 30, 2026, and before Claude Code 2.1.332 the sonnet alias still resolves to it, so update, or set ANTHROPIC_DEFAULT_SONNET_MODEL (and ANTHROPIC_DEFAULT_OPUS_MODEL) to a newer model. The aliases and IDs themselves are in Claude Code models.
Cloud provider variables
Each of these switches Claude Code from Anthropic’s API to a cloud provider, which then bills you; the Bedrock, Google Cloud and Foundry switches outrank every other credential:
| Variable | Provider |
|---|---|
CLAUDE_CODE_USE_BEDROCK=1 | Amazon Bedrock; credentials from the AWS chain or AWS_BEARER_TOKEN_BEDROCK; endpoint override ANTHROPIC_BEDROCK_BASE_URL |
CLAUDE_CODE_USE_VERTEX=1 | Google Cloud’s Agent Platform (Vertex AI); project in ANTHROPIC_VERTEX_PROJECT_ID |
CLAUDE_CODE_USE_FOUNDRY=1 | Microsoft Foundry |
CLAUDE_CODE_USE_ANTHROPIC_AWS=1 | Claude Platform on AWS |
CLAUDE_CODE_SKIP_BEDROCK_AUTH and CLAUDE_CODE_SKIP_VERTEX_AUTH skip the provider’s own authentication, for when a gateway in front handles it. The full Bedrock set-up, with the region and Vertex variables, is in Claude Code on Amazon Bedrock.
Timeouts and retries
| Variable | Default | What it limits |
|---|---|---|
API_TIMEOUT_MS | 600000 (10 min) | How long each API attempt waits for response headers, not how long a reply streams. 0 removes it (2.1.305 or later) |
BASH_DEFAULT_TIMEOUT_MS | 120000 (2 min) | A shell command Claude runs in the foreground |
BASH_MAX_TIMEOUT_MS | 600000 (10 min) | The most Claude may ask for on one command; the ceiling is the larger of this and the default |
CLAUDE_CODE_MAX_RETRIES | 10 | Retries of a failed API request, capped at 15 |
CLAUDE_CODE_RETRY_WATCHDOG | off | 1 keeps retrying 429 and 529 capacity errors past the retry limit, for unattended sessions |
MCP_TIMEOUT | 30000 (30 s) | An MCP server’s startup |
MCP_TOOL_TIMEOUT | 100000000 (about 28 h) | An MCP tool call; HTTP, SSE and claude.ai connector servers also stop each request after 60 seconds unless this (or the server’s own timeout) is set above 60000 |
A long build or test suite killed at two minutes is BASH_DEFAULT_TIMEOUT_MS; raise it with BASH_MAX_TIMEOUT_MS if you also want Claude able to ask for longer. API_TIMEOUT_MS is the one to raise behind a slow proxy.
Output, thinking, effort and context
CLAUDE_CODE_MAX_OUTPUT_TOKENScaps output tokens for most requests. Defaults and caps depend on the model, and a value over the model’s cap is lowered to it; for a model ID Claude Code does not recognise, the default is 32000 and the cap 128000.MAX_THINKING_TOKENSis a fixed thinking budget. Models with adaptive reasoning (Fable, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later) ignore a positive value.0turns thinking off on Anthropic’s API, except on Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable, which always think.CLAUDE_CODE_EFFORT_LEVELislow,medium,high,xhighormax, and beats--effort,/effortand the settings keys;autosends no level and lets the API choose.CLAUDE_CODE_AUTO_COMPACT_WINDOWsets how full the context gets before it is compacted, as a token count of 100000 or more (200kworks from 2.1.304).CLAUDE_AUTOCOMPACT_PCT_OVERRIDEcompacts earlier by percentage but cannot raise the threshold.DISABLE_AUTO_COMPACT=1stops automatic and idle compaction and leaves/compact;DISABLE_COMPACT=1stops all of it,/compactincluded.CLAUDE_CODE_DISABLE_1M_CONTEXT=1holds models to a 200K window.ENABLE_PROMPT_CACHING_1H=1asks for a one-hour prompt cache instead of five minutes, meant for API-key and cloud-provider users (plans within their included usage get it on the main conversation already); one-hour cache writes cost more.DISABLE_PROMPT_CACHING=1turns caching off.
Telemetry, updates and background traffic
| Variable | What it turns off |
|---|---|
DISABLE_TELEMETRY | Telemetry, and with it feature-flag fetching. Anthropic says the events “don’t include user data like code, file paths, or Bash commands” |
DO_NOT_TRACK=1 | The same as DISABLE_TELEMETRY, but read as a normal on/off value, so 0 leaves telemetry on |
DISABLE_ERROR_REPORTING | Error reports |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC | Auto-updates, telemetry, error reporting, /feedback, release notes, the PR status badge checks and availability checks such as fast mode’s |
CLAUDE_CODE_DISABLE_FEATURE_FLAGS=1 | Feature-flag fetching alone, leaving telemetry on (2.1.319 or later) |
DISABLE_AUTOUPDATER=1 | Background updates; claude update still works |
DISABLE_UPDATES=1 | Every update, claude update and claude install included |
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 | Auto memory: Claude neither writes nor loads its memory files |
DISABLE_TELEMETRY, DO_NOT_TRACK, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC and CLAUDE_CODE_DISABLE_FEATURE_FLAGS all stop feature-flag fetching, and with it features such as claude import and syncing the skills enabled for your claude.ai account. The last two also make Remote Control unavailable; for the first two, Remote Control’s requirements decide. If you drive a server’s sessions from your phone, read the list of what stops before setting any of them. CLAUDE_CODE_ENABLE_TELEMETRY=1 is the opposite switch: it turns on OpenTelemetry export to your own collector, and only works from your shell, user or managed settings.
Proxies and certificates
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY="localhost,192.168.1.1,example.com,.example.com"
export NODE_EXTRA_CA_CERTS=/path/to/ca-cert.pemCopiedPer the network configuration docs, lowercase forms work too, checked in the order https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY; NO_PROXY takes a comma- or space-separated list, or *; and “Claude Code does not support SOCKS proxies.” A proxy that needs a password takes it in the URL, which then sits in your environment. Write the proxy as a full URL with http://. Claude Code trusts the operating system’s certificates as well as its own bundle (npm installs need Node 22.15 or later for the system store), so a corporate TLS proxy whose root is installed system-wide needs nothing more; NODE_EXTRA_CA_CERTS adds one that isn’t, and CLAUDE_CODE_CLIENT_CERT, CLAUDE_CODE_CLIENT_KEY and CLAUDE_CODE_CLIENT_KEY_PASSPHRASE handle mutual TLS. /status shows the proxy in use.
Where it keeps files, and what it runs
CLAUDE_CONFIG_DIRmoves~/.claude, with its settings, history, plugins and stored login. Anthropic’s example for two accounts on one machine isalias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'.CLAUDE_CODE_TMPDIRmoves Claude Code’s own temporary files.CLAUDE_CODE_SHELLpicks the shell for Claude’s commands: a path tobashorzshonly, since fish and others are not supported.CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIRreturns to the starting folder after each command.CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1strips credentials,ANTHROPIC_API_KEYamong them, from the environment of the commands, hooks and local MCP servers Claude Code starts, while it keeps them for its own requests. It leaves GitHub tokens and proxy settings in place.
To see what a session actually received, run env | grep -E 'ANTHROPIC|CLAUDE' in the shell you start it from (PowerShell: Get-ChildItem Env:ANTHROPIC*), then /status inside Claude Code for the credential, model and proxy it chose. The env line prints any key in full, so don’t paste its output anywhere public. The complete list, well past what any one setup needs, is Anthropic’s environment variables reference, which changes most weeks with the CHANGELOG.