I had doubled API_TIMEOUT_MS in my shell profile, opened a fresh terminal, and re-run a long diff review. It stopped at exactly the same point as before. echo showed the new value sitting right there in the shell, so for a while I simply stared at it.
The culprit was an old value I had put in the env block of ~/.claude/settings.json months earlier and forgotten. Claude Code writes each env entry into its own process environment, replacing whatever it inherited from the shell. I had been looking in the wrong place the whole time.
This page is rewritten for anyone in the same spot. It walks the order I now use: does the variable exist → where did I set it → which source wins.
One thing I owe you up front: earlier versions of this page listed several variables that are not in the official reference. In November 2026 I went through the official Environment variables page line by line, removed the names that don't exist, and replaced them with the mechanisms that actually do the job. If you used the old version, I'm sorry, and the correction table below should save you some time.
Correcting the record: names that don't exist, and what to use instead
Claude Code gives no error and no warning when it sees a variable name it doesn't know. That is exactly why "is this name in the official list?" is the cheapest first check when something has no effect.
| Name in the old version | Reality | Use instead |
|---|---|---|
ANTHROPIC_TEMPERATURE | Not in the official list | Claude Code has no temperature variable. Steer output through CLAUDE.md, the model, and effort |
CLAUDE_CODE_DEBUG / CLAUDE_CODE_DEBUG_PROMPT / CLAUDE_CODE_DEBUG_API / CLAUDE_CODE_LOG_FILE | Don't exist | DEBUG=1 or claude --debug; output path via CLAUDE_CODE_DEBUG_LOGS_DIR |
CLAUDE_CODE_TELEMETRY / CLAUDE_CODE_CRASH_REPORTING | Don't exist | DISABLE_TELEMETRY / DISABLE_ERROR_REPORTING / CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
CLAUDE_CODE_REQUEST_TIMEOUT / CLAUDE_CODE_TOOL_TIMEOUT / CLAUDE_CODE_RETRY_BASE_MS | Don't exist | API_TIMEOUT_MS / BASH_DEFAULT_TIMEOUT_MS / BASH_MAX_TIMEOUT_MS / MCP_TOOL_TIMEOUT |
CLAUDE_CODE_REQUIRE_APPROVAL | Doesn't exist | Permission modes (permissions.defaultMode in settings, or --permission-mode) |
CLAUDE_CODE_SANDBOX / CLAUDE_CODE_PROJECT_SCOPE_STRICT | Don't exist | The sandbox.enabled setting plus permissions allow / deny rules |
CLAUDE_CODE_MAX_PARALLEL_TOOL_CALLS | Doesn't exist | I haven't been able to confirm any official equivalent |
ANTHROPIC_SMALL_FAST_MODEL | Exists but DEPRECATED | ANTHROPIC_DEFAULT_HAIKU_MODEL |
The other misconception was that environment variables sit at the bottom of a single precedence ladder. In practice it differs per variable: ANTHROPIC_MODEL is read before the model setting, and CLAUDE_CODE_EFFORT_LEVEL overrides both --effort and /effort. The next two sections separate "where" from "who wins".
Where to set it: your shell or the settings env block
There are two places. A value you export lasts for that terminal session; a value in a settings file's env block applies every time claude runs, however it was launched.
{
"env": {
"API_TIMEOUT_MS": "1200000",
"BASH_DEFAULT_TIMEOUT_MS": "300000"
}
}No shell processes env values, so ~ and $HOME stay exactly as typed. For path variables such as CLAUDE_CONFIG_DIR, write the absolute path.
| File | Applies to | Good for |
|---|---|---|
~/.claude/settings.json | You, every project | Personal preferences: timeouts, turning off reporting |
.claude/settings.json | Everyone on the project (checked in) | Model pins or MCP timeouts the repo should share |
.claude/settings.local.json | You, this project only | Local experiments |
| Managed settings | Everyone in the organization | Gateway endpoints, telemetry policy |
Be aware that project and local settings silently drop some variables. CLAUDE_CONFIG_DIR, CLAUDE_CODE_TMPDIR, HOME, TMPDIR, and the OpenTelemetry exporter variables, among others, are things a checked-out repository shouldn't control, so they only work from your shell, user settings, or managed settings. claude --debug shows the warning when one is dropped.
Who wins when two sources disagree
This is where my night went sideways, so here is the official behavior arranged the way I actually use it:
- Shell vs settings
env: in most sessions the settings file wins, because Claude Code writes eachenventry into the process environment over the inherited value - Between settings files: normal settings precedence applies, so managed settings override the same variable in user or project settings
- Against CLI flags and in-session commands: it varies per feature.
--modeland/modelbeatANTHROPIC_MODEL;CLAUDE_CODE_EFFORT_LEVELbeats--effortand/effort - Against a dedicated settings key: also per key.
ANTHROPIC_MODELis read first, and themodelsetting is only used when the variable is unset
When a value won't take, check the settings env blocks first and the shell last. That's the order I've stuck to since.
You can also neutralize a variable you can't unset. If a shell profile you don't control exports a stale CLAUDE_CODE_USE_VERTEX, setting it to an empty string in env makes Claude Code treat it as unset for provider selection:
{
"env": {
"CLAUDE_CODE_USE_VERTEX": ""
}
}Timing matters too. Shell variables are read once at startup. Settings env values are reapplied to a running session when you save the file, except for features that only read at startup, such as OpenTelemetry. Deleting a line from env doesn't unset it in the running session; that takes effect on the next launch.
Authentication and endpoints
Knowing the order Claude Code uses when several credentials are present is what keeps you from billing the wrong account. As of November 2026 the official order is:
- Cloud provider credentials, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEX, orCLAUDE_CODE_USE_FOUNDRYis set ANTHROPIC_AUTH_TOKEN(sent asAuthorization: Bearer, for gateways)ANTHROPIC_API_KEY(sent asX-Api-Key)- Output of the
apiKeyHelpersetting CLAUDE_CODE_OAUTH_TOKEN(a long-lived token fromclaude setup-token)- Anthropic profile and federation credentials
- Subscription credentials from
/login
So even if you've signed in with Pro or Max, a leftover ANTHROPIC_API_KEY in your shell is chosen first. In interactive mode you're asked once whether to use the key, and you can change that later with the "Use custom API key" toggle in /config.
# Direct Anthropic API
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
# Through a company gateway that authenticates with bearer tokens
export ANTHROPIC_BASE_URL="https://llm-gateway.example.internal"
export ANTHROPIC_AUTH_TOKEN="YOUR_GATEWAY_TOKEN"
# Amazon Bedrock (AWS_REGION is optional if your AWS profile sets one)
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION="us-east-1"
# Google Cloud's Agent Platform (Vertex AI)
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION="global"
export ANTHROPIC_VERTEX_PROJECT_ID="your-gcp-project"Rather than keeping an API key in plain text in a shell profile, I'd store it in the macOS Keychain and let apiKeyHelper fetch it. Anything in env sits in the settings file as plain text and is passed to every subprocess Claude Code starts.
# One-time setup
security add-generic-password -a "$USER" -s "anthropic-api-key" -w "YOUR_ANTHROPIC_API_KEY"{
"apiKeyHelper": "security find-generic-password -a $USER -s anthropic-api-key -w"
}apiKeyHelper runs through a shell, so $USER expands here, unlike values in env.
Models and how much the model thinks
| Variable | What it does | Watch out for |
|---|---|---|
ANTHROPIC_MODEL | The model to use | Loses to --model and /model; beats the model setting |
ANTHROPIC_DEFAULT_MODEL | Default model for new sessions (v2.1.236+) | Has no effect while ANTHROPIC_MODEL is set |
ANTHROPIC_DEFAULT_OPUS_MODEL / _SONNET_MODEL / _HAIKU_MODEL | What each alias resolves to | The Haiku one also drives background tasks |
CLAUDE_CODE_SUBAGENT_MODEL | Default model for subagents | An agent definition's model, or a model passed at spawn, takes precedence |
CLAUDE_CODE_EFFORT_LEVEL | low through max | Stronger than --effort and /effort; a maxEffortLevel cap still applies |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Output token limit | Values above the model's cap are lowered to the cap |
MAX_THINKING_TOKENS | Fixed extended-thinking budget | Capped one below max output; 0 disables |
Aliases resolve differently per provider. In the official table as of November 2026, sonnet is Sonnet 5.5 on the Anthropic API but Sonnet 4.5 on Amazon Bedrock and Agent Platform. Share one .claude/settings.json with a teammate on Bedrock and the same sonnet runs two different models. When versions need to match, pin a full ID such as claude-opus-5-5, or set ANTHROPIC_DEFAULT_SONNET_MODEL.
export ANTHROPIC_MODEL="sonnet"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5-20251001"
export CLAUDE_CODE_SUBAGENT_MODEL="haiku"
export CLAUDE_CODE_EFFORT_LEVEL="medium"The ANTHROPIC_MODEL versus ANTHROPIC_DEFAULT_MODEL trap gets its own write-up in Adding ANTHROPIC_DEFAULT_MODEL without removing ANTHROPIC_MODEL doesn't change the starting model.
Timeouts and retries
If you add a value without knowing the default, it's easy to think you shortened something you actually lengthened. Official defaults as of November 2026:
| Variable | Applies to | Default |
|---|---|---|
API_TIMEOUT_MS | Each API attempt, until response headers arrive | 600000 (10 min) |
BASH_DEFAULT_TIMEOUT_MS | Foreground Bash / PowerShell commands | 120000 (2 min) |
BASH_MAX_TIMEOUT_MS | The ceiling the model may request | 600000 (10 min) |
MCP_TIMEOUT | MCP server startup | 30000 (30 s) |
MCP_TOOL_TIMEOUT | MCP tool execution | 100000000 (about 28 h) |
CLAUDE_CODE_MAX_RETRIES | Retries for failed API requests | 10 |
API_TIMEOUT_MS covers the wait for headers, not how long a stream runs afterward. If long responses are what stall, MCP and command timeouts are usually the better first suspects.
MCP is the deepest trap. HTTP, SSE, and claude.ai connector servers also have a 60-second per-request limit, which only rises when MCP_TOOL_TIMEOUT or the per-server timeout is set above 60000. Setting it lower shortens the overall limit but leaves the 60 seconds in place. I wrote up how I ran into that in My MCP timeout setting was ignored and every call died at exactly 60 seconds.
Retries default to 10 but can stop earlier on 529 overloaded errors. In CI, I'd rather cap hangs with BASH_DEFAULT_TIMEOUT_MS and a job-level timeout than by cutting retries, because the log then tells you where it stopped.
Logs, telemetry and history
# Turn on debug logging (same as --debug)
export DEBUG=1
# Change where it's written (a FILE path, despite the name; this alone enables nothing)
export CLAUDE_CODE_DEBUG_LOGS_DIR="$HOME/claude-debug.txt"
# Opt out of telemetry and error reporting
export DISABLE_TELEMETRY=1
export DISABLE_ERROR_REPORTING=1
# Turn off auto-updates, telemetry, error reporting, release notes and similar traffic at once
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
# For throwaway scripted runs: keep prompt history and transcripts off disk
export CLAUDE_CODE_SKIP_PROMPT_HISTORY=1Two of these behave against intuition. DISABLE_TELEMETRY and DISABLE_ERROR_REPORTING still opt out when set to 0 or false; any non-empty value counts, so unset the variable to turn them back on. And CLAUDE_CODE_DEBUG_LOGS_DIR takes a file path, not a directory, and writes nothing unless DEBUG=1 or --debug is also set. The default location is ~/.claude/debug/<session-id>.txt.
Turning telemetry off also turns off feature-flag fetching, which disables some features. The official page lists which ones, and it's worth reading before you switch it off for a whole organization.
Tools and safety: settings, not variables
The old version said the PowerShell variable makes Claude Code use PowerShell instead of Bash. The real behavior is more specific:
| Environment | How CLAUDE_CODE_USE_POWERSHELL_TOOL behaves |
|---|---|
| Windows without Git Bash | Enabled automatically; 0 disables |
| Windows with Git Bash | On by default for claude.ai and Console accounts; 1 enables it on Bedrock, Agent Platform and Foundry |
| Linux, macOS, WSL | 1 enables it; requires pwsh on PATH |
CLAUDE_CODE_SHELL sets the shell the Bash tool uses and accepts a bash or zsh path. Shells like fish aren't supported, and an invalid path is quietly ignored in favor of auto-detection. To turn off only WebFetch, use CLAUDE_CODE_DISABLE_WEB_FETCH=1 (v2.1.285+); WebSearch stays available.
Approval behavior and sandboxing, on the other hand, live in settings:
{
"permissions": {
"defaultMode": "acceptEdits",
"deny": ["Read(./.env)", "Read(./secrets/**)"]
},
"sandbox": {
"enabled": true
}
}Permission modes are default, acceptEdits, plan, auto, dontAsk, and bypassPermissions. sandbox.enabled turns on Bash sandboxing on macOS, Linux, and WSL2. If an allow rule seems to be ignored, When an allow rule seems to be ignored walks through the layers to check.
Troubleshooting table
| Symptom | Likely cause | How to check | Fix |
|---|---|---|---|
| Changing an exported value changes nothing | The same variable is in a settings env block | grep -n '"env"' -A10 ~/.claude/settings.json .claude/settings*.json | Keep it in one place. If the shell should win, remove it from env and relaunch |
| Nothing happens at all | The name isn't in the official list (typo or invented name) | Search the official Environment variables page | Use the real name, or the settings key |
Only values in project env are ignored | A variable project settings can't set | Look for the warning in claude --debug | Move it to the shell, user settings, or managed settings |
Console is billed even after /login | ANTHROPIC_API_KEY ranks higher in auth order | Login method in /status; env | grep ANTHROPIC | Unset it, or turn off Use custom API key in /config |
Setting telemetry to 0 doesn't turn it back on | DISABLE_TELEMETRY treats any non-empty value as opt-out | env | grep DISABLE_ | Unset the variable |
| Same settings, different model than a teammate | Aliases resolve differently per provider | Compare the model in each person's /status | Pin a full model ID or ANTHROPIC_DEFAULT_*_MODEL |
| Value missing when launched from VS Code or the desktop app | That launch path doesn't read your shell profile | Compare echo in the integrated terminal and the app | Put it in ~/.claude/settings.json env, which doesn't depend on the launch path |
One footnote on that last row: when the Claude Desktop app or a self-hosted runner starts the session, the launch environment it builds takes precedence, and a settings env value is ignored for any variable that environment already sets. If a value won't take through the app, check the app's own environment settings too.
Templates by use case
Solo development (~/.claude/settings.json)
{
"env": {
"API_TIMEOUT_MS": "900000",
"BASH_DEFAULT_TIMEOUT_MS": "300000",
"DISABLE_ERROR_REPORTING": "1"
},
"apiKeyHelper": "security find-generic-password -a $USER -s anthropic-api-key -w",
"permissions": { "defaultMode": "acceptEdits" }
}I leave the model out of this file and pick it per task with /model. When the model lives in env, I tend to forget it's there every time I use /model.
Shared team settings (.claude/settings.json)
{
"env": {
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
"MCP_TIMEOUT": "60000",
"MCP_TOOL_TIMEOUT": "180000"
},
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)"]
}
}Endpoints and credentials don't belong here. Anyone who checks out the repo reads this file, so gateway URLs and telemetry policy go in managed settings, and credentials stay in each person's own environment.
CI (GitHub Actions)
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
ANTHROPIC_MODEL: claude-haiku-4-5-20251001
BASH_DEFAULT_TIMEOUT_MS: "180000"
CLAUDE_CODE_MAX_RETRIES: "3"
CLAUDE_CODE_SKIP_PROMPT_HISTORY: "1"
DISABLE_TELEMETRY: "1"claude -p starts in default mode, so tools that need approval won't run. Grant what the job needs explicitly with --allowedTools or allow rules. If CI runs on a subscription rather than an API key, store a CLAUDE_CODE_OAUTH_TOKEN from claude setup-token in secrets instead of ANTHROPIC_API_KEY.
The next thing that usually breaks
Once the variables are sorted out, the next snag is usually a misspelled settings key. Like variable names, unknown keys are silently ignored. A one-letter typo in a settings.json key is silently ignored by Claude Code shows how to catch them with /doctor. If billing is the worry, When Console was billing me despite a Pro plan may also help.
If you do one thing after reading this, open your ~/.claude/settings.json and take stock of what's sitting in env. For me, the answer to "why isn't this setting working" has almost always been there.