Claude Code environment variables: the useful ones

Claude Code reads hundreds of environment variables. The ones worth knowing, grouped by job: the model and effort, timeouts for long commands, a second account, privacy and updates, proxies, and MCP servers. Plus how to set them in settings.json so they apply however Claude Code starts, and which value wins. Checked against Claude Code 2.1.308.

Short answer: Put them under "env" in ~/.claude/settings.json, so they apply however you start claude. The ones most people need: CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 (no telemetry, error reports or auto-updates), BASH_DEFAULT_TIMEOUT_MS for long builds, CLAUDE_CONFIG_DIR for a second account, CLAUDE_CODE_EFFORT_LEVEL for a fixed effort, and HTTPS_PROXY behind a company proxy.

Claude Code's documentation lists about 400 environment variables, most of them for cloud providers and gateways. You will need perhaps a dozen. Here they are, grouped by what you are trying to do, with the defaults from the documentation.

How do you set an environment variable for Claude Code?

Three ways, from most to least lasting:

  1. In a settings file, under env. Claude Code reads it from the file, so it applies whether you start claude from a terminal, an IDE or a script, and a running session picks up most changes when you save:

``json { "env": { "BASH_DEFAULT_TIMEOUT_MS": "300000", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" } } ``

  1. In your shell profile: export BASH_DEFAULT_TIMEOUT_MS=300000 in ~/.bashrc or ~/.zshrc. It applies the next time you start claude.
  2. For one run: BASH_DEFAULT_TIMEOUT_MS=300000 claude.

Values in env are strings and are not run through a shell, so ~ and $HOME stay as typed: write absolute paths. Which file you use decides who they apply to:

FileApplies to
~/.claude/settings.jsonYou, in every project
.claude/settings.jsonEveryone in the project, checked into git
.claude/settings.local.jsonYou, in this project only

Which value wins?

When the same variable is in your shell and in a settings file's env, the settings file wins in most sessions. Between flags and variables it depends on the variable: --model and /model override ANTHROPIC_MODEL, but CLAUDE_CODE_EFFORT_LEVEL overrides --effort and /effort. A settings file can set a variable but not remove one; to cancel one your shell exports, set it to an empty string.

Which variables pick the model and effort?

VariableDoes
ANTHROPIC_MODELThe model to use, an alias such as opus or a full model name
CLAUDE_CODE_EFFORT_LEVELlow, medium, high, xhigh, max, or auto for the model's default; wins over --effort and /effort
CLAUDE_CODE_SUBAGENT_MODELThe model subagents, teammates and workflow agents get when nothing else names one
CLAUDE_CODE_MAX_OUTPUT_TOKENSThe most Claude writes in one reply; lowered to the model's own cap if set above it

How do you give long commands more time?

VariableDefaultDoes
BASH_DEFAULT_TIMEOUT_MS120000 (2 minutes)How long a Bash command may run when Claude does not ask for more
BASH_MAX_TIMEOUT_MS600000 (10 minutes)The longest timeout Claude may ask for on one command
BASH_MAX_OUTPUT_LENGTH30000 charactersHow much of a command's output reaches Claude (at most 150000)
API_TIMEOUT_MS600000 (10 minutes)How long each API request waits for its response to start; raise it on slow networks or behind a proxy

Claude can ask for a longer timeout on one command, up to BASH_MAX_TIMEOUT_MS, but when it does not, a test suite that takes four minutes is stopped after two. Setting BASH_DEFAULT_TIMEOUT_MS to 300000 gives every command five minutes from the start.

How do you run two Claude Code accounts side by side?

CLAUDE_CONFIG_DIR moves everything Claude Code keeps (settings, session history, plugins) to another folder. The documentation's own example is an alias:

alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'

claude keeps your personal setup in ~/.claude, and claude-work starts with its own login and settings. Project and local settings files cannot set this one.

How do you turn off telemetry and updates?

VariableTurns off
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICAuto-updates, telemetry, error reporting, /feedback, release notes and other non-essential traffic, all at once
DISABLE_TELEMETRYUsage telemetry only; any value, even 0 or false, turns it off, so unset it to turn telemetry back on
DISABLE_AUTOUPDATERBackground updates; claude update by hand still works
DISABLE_UPDATESEvery update, by hand too, for teams that ship Claude Code themselves
CLAUDE_CODE_DISABLE_AUTO_MEMORYAuto memory: Claude no longer creates or loads its memory files
CLAUDE_CODE_DISABLE_TERMINAL_TITLEThe terminal title that follows the conversation

Which variables matter behind a company proxy?

VariableDoes
HTTPS_PROXY, HTTP_PROXYThe proxy server for Claude Code's connections
NO_PROXYHosts and IPs that skip the proxy
ANTHROPIC_BASE_URLSends API requests to another host, such as a gateway your company runs

Also note ANTHROPIC_API_KEY: when it is set, Claude Code uses that key instead of your Pro, Max, Team or Enterprise subscription, even when you are logged in. If you are billed unexpectedly, check whether a shell profile exports it, and unset ANTHROPIC_API_KEY to go back to the subscription.

Which variables control MCP servers?

VariableDefaultDoes
MCP_TIMEOUT30000 (30 seconds)How long an MCP server has to start
MCP_TOOL_TIMEOUTabout 28 hoursHow long one MCP tool call may run; HTTP servers also stop each request after 60 seconds unless you raise this above 60000
MAX_MCP_OUTPUT_TOKENS25000The most an MCP tool's answer may hold; Claude Code warns above 10,000

Where can you check this?

Can you see every variable with what it does?

Config Studio for Claude Code lists Claude Code's environment variables in groups (the model, credentials, limits, the shell, MCP, turning things off, telemetry, proxies) and marks the ones it found only in the program and not in the documentation. It writes the env block into the right settings file for you, and nothing changes on your computer until you run its install script yourself.

The tool

Do it in your browser.

Claude Code

Config Studio for Claude Code

Every file Claude Code reads, explained: what each setting does, where it lives, which file wins, and an editor that writes it for you.

Keep reading

More from the blog.

Every post