Claude Code environment variables: the useful ones
The Claude Code environment variables people actually set, grouped by model, sign-in, network, privacy, updates and behaviour, and where to put them.
Contents
Claude Code environment variables decide which credential it signs in with (ANTHROPIC_API_KEY), which model it runs (ANTHROPIC_MODEL), where requests go (ANTHROPIC_BASE_URL, HTTPS_PROXY) and what it reports (DISABLE_TELEMETRY). Export one in your shell for that terminal, or put it in the env block of ~/.claude/settings.json for every run.
Anthropic's reference lists well over a hundred. The tables below hold the ones people actually set, grouped by what they change, as the reference read on 22 October 2026. Variables are added, renamed and retired between releases, so if one here does nothing, run claude --version and look it up in the reference again.
Where to set them#
You can use the shell and a settings file together. A shell export lasts for the terminal it was typed in:
| Shell | Raise the API timeout to 20 minutes |
|---|---|
| macOS, Linux, WSL | export API_TIMEOUT_MS=1200000 |
| PowerShell | $env:API_TIMEOUT_MS = "1200000" |
| CMD | set API_TIMEOUT_MS=1200000 |
The env block of a settings file reaches every claude run that reads the file:
{
"env": {
"API_TIMEOUT_MS": "1200000",
"BASH_DEFAULT_TIMEOUT_MS": "300000"
}
}
Each settings file reaches different people.
| File | Applies to |
|---|---|
~/.claude/settings.json |
You, in every project |
.claude/settings.json |
Everyone in the project (it's committed, so never put a key here) |
.claude/settings.local.json |
You, in this project only |
| Managed settings | Everyone in an organisation |
Which value wins#
- A variable set in both your shell and a settings
envblock: the settings value usually applies, because Claude Code overwrites the inherited one. - Between files, managed settings beat user and project settings.
- A settings file can set a variable but not remove one. To cancel one your shell exports, set it to an empty string:
"CLAUDE_CODE_USE_VERTEX": "". - Project and local settings can't set a few variables,
CLAUDE_CONFIG_DIRamong them.
Values in JSON are always strings: write "1", not 1.
Model and reasoning#
| Variable | What it does |
|---|---|
ANTHROPIC_MODEL |
The model to use, as a full ID or an alias |
ANTHROPIC_DEFAULT_OPUS_MODEL |
The model the opus alias points to |
ANTHROPIC_DEFAULT_SONNET_MODEL |
The model the sonnet alias points to |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
The model the haiku alias points to, also used for background work such as session titles |
CLAUDE_CODE_SUBAGENT_MODEL |
The default model for subagents, agent-team teammates and workflow agents that aren't given one |
CLAUDE_CODE_EFFORT_LEVEL |
Effort on models that support it: low, medium, high, xhigh, max or auto |
MAX_THINKING_TOKENS |
A fixed thinking budget, on models that use one (adaptive models ignore it; use effort) |
CLAUDE_CODE_MAX_OUTPUT_TOKENS |
Maximum output tokens for most requests |
CLAUDE_CODE_DISABLE_1M_CONTEXT |
1 turns off the 1M-token context window |
The three ANTHROPIC_DEFAULT_*_MODEL variables matter most on Bedrock and Vertex, where Anthropic says to pin every model before a team rollout. Our Bedrock and Vertex guide has the IDs.
CLAUDE_CODE_MAX_OUTPUT_TOKENS is the one to reach for when a reply stops with an output token error. Our guide to Claude's response exceeding the output token maximum says how high it can go on each model.
Sign-in and accounts#
| Variable | What it does |
|---|---|
ANTHROPIC_API_KEY |
An API key, sent as X-Api-Key. When set, it's used instead of your subscription, even if you're logged in (interactive sessions ask once before using it) |
ANTHROPIC_AUTH_TOKEN |
A value for the Authorization: Bearer header, usually a gateway token |
CLAUDE_CODE_OAUTH_TOKEN |
A claude.ai sign-in token, in place of /login, for scripts and automated runs |
CLAUDE_CONFIG_DIR |
Moves the config folder away from ~/.claude: settings, history and plugins all live under it |
One forgotten export ANTHROPIC_API_KEY=... line in ~/.zshrc is enough for Claude Code to use the key: your Pro or Max plan sits unused and every turn is billed per token. /status names the credential in use. The other reasons Claude Code asks for /login again, or bills a key when you expected the plan, are in Claude Code keeps asking to log in.
Anthropic's reference calls CLAUDE_CONFIG_DIR "useful for running multiple accounts side by side": CLAUDE_CONFIG_DIR=~/.claude-work claude keeps that account's settings and history in its own folder. The two-folder setup, with shell aliases, is in switch Claude accounts without logging out.
Provider, gateway and network#
| Variable | What it does |
|---|---|
ANTHROPIC_BASE_URL |
Sends requests to a proxy or gateway instead of Anthropic |
ANTHROPIC_CUSTOM_HEADERS |
Extra request headers, Name: Value, one per line (\n in JSON) |
CLAUDE_CODE_USE_BEDROCK |
Use Amazon Bedrock |
CLAUDE_CODE_USE_VERTEX |
Use Google Cloud's Agent Platform (Vertex AI) |
CLAUDE_CODE_USE_FOUNDRY |
Use Microsoft Foundry |
HTTPS_PROXY, HTTP_PROXY |
Your proxy server |
NO_PROXY |
Domains and IPs that skip the proxy |
NODE_EXTRA_CA_CERTS |
Path to your company's CA bundle, for TLS-inspecting proxies |
API_TIMEOUT_MS |
How long each API attempt waits for response headers (default 600,000 ms) |
Bedrock and Vertex bring their own set (AWS_REGION, CLOUD_ML_REGION, ANTHROPIC_VERTEX_PROJECT_ID and more), covered in the Bedrock and Vertex guide. For a gateway, Anthropic's gateway guide shows how to test ANTHROPIC_BASE_URL with one curl before starting Claude Code. If requests don't get through, our guide to Claude Code's Unable to connect to API error covers a leftover ANTHROPIC_BASE_URL, HTTPS_PROXY and NODE_EXTRA_CA_CERTS.
Privacy and telemetry#
| Variable | What it does |
|---|---|
DISABLE_TELEMETRY |
Opts out of telemetry. Any non-empty value opts out, even 0 or false; unset it to opt back in |
DISABLE_ERROR_REPORTING |
Opts out of error reporting, with the same any-value rule |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
Turns off nonessential traffic: auto-updates, telemetry, error reporting, /feedback, release notes and more |
CLAUDE_CODE_ENABLE_TELEMETRY |
1 turns on OpenTelemetry metrics and logs, for your own monitoring |
DISABLE_TELEMETRY=0 still turns telemetry off, because Claude Code only checks that the variable has a value, and DISABLE_ERROR_REPORTING=false works the same way. To opt back in, unset DISABLE_TELEMETRY. CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 also stops auto-updates, so with it set, updating is up to you.
Updates#
| Variable | What it does |
|---|---|
DISABLE_AUTOUPDATER |
1 stops background updates. claude update still works |
DISABLE_UPDATES |
1 blocks every update path, claude update and claude install included. For companies that ship Claude Code themselves |
CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE |
1 lets Claude Code run the Homebrew or WinGet upgrade for you in the background |
To confirm, run claude doctor: its Auto-updates line says disabled (set by env: DISABLE_AUTOUPDATER).
Behaviour and limits#
| Variable | What it does |
|---|---|
BASH_DEFAULT_TIMEOUT_MS |
Default timeout for a foreground shell command (120,000 ms) |
BASH_MAX_TIMEOUT_MS |
The longest timeout the model may set for one (600,000 ms) |
MCP_TIMEOUT |
How long an MCP server may take to start (30,000 ms) |
MCP_TOOL_TIMEOUT |
How long an MCP tool call may run. HTTP servers also time out each request after 60 s unless you raise this above 60,000 |
MAX_MCP_OUTPUT_TOKENS |
The most tokens an MCP tool's reply may carry (25,000); a warning shows above 10,000 |
ENABLE_TOOL_SEARCH |
How MCP tools load: deferred by default; auto or auto:N only past a share of the context; false loads them all up front |
DISABLE_PROMPT_CACHING |
1 turns prompt caching off for every model |
CLAUDE_CODE_AUTO_COMPACT_WINDOW |
The window auto-compact works against, 100,000 to 1,000,000 tokens |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
The percentage of that window at which auto-compact starts; it can only lower the default |
CLAUDE_CODE_SHELL |
The bash or zsh binary the Bash tool uses (fish isn't supported) |
CLAUDE_CODE_GIT_BASH_PATH |
Where Git Bash is, on Windows, when Claude Code can't find it |
CLAUDE_CODE_DISABLE_TERMINAL_TITLE |
1 stops Claude Code renaming your terminal tab |
DISABLE_COST_WARNINGS |
1 hides cost warning messages |
Check for DISABLE_PROMPT_CACHING=1 left over from debugging if your limits drain fast: with it on, every request re-reads the whole context at full price. A large MAX_MCP_OUTPUT_TOKENS lets one tool reply fill the window. How caching and context add up per turn is in why Claude Code uses so many tokens.
Check what's in effect#
/statusshows the model, the account or key in use, the base URL and, on a cloud provider, the region.claude doctorshows install health, settings-file errors and the update setting.- A status line can print the model and context on every reply, so a wrong variable shows up straight away.
Accounts without the variables#
CLAUDE_CONFIG_DIR and ANTHROPIC_API_KEY are also how people keep a work plan, a personal plan and a key for when both run out apart: one terminal per folder or key. When the work account hits its limit, the task stops in that terminal, and you start it again in the other one.
Shuriken does that juggling for you. You add each account or key once as a source, and hot swapping takes it from there: Shuriken moves your chats to another of your accounts or sources when one nears its limit, inside the running chat and on every device. "Switch at" is 99% by default. An API key for the same provider stays out of the way until you choose: "Switch to API keys" is off by default, and once on, each fallback run stops at a $25 spend cap unless you change it. Only add accounts you own and are entitled to use; providers' terms may not allow sharing a subscription sign-in.
If you'd rather stop exporting variables per account, download Shuriken.
Sources
- Environment variables (Claude Code docs) (accessed 22 October 2026)
- Advanced setup: updates (Claude Code docs) (accessed 22 October 2026)
- Connect Claude Code to an LLM gateway (Claude Code docs) (accessed 22 October 2026)
- Claude Code on Amazon Bedrock (Claude Code docs) (accessed 22 October 2026)
- Network configuration (Claude Code docs) (accessed 22 October 2026)
- Manage costs effectively (Claude Code docs) (accessed 22 October 2026)
Frequently asked questions
Where do I set Claude Code environment variables?
Either export them in your shell before running claude, or put them in the env block of a settings file such as ~/.claude/settings.json, which applies every time claude runs. Use .claude/settings.local.json for one project only.
Which wins, my shell or settings.json?
Usually settings.json: Anthropic's docs say Claude Code overwrites the inherited value with the one from a settings env block. Managed settings beat user and project settings.
How do I set the model with an environment variable?
Set ANTHROPIC_MODEL. To change what the opus, sonnet and haiku aliases point to, set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL.
How do I turn off Claude Code telemetry?
Set DISABLE_TELEMETRY=1. Any non-empty value opts out, even 0 or false; unset it to turn telemetry back on. CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 also turns off error reporting and auto-updates.
Can a settings file remove a variable from my shell?
No, only set one. To neutralise an inherited value, set it to an empty string in the env block, for example "CLAUDE_CODE_USE_VERTEX": "".