Beta
Download

Claude Code environment variables and where to set them

AutoRouter6 min read

Key facts

As of November 13, 2026, Anthropic's environment variable reference lists 406 variables that Claude Code reads. You set one in your shell before launching claude, which lasts for that terminal session, or under the env key of a settings.json file, which applies every time Claude Code runs. This post covers the variables most people set, grouped by job, and the rules for which value wins. Model variables get a short table here; how to change the model in Claude Code covers them in full.

Where do you set Claude Code environment variables?

Set a variable in your shell for one session, or in a settings file for every session. In the shell, export it before you start Claude Code, and add the line to ~/.zshrc to keep it:

export API_TIMEOUT_MS="1200000"
claude

# check what's set
echo $API_TIMEOUT_MS

In a settings file, put it under env. Claude Code reads these values from the file directly, so they apply no matter how claude was launched:

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

No shell processes the env block, so ~ and $HOME stay as typed; write absolute paths, such as "CLAUDE_CONFIG_DIR": "/Users/you/.claude-work". The file you choose decides who the variable applies to:

FileApplies to
~/.claude/settings.jsonYou, in every project
.claude/settings.jsonEveryone in the project, checked into source control
.claude/settings.local.jsonYou, in this project only
Managed settingsEveryone in your organization, set by an admin

Which value wins when a Claude Code variable is set twice?

When the same variable is in your shell and in a settings file, the settings file value applies in most sessions, because Claude Code writes each env entry over the inherited one (Anthropic). Between settings files, managed settings beat user and project settings. A few more rules decide the rest:

Which environment variables control sign-in and the API endpoint?

These variables decide which account pays and where requests go. ANTHROPIC_API_KEY is the one that surprises people: when set, it is used instead of your Pro, Max, Ultra, Team or Enterprise subscription even if you are logged in, after you approve it once in an interactive session, and always in -p mode (Anthropic).

VariableWhat it does
ANTHROPIC_API_KEYAPI key sent as the X-Api-Key header; replaces your subscription once approved. unset ANTHROPIC_API_KEY to go back
ANTHROPIC_AUTH_TOKENCustom Authorization header value, sent as Bearer <value>
CLAUDE_CODE_OAUTH_TOKENA claude.ai login token for scripts and the SDK, made with claude setup-token
ANTHROPIC_BASE_URLSends requests to a proxy or gateway instead of api.anthropic.com; Remote Control turns off when it points elsewhere
ANTHROPIC_CUSTOM_HEADERSExtra request headers, Name: Value, one per line
CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, CLAUDE_CODE_USE_FOUNDRYUse Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry
HTTPS_PROXY, HTTP_PROXY, NO_PROXYCorporate proxy, and the hosts that bypass it

Gateways and model routers usually attach to Claude Code through these settings. AutoRouter, the Mac app for Codex and Claude Code, adds itself to Claude Code's settings.json when you enable it, after saving a copy of the file; your other settings stay as they are, and disabling Claude Code in AutoRouter's settings switches it back. See AutoRouter for setup.

Which environment variables choose Claude Code's model and effort?

Claude Code takes its model from ANTHROPIC_MODEL when no --model flag or /model choice overrides it, and from these related variables:

VariableWhat it does
ANTHROPIC_MODELModel for sessions launched with it
ANTHROPIC_DEFAULT_MODELModel new sessions start on when nothing else sets one
ANTHROPIC_DEFAULT_OPUS_MODEL, _SONNET_MODEL, _HAIKU_MODELThe model ID each alias resolves to; the Haiku one also runs background tasks
CLAUDE_CODE_SUBAGENT_MODELDefault model for subagents and teammates that have none set
CLAUDE_CODE_EFFORT_LEVELlow, medium, high, xhigh or max; overrides --effort and /effort
MAX_THINKING_TOKENSFixed extended-thinking budget; 0 turns thinking off

Which environment variables set Claude Code's timeouts and limits?

Raise these when long commands, slow networks or large tool results get cut off. All times are in milliseconds.

Defaults from Anthropic's reference. Each variable takes milliseconds: 600 seconds is 600000.
VariableDefaultWhat it limits
API_TIMEOUT_MS600000 (10 minutes)Time each API request has to receive its response headers
BASH_DEFAULT_TIMEOUT_MS120000 (2 minutes)Default timeout for a foreground shell command
BASH_MAX_TIMEOUT_MS600000 (10 minutes)Longest timeout Claude can set for a shell command
MCP_TIMEOUT30000 (30 seconds)MCP server startup
MAX_MCP_OUTPUT_TOKENS25000 tokensSize of an MCP tool response; a warning shows above 10,000
CLAUDE_CODE_MAX_OUTPUT_TOKENSVaries by modelOutput tokens per request; higher values leave less room before auto-compaction
CLAUDE_CODE_AUTO_COMPACT_WINDOWVaries by modelHow full the context gets before compaction, 100,000 to 1,000,000 tokens
CLAUDE_AUTOCOMPACT_PCT_OVERRIDENot setPercentage of that window at which compaction starts; can only lower it

Which environment variables control updates, telemetry and privacy?

Most on/off variables accept 1, true, yes or on, but three read only whether they are set at all: DISABLE_TELEMETRY, DISABLE_ERROR_REPORTING and CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC. For those, 0 and false still turn the behavior on; unset the variable to turn it off (Anthropic).

VariableWhat it does
DISABLE_AUTOUPDATERStops background updates; claude update still works
DISABLE_UPDATESBlocks every update, manual ones included
CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATELets Claude Code run the Homebrew or WinGet upgrade for you
DISABLE_TELEMETRYOpts out of telemetry and feature-flag fetching
DISABLE_ERROR_REPORTINGOpts out of error reporting
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICTurns off auto-updates, telemetry, error reporting, /feedback and other nonessential traffic
DISABLE_PROMPT_CACHINGTurns off prompt caching for all models, which makes requests cost more
CLAUDE_CONFIG_DIRMoves settings, history and plugins from ~/.claude, for example to run two accounts
CLAUDE_CODE_SHELLPath to the bash or zsh that runs shell commands

Questions

Why isn't my Claude Code environment variable taking effect?

The usual causes are a session started before you ran export, a settings file that sets the same variable and wins, or a project settings file trying to set a variable only user or managed settings may set. Run echo $NAME in the same terminal, restart claude, and run claude doctor to see settings errors.

How do I unset a variable that my shell profile exports?

Run unset NAME in your shell, or, if you can't change the profile, set the variable to an empty string in your settings file's env block. Claude Code treats the empty value as unset for provider selection, though subprocesses still inherit it.

Can I run two Claude accounts side by side?

Yes. Give each its own config folder with CLAUDE_CONFIG_DIR, for example alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'. Anthropic's docs suggest this alias; in a settings file, write the absolute path instead of ~.

Which variables does an MCP server use?

Claude Code itself reads MCP_TIMEOUT, MAX_MCP_OUTPUT_TOKENS and ENABLE_TOOL_SEARCH. A server's own keys go in its --env flags or its .mcp.json entry, which can expand ${VAR} from your environment; how to add an MCP server to Claude Code shows both.

Where do I set variables if I haven't installed Claude Code yet?

Install first; the variables do nothing until claude runs. How to install Claude Code on a Mac walks through it, including the CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE setting for Homebrew installs.

Sources