Claude Code environment variables and where to set them
AutoRouter6 min read
Key facts
- Anthropic's environment variable reference lists 406 variables as of November 13, 2026 (Anthropic).
- A variable in the
envkey of a settings.json file applies howeverclaudewas launched, and it overrides the same variable from your shell in most sessions. DISABLE_TELEMETRY,DISABLE_ERROR_REPORTINGandCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICturn on with any non-empty value, so setting them to0still opts out.ANTHROPIC_API_KEYreplaces your Claude subscription even when you are logged in, after you approve it once in an interactive session.
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:
| File | Applies to |
|---|---|
~/.claude/settings.json | You, in every project |
.claude/settings.json | Everyone in the project, checked into source control |
.claude/settings.local.json | You, in this project only |
| Managed settings | Everyone 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:
- Flags and commands vary by feature.
--modeland/modeloverrideANTHROPIC_MODEL, butCLAUDE_CODE_EFFORT_LEVELoverrides--effortand/effort. - Variable before setting, for some keys.
ANTHROPIC_MODELwins over themodelsetting, which applies only when the variable is unset. - Project files can't set everything. Project and local settings can't set
CLAUDE_CONFIG_DIR,CLAUDE_CODE_OAUTH_TOKENor the OpenTelemetry exporter variables. - Shell values load once. Claude Code reads shell variables at startup, so restart
claudeafter anexport. Values in a settings file reapply to a running session when you save it, except features that read them only at startup. - You can't remove a variable from a settings file. To cancel one your shell exports, set it to an empty string, such as
"CLAUDE_CODE_USE_VERTEX": "".
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).
| Variable | What it does |
|---|---|
ANTHROPIC_API_KEY | API key sent as the X-Api-Key header; replaces your subscription once approved. unset ANTHROPIC_API_KEY to go back |
ANTHROPIC_AUTH_TOKEN | Custom Authorization header value, sent as Bearer <value> |
CLAUDE_CODE_OAUTH_TOKEN | A claude.ai login token for scripts and the SDK, made with claude setup-token |
ANTHROPIC_BASE_URL | Sends requests to a proxy or gateway instead of api.anthropic.com; Remote Control turns off when it points elsewhere |
ANTHROPIC_CUSTOM_HEADERS | Extra request headers, Name: Value, one per line |
CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, CLAUDE_CODE_USE_FOUNDRY | Use Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry |
HTTPS_PROXY, HTTP_PROXY, NO_PROXY | Corporate 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:
| Variable | What it does |
|---|---|
ANTHROPIC_MODEL | Model for sessions launched with it |
ANTHROPIC_DEFAULT_MODEL | Model new sessions start on when nothing else sets one |
ANTHROPIC_DEFAULT_OPUS_MODEL, _SONNET_MODEL, _HAIKU_MODEL | The model ID each alias resolves to; the Haiku one also runs background tasks |
CLAUDE_CODE_SUBAGENT_MODEL | Default model for subagents and teammates that have none set |
CLAUDE_CODE_EFFORT_LEVEL | low, medium, high, xhigh or max; overrides --effort and /effort |
MAX_THINKING_TOKENS | Fixed 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.
600000.| Variable | Default | What it limits |
|---|---|---|
API_TIMEOUT_MS | 600000 (10 minutes) | Time each API request has to receive its response headers |
BASH_DEFAULT_TIMEOUT_MS | 120000 (2 minutes) | Default timeout for a foreground shell command |
BASH_MAX_TIMEOUT_MS | 600000 (10 minutes) | Longest timeout Claude can set for a shell command |
MCP_TIMEOUT | 30000 (30 seconds) | MCP server startup |
MAX_MCP_OUTPUT_TOKENS | 25000 tokens | Size of an MCP tool response; a warning shows above 10,000 |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Varies by model | Output tokens per request; higher values leave less room before auto-compaction |
CLAUDE_CODE_AUTO_COMPACT_WINDOW | Varies by model | How full the context gets before compaction, 100,000 to 1,000,000 tokens |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | Not set | Percentage 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).
| Variable | What it does |
|---|---|
DISABLE_AUTOUPDATER | Stops background updates; claude update still works |
DISABLE_UPDATES | Blocks every update, manual ones included |
CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE | Lets Claude Code run the Homebrew or WinGet upgrade for you |
DISABLE_TELEMETRY | Opts out of telemetry and feature-flag fetching |
DISABLE_ERROR_REPORTING | Opts out of error reporting |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC | Turns off auto-updates, telemetry, error reporting, /feedback and other nonessential traffic |
DISABLE_PROMPT_CACHING | Turns off prompt caching for all models, which makes requests cost more |
CLAUDE_CONFIG_DIR | Moves settings, history and plugins from ~/.claude, for example to run two accounts |
CLAUDE_CODE_SHELL | Path 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
- Environment variables, Anthropic, checked November 13, 2026
- Settings, Anthropic, checked November 13, 2026
- Model configuration, Anthropic, checked November 13, 2026
- Advanced setup, Anthropic, checked November 13, 2026