Claude Code reads more than 400 environment variables. You only need a handful of them, but those few fix real problems: commands that time out, the wrong account being billed, a model alias that points to an old version, or a proxy that blocks requests.
This guide explains how to set Claude Code environment variables on macOS, Linux and Windows, how to put them in settings.json so they apply every time, which source wins when two disagree, and the 30 most useful variables grouped by job. Everything follows Anthropic’s Claude Code documentation as of December 2026.
- One session:
export API_TIMEOUT_MS=1200000thenclaude(PowerShell:$env:API_TIMEOUT_MS = "1200000"). - Every session: put them under
"env"in~/.claude/settings.json. - Settings file beats shell for the same variable in most sessions.
- Longer commands:
BASH_DEFAULT_TIMEOUT_MSandBASH_MAX_TIMEOUT_MS. - Billing surprise:
ANTHROPIC_API_KEYoverrides your Pro/Max subscription when set. - Pin models:
ANTHROPIC_DEFAULT_OPUS_MODEL,..._SONNET_MODEL,..._HAIKU_MODEL.
Set Variables in Your Shell
A variable you set in the shell lasts for that terminal session. Set it before you launch claude.
macOS, Linux and WSL:
export API_TIMEOUT_MS="1200000"
claude
To make it permanent, add the export line to ~/.bashrc, ~/.zshrc or your shell profile.
Windows PowerShell:
$env:API_TIMEOUT_MS = "1200000"
claude
Permanent: [Environment]::SetEnvironmentVariable("API_TIMEOUT_MS", "1200000", "User"), then open a new terminal.
Windows CMD:
set API_TIMEOUT_MS=1200000
claude
Permanent: setx API_TIMEOUT_MS "1200000", then open a new terminal. Check a value with echo $API_TIMEOUT_MS (bash) or $env:API_TIMEOUT_MS (PowerShell).
Shell variables are read at startup, so restart Claude Code after changing them.
Set Variables in settings.json
Variables under the env key in a settings file apply every time Claude Code runs, no matter how it was launched.
{
"env": {
"API_TIMEOUT_MS": "1200000",
"BASH_DEFAULT_TIMEOUT_MS": "300000"
}
}
| File | Applies to |
|---|---|
~/.claude/settings.json |
You, in every project |
.claude/settings.json |
Everyone in the project (commit it) |
.claude/settings.local.json |
You, in this project only |
| Managed settings | Everyone in your organization |
- Open the file for the scope you want, creating it if needed.
- Add an
envobject with string values. - Use absolute paths. No shell processes these values, so
~and$HOMEstay as typed. - Save. A running session applies new and changed values immediately. Removed variables stay set until you relaunch.
Never commit API keys in .claude/settings.json. Put secrets in your shell or in settings.local.json. Our Claude Code settings guide explains every scope and key.
Which Value Wins?
- Shell vs settings file: the settings file value applies in most sessions, because Claude Code writes each
enventry into its environment. - Between settings files: normal settings precedence, so managed beats user and project.
- Variable vs settings key: it differs per key.
ANTHROPIC_MODELis read before themodelsetting. - Variable vs flags and commands: also per feature.
--modeland/modeloverrideANTHROPIC_MODEL, butCLAUDE_CODE_EFFORT_LEVELoverrides--effortand/effort. - Cannot unset a variable exported by a profile you do not control? Set it to an empty string in
env, for example"CLAUDE_CODE_USE_VERTEX": "".
Project and local settings cannot set some variables, such as CLAUDE_CONFIG_DIR. Numeric values accept forms like 2e3 and 64_000.
Authentication and Billing
| Variable | What it does |
|---|---|
ANTHROPIC_API_KEY |
API key sent as X-Api-Key. When set, it is used instead of your Pro, Max, Ultra, Team or Enterprise subscription. In -p mode it is always used; interactively you approve it once |
ANTHROPIC_AUTH_TOKEN |
Custom Authorization header value, prefixed with Bearer |
ANTHROPIC_BASE_URL |
Send requests through a proxy or gateway. Remote Control is disabled when it points elsewhere than the Anthropic API |
CLAUDE_CONFIG_DIR |
Move settings, history and plugins off ~/.claude; handy for two accounts |
If Claude Code is billing your API account when you expected your subscription, run unset ANTHROPIC_API_KEY. A two-account setup looks like this:
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'
Compare the options in our Claude Pro vs API guide.
Models, Effort and Context
| Variable | What it does |
|---|---|
ANTHROPIC_MODEL |
Model or alias for sessions launched with it |
ANTHROPIC_DEFAULT_MODEL |
Model new sessions start on when nothing else sets one |
ANTHROPIC_DEFAULT_OPUS_MODEL |
What opus resolves to, and what opusplan plans with |
ANTHROPIC_DEFAULT_SONNET_MODEL |
What sonnet resolves to, and what opusplan executes with |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
What haiku resolves to; also used for background tasks |
CLAUDE_CODE_SUBAGENT_MODEL |
Default model for subagents and agent team members |
CLAUDE_CODE_EFFORT_LEVEL |
low to max; beats every other effort source |
CLAUDE_CODE_AUTO_COMPACT_WINDOW |
When auto-compaction runs, 100K tokens or more |
CLAUDE_CODE_DISABLE_1M_CONTEXT |
1 holds sessions to a 200K window |
DISABLE_AUTO_COMPACT |
1 stops automatic compaction; /compact still works |
ANTHROPIC_SMALL_FAST_MODEL is deprecated; use the Haiku variable. Our guides on changing the model and the context window go deeper.
Timeouts and Output Limits
| Variable | Default | What it does |
|---|---|---|
BASH_DEFAULT_TIMEOUT_MS |
120000 (2 min) | Default timeout for a Bash or PowerShell command |
BASH_MAX_TIMEOUT_MS |
600000 (10 min) | Longest timeout the model can request |
API_TIMEOUT_MS |
600000 (10 min) | Time each API attempt has to get response headers |
MCP_TIMEOUT |
30000 (30 s) | MCP server startup timeout |
MAX_MCP_OUTPUT_TOKENS |
25000 | Maximum tokens in an MCP tool response |
CLAUDE_CODE_MAX_OUTPUT_TOKENS |
Per model | Max output tokens; values above the model cap are lowered |
MAX_THINKING_TOKENS |
Adaptive | Fixed extended thinking budget, minimum 1,024 |
Long builds or test suites killed after two minutes are the most common reason people look for these. Raise BASH_DEFAULT_TIMEOUT_MS to 300000 or more. Slow MCP servers are covered in our Claude Code MCP setup guide.
Cloud Providers and Proxies
| Variable | What it does |
|---|---|
CLAUDE_CODE_USE_BEDROCK |
Use Amazon Bedrock |
CLAUDE_CODE_USE_VERTEX |
Use Google Cloud’s Agent Platform (Vertex AI) |
HTTPS_PROXY |
HTTPS proxy for network connections |
CLAUDE_CODE_CERT_STORE |
Which CA certificates to trust: bundled, system or both (default bundled,system), useful with corporate TLS inspection |
DISABLE_PROMPT_CACHING |
1 turns off prompt caching for all models |
ENABLE_TOOL_SEARCH |
Controls MCP tool search; false loads all tools up front |
Leave prompt caching on unless a proxy breaks it; caching cuts cost a lot. See our prompt caching guide.
Updates, Telemetry and Privacy
| Variable | What it does |
|---|---|
DISABLE_AUTOUPDATER |
1 stops background updates; claude update still works |
DISABLE_TELEMETRY |
Any value opts out. Even 0 or false opts out; unset it to turn telemetry back on |
DISABLE_ERROR_REPORTING |
Same rule: any value opts out |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
Turns off auto-updates, telemetry, error reporting, /feedback and release notes in one go |
CLAUDE_CODE_ENABLE_TELEMETRY |
1 enables OpenTelemetry metrics for your own monitoring |
Telemetry events do not include code, file paths or Bash commands, according to the docs.
Shell and Terminal
| Variable | What it does |
|---|---|
CLAUDE_CODE_SHELL |
Path to the bash or zsh used for commands (fish is not supported) |
CLAUDE_CODE_GIT_BASH_PATH |
Windows: path to bash.exe when Git Bash is not on PATH |
CLAUDE_CODE_NO_FLICKER |
1 switches to fullscreen rendering |
CLAUDE_CODE_DISABLE_TERMINAL_TITLE |
1 stops automatic terminal titles and session title generation |
CLAUDE_CODE_BS_AS_CTRL_BACKSPACE |
Windows: set 0 if Backspace deletes whole words |
More terminal fixes in our Claude Code terminal setup guide.
Ready-Made Recipes
Let long builds finish
{
"env": {
"BASH_DEFAULT_TIMEOUT_MS": "600000",
"BASH_MAX_TIMEOUT_MS": "1800000"
}
}
Pin model versions for a team
{
"env": {
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5"
}
}
Quiet, privacy-first setup
{
"env": {
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}
Cheap subagents
export CLAUDE_CODE_SUBAGENT_MODEL=haiku
Common Mistakes to Avoid
- Setting a variable after launch. Shell variables are read when
claudestarts. Export first, then launch, or use the settings file, which applies to a running session when you save it. - Using
DISABLE_TELEMETRY=0to turn telemetry on. Any value opts out. Remove the variable instead. - Committing secrets.
.claude/settings.jsonis shared with your team through git. KeepANTHROPIC_API_KEYin your shell, a secret manager orsettings.local.json. - Writing
~/in a path. Theenvblock does not expand it, so the path points nowhere. - Raising timeouts too far. A very long
BASH_MAX_TIMEOUT_MSlets a stuck command hold the session. Raise it only as far as your slowest real task needs. - Forgetting that environment variables override
/effort. If effort changes seem ignored, check forCLAUDE_CODE_EFFORT_LEVEL.
Troubleshooting
My variable has no effect
Shell variables need a restart. Also check whether a settings file sets the same variable, since it usually wins, and whether the variable is one that project settings are not allowed to set.
Claude Code uses my API key instead of my subscription
ANTHROPIC_API_KEY is set somewhere. Unset it in the shell and remove it from settings files.
Commands stop after 2 minutes
Raise BASH_DEFAULT_TIMEOUT_MS, or ask Claude to run the task in the background.
A path variable fails in settings.json
Replace ~ with the full path; settings values are not expanded.
Still stuck? Our Claude Code not working guide covers install and auth errors.
FAQ
Where do I set environment variables for Claude Code?
In your shell before launching, or under "env" in ~/.claude/settings.json for every session.
How do I increase the Claude Code command timeout?
Set BASH_DEFAULT_TIMEOUT_MS (default 120000) and BASH_MAX_TIMEOUT_MS (default 600000).
How do I disable auto-update in Claude Code?
Set DISABLE_AUTOUPDATER=1. Use DISABLE_UPDATES to block manual updates too.
How do I turn off telemetry?
Set DISABLE_TELEMETRY=1, or CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 for all nonessential traffic.
Do settings.json env values override my shell?
Yes, in most sessions the settings file value replaces the inherited shell value.
Can I use variables like $HOME in settings.json?
No. Values are copied as written, so use absolute paths.



