Claude Code environment variables are settings you pass through the environment instead of a config key: set them with export NAME=value before running claude, or under the env key in ~/.claude/settings.json so they apply to every session. The ones most people need cover authentication (ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN), the model (ANTHROPIC_MODEL), cloud providers (CLAUDE_CODE_USE_BEDROCK), timeouts (API_TIMEOUT_MS, BASH_DEFAULT_TIMEOUT_MS) and privacy (DISABLE_TELEMETRY).
The full table on Anthropic's environment variables page runs to several hundred rows. This guide, checked against that page on 26 October 2026, covers how to set variables, which value wins, and the variables worth knowing.
How do you set environment variables for Claude Code?
There are two ways, and they behave differently.
In your shell. Export the variable, then start claude. It lasts for that terminal session; add the line to ~/.zshrc or ~/.bashrc to keep it.
export API_TIMEOUT_MS="1200000"
claude
On Windows PowerShell use $env:API_TIMEOUT_MS = "1200000", and in CMD use set API_TIMEOUT_MS=1200000. Use setx or [Environment]::SetEnvironmentVariable to make it permanent, then open a new terminal.
In a settings file. Add the variable under env. Claude Code reads it straight from the file, so it applies however claude was launched.
{
"env": {
"API_TIMEOUT_MS": "1200000",
"BASH_DEFAULT_TIMEOUT_MS": "300000"
}
}
Which file you pick decides who it applies to:
| File | Applies to |
|---|---|
~/.claude/settings.json |
You, in every project |
.claude/settings.json |
Everyone in the project, committed to git |
.claude/settings.local.json |
You, in this project only |
| Managed settings | Everyone in your organization, deployed by an admin |
Two details from the docs trip people up. First, no shell processes these values, so ~ and $HOME stay as typed; write absolute paths. Second, saving the file updates a running session, but removing a variable only takes effect the next time you launch claude. Our settings guide explains the file hierarchy.
Which value wins when a variable is set twice?
- Shell vs settings file: in most sessions the settings file wins, because Claude Code writes each
enventry over the inherited shell value. - Between settings files: normal settings precedence, so managed settings beat user and project settings.
- Project files can't set everything.
CLAUDE_CONFIG_DIRand the OpenTelemetry exporter variables are ignored in project and local settings. - Variables vs flags: it depends on the feature.
--modeland/modeloverrideANTHROPIC_MODEL, butCLAUDE_CODE_EFFORT_LEVELoverrides--effortand/effort. - Can't unset a stale variable? Set it to an empty string in
env, such as"CLAUDE_CODE_USE_VERTEX": "". Claude Code treats that as unset for provider selection.
For on/off variables, 1, true, yes or on turn a behavior on, and 0, false, no or off turn it off. The exceptions are DISABLE_TELEMETRY, DISABLE_ERROR_REPORTING and CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: any non-empty value, even 0, switches them on. Unset them to switch back.
Which variables control authentication?
| Variable | What it does |
|---|---|
ANTHROPIC_API_KEY |
API key sent as X-Api-Key. Used instead of your Claude subscription even when you are logged in |
ANTHROPIC_AUTH_TOKEN |
Custom Authorization header value, prefixed with Bearer . Common with gateways |
CLAUDE_CODE_OAUTH_TOKEN |
OAuth token for claude.ai login without a browser. Generate it with claude setup-token |
ANTHROPIC_BASE_URL |
Send requests to a proxy or gateway instead of the default endpoint |
ANTHROPIC_CUSTOM_HEADERS |
Extra request headers in Name: Value form, one per line |
CLAUDE_CODE_API_KEY_HELPER_TTL_MS |
How often to refresh credentials from an apiKeyHelper script |
When several credentials exist, the authentication docs give this order: cloud provider variables, then ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY, then apiKeyHelper, then CLAUDE_CODE_OAUTH_TOKEN, then Anthropic profile credentials, and finally your /login subscription. A forgotten ANTHROPIC_API_KEY in your shell profile is the classic reason a subscriber suddenly sees API charges.
Which variables choose the model and provider?
| Variable | What it does |
|---|---|
ANTHROPIC_MODEL |
The model setting to use |
ANTHROPIC_DEFAULT_OPUS_MODEL |
The model ID the opus alias resolves to |
ANTHROPIC_DEFAULT_SONNET_MODEL |
The model ID the sonnet alias resolves to |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
The model ID the haiku alias resolves to, also used for background work |
CLAUDE_CODE_SUBAGENT_MODEL |
Default model for subagents and agent team teammates without their own model |
CLAUDE_CODE_EFFORT_LEVEL |
Effort level: low, medium, high, xhigh, max or auto |
CLAUDE_CODE_USE_BEDROCK |
Use Amazon Bedrock |
CLAUDE_CODE_USE_VERTEX |
Use Google Cloud's Agent Platform |
CLAUDE_CODE_USE_FOUNDRY |
Use Microsoft Foundry |
ANTHROPIC_VERTEX_PROJECT_ID |
GCP project for Agent Platform requests |
AWS_BEARER_TOKEN_BEDROCK |
Amazon Bedrock API key |
CLAUDE_CODE_DISABLE_1M_CONTEXT |
Turn off 1M context window support |
Pinning the alias variables is how teams on Bedrock or Agent Platform map opus and sonnet to model IDs their account can use. See our Bedrock and Vertex guide, LLM gateway guide and models guide.
Which variables change timeouts, output and tokens?
| Variable | Default | What it does |
|---|---|---|
API_TIMEOUT_MS |
600000 (10 min) | Time each API attempt has to receive response headers |
BASH_DEFAULT_TIMEOUT_MS |
120000 (2 min) | Default timeout for a foreground Bash or PowerShell command |
BASH_MAX_TIMEOUT_MS |
600000 (10 min) | Longest timeout the model can request for a command |
BASH_MAX_OUTPUT_LENGTH |
30000 chars | How much command output Claude reads back (max 150000) |
MCP_TIMEOUT |
30000 (30 s) | MCP server startup timeout |
MCP_TOOL_TIMEOUT |
100000000 | MCP tool execution timeout |
MAX_MCP_OUTPUT_TOKENS |
25000 | Maximum tokens in an MCP tool response |
CLAUDE_CODE_MAX_OUTPUT_TOKENS |
Varies by model | Maximum output tokens for most requests |
MAX_THINKING_TOKENS |
Unset | Fixed extended thinking budget |
CLAUDE_CODE_MAX_RETRIES |
10 | Retries for failed API requests |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
Unset | Compact earlier, as a percentage (1 to 100) of the auto-compact window |
DISABLE_AUTO_COMPACT |
Unset | Turn off automatic compaction; /compact still works |
Long builds and test suites are the usual reason to raise BASH_DEFAULT_TIMEOUT_MS. Numeric variables accept forms such as 2e3 or 64_000. Raising CLAUDE_CODE_MAX_OUTPUT_TOKENS shrinks the room left before auto-compaction, which our context window guide explains.
Which variables control privacy, updates and networking?
| Variable | What it does |
|---|---|
DISABLE_TELEMETRY |
Opt out of telemetry. Also turns off feature-flag fetching |
DISABLE_ERROR_REPORTING |
Opt out of error reporting |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
Turn off auto-updates, telemetry, error reporting, /feedback, release notes and other nonessential traffic |
DISABLE_AUTOUPDATER |
Stop background updates; claude update still works |
DISABLE_UPDATES |
Block all updates, including claude update and claude install |
HTTPS_PROXY, HTTP_PROXY |
Proxy server for network connections |
NO_PROXY |
Hosts that bypass the proxy |
NODE_EXTRA_CA_CERTS |
Path to a custom CA certificate for enterprise networks |
CLAUDE_CODE_CLIENT_CERT |
Client certificate file for mTLS |
CLAUDE_CODE_SUBPROCESS_ENV_SCRUB |
Strip credentials from Bash commands, hooks and stdio MCP servers that Claude starts |
CLAUDE_CODE_ENABLE_TELEMETRY |
Turn on OpenTelemetry metrics and logs for your own monitoring |
Turning off feature-flag fetching has a cost. The docs list features that stop working, including Remote Control with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC set, claude import and the advisor tool. The network configuration page notes that Claude Code does not support SOCKS proxies. For OpenTelemetry setup, see our monitoring guide.
Which variables help with everyday setup and debugging?
| Variable | What it does |
|---|---|
CLAUDE_CONFIG_DIR |
Move the config directory from ~/.claude. Handy for separate work and personal accounts |
CLAUDE_CODE_SHELL |
Path to the bash or zsh binary for Bash tool commands |
CLAUDE_CODE_GIT_BASH_PATH |
Windows only: path to Git Bash's bash.exe |
CLAUDE_ENV_FILE |
Script run before each Bash command, for example to keep a virtualenv active |
CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR |
Return to the project directory after each command |
CLAUDE_CODE_SIMPLE |
Same as --bare: minimal prompt, Bash and file tools only |
CLAUDE_CODE_SAFE_MODE |
Same as --safe-mode: start with customizations off |
CLAUDE_CODE_SKIP_PROMPT_HISTORY |
Don't write prompt history or transcripts to disk |
DEBUG |
Turn on debug mode, like --debug |
CLAUDE_CODE_DEBUG_LOGS_DIR |
Debug log file path (a file, despite the name) |
DISABLE_PROMPT_CACHING |
Turn off prompt caching for all models |
CLAUDE_CODE_DISABLE_AUTO_MEMORY |
Turn off auto memory |
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS |
Turn on experimental agent teams |
A popular pattern from the docs runs two accounts side by side:
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'
Many of these have matching CLI flags; see our CLI reference. Inside containers, containerEnv in devcontainer.json is the usual place to set them, as our Docker guide shows.
Where should you keep these settings?
Put personal preferences in ~/.claude/settings.json, team defaults in the committed .claude/settings.json, and secrets in neither: keep API keys and tokens in your shell, a secrets manager or your CI's secret store. If you reuse the same instructions across projects, such as a setup checklist for new repos, Kipt can hold them as prompts in a private GitHub repo you own, next to your Agent Skills.