# Claude Code environment variables and where to set them

> Claude Code reads environment variables from your shell (`export NAME=value` before you run `claude`) or from the `env` key of a settings.json file, which applies every time it runs. Anthropic's reference lists 406 variables as of November 13, 2026; the ones most people set cover sign-in (`ANTHROPIC_API_KEY`), the endpoint (`ANTHROPIC_BASE_URL`), the model, timeouts, updates and telemetry. When a variable is set in both places, the settings file value usually wins.

Author: Tyler J. Cagle (https://x.com/tjcages)
Published: 2026-11-15T18:20:00.000Z
Reading time: 7 min
Canonical: https://auto.sh/blog/claude-code-environment-variables
Publisher: Auto (https://auto.sh)

## Key facts

- Anthropic's environment variable reference lists 406 variables as of November 13, 2026 ([Anthropic](https://code.claude.com/docs/en/env-vars#variables)).
- A variable in the `env` key of a settings.json file applies however `claude` was launched, and it overrides the same variable from your shell in most sessions.
- `DISABLE_TELEMETRY`, `DISABLE_ERROR_REPORTING` and `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` turn on with any non-empty value, so setting them to `0` still opts out.
- `ANTHROPIC_API_KEY` replaces your Claude subscription even when you are logged in, after you approve it once in an interactive session.

![Claude Code reads 406 environment variables. 406 environment variables. Source: Anthropic's Claude Code environment variable and settings docs, checked November 13, 2026.](https://auto.sh/blog/images/claude-code-environment-variables/1-variable-count.png)

As of November 13, 2026, [Anthropic's environment variable reference](https://code.claude.com/docs/en/env-vars) lists 406 variables that Claude Code reads. You set one in your shell before launching `claude`, which lasts for that terminal session, or under the `env` key of a `settings.json` file, which applies every time Claude Code runs. This post covers the variables most people set, grouped by job, and the rules for which value wins. Model variables get a short table here; [how to change the model in Claude Code](/blog/claude-code-model-settings) covers them in full.

## Where do you set Claude Code environment variables?

Set a variable in your shell for one session, or in a settings file for every session. In the shell, export it before you start Claude Code, and add the line to `~/.zshrc` to keep it:

```bash
export API_TIMEOUT_MS="1200000"
claude

# check what's set
echo $API_TIMEOUT_MS
```

In a settings file, put it under `env`. Claude Code reads these values from the file directly, so they apply no matter how `claude` was launched:

```json
{
  "env": {
    "API_TIMEOUT_MS": "1200000",
    "BASH_DEFAULT_TIMEOUT_MS": "300000"
  }
}
```

No shell processes the `env` block, so `~` and `$HOME` stay as typed; write absolute paths, such as `"CLAUDE_CONFIG_DIR": "/Users/you/.claude-work"`. The file you choose decides who the variable applies to:

| File                          | Applies to                                           |
| ----------------------------- | ---------------------------------------------------- |
| `~/.claude/settings.json`     | You, in every project                                |
| `.claude/settings.json`       | Everyone in the project, checked into source control |
| `.claude/settings.local.json` | You, in this project only                            |
| Managed settings              | Everyone in your organization, set by an admin       |

## Which value wins when a Claude Code variable is set twice?

When the same variable is in your shell and in a settings file, the settings file value applies in most sessions, because Claude Code writes each `env` entry over the inherited one ([Anthropic](https://code.claude.com/docs/en/env-vars#precedence)). Between settings files, managed settings beat user and project settings. A few more rules decide the rest:

- **Flags and commands vary by feature.** `--model` and `/model` override `ANTHROPIC_MODEL`, but `CLAUDE_CODE_EFFORT_LEVEL` overrides `--effort` and `/effort`.
- **Variable before setting, for some keys.** `ANTHROPIC_MODEL` wins over the `model` setting, which applies only when the variable is unset.
- **Project files can't set everything.** Project and local settings can't set `CLAUDE_CONFIG_DIR`, `CLAUDE_CODE_OAUTH_TOKEN` or the OpenTelemetry exporter variables.
- **Shell values load once.** Claude Code reads shell variables at startup, so restart `claude` after an `export`. Values in a settings file reapply to a running session when you save it, except features that read them only at startup.
- **You can't remove a variable from a settings file.** To cancel one your shell exports, set it to an empty string, such as `"CLAUDE_CODE_USE_VERTEX": ""`.

![The highest place a variable is set wins. Where it's set, highest first: 1. Managed settings, Everyone in your organization; 2. .claude/settings.local.json, You, in this project; 3. .claude/settings.json, Everyone in the project; 4. ~/.claude/settings.json, You, in every project; 5. export in your shell, That terminal session. Source: Anthropic's Claude Code environment variable and settings docs, checked November 13, 2026.](https://auto.sh/blog/images/claude-code-environment-variables/2-where-to-set.png)

## Which environment variables control sign-in and the API endpoint?

These variables decide which account pays and where requests go. `ANTHROPIC_API_KEY` is the one that surprises people: when set, it is used instead of your Pro, Max, Ultra, Team or Enterprise subscription even if you are logged in, after you approve it once in an interactive session, and always in `-p` mode ([Anthropic](https://code.claude.com/docs/en/env-vars#variables)).

| Variable                                                                       | What it does                                                                                                           |
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `ANTHROPIC_API_KEY`                                                            | API key sent as the `X-Api-Key` header; replaces your subscription once approved. `unset ANTHROPIC_API_KEY` to go back |
| `ANTHROPIC_AUTH_TOKEN`                                                         | Custom `Authorization` header value, sent as `Bearer <value>`                                                          |
| `CLAUDE_CODE_OAUTH_TOKEN`                                                      | A claude.ai login token for scripts and the SDK, made with `claude setup-token`                                        |
| `ANTHROPIC_BASE_URL`                                                           | Sends requests to a proxy or gateway instead of api.anthropic.com; Remote Control turns off when it points elsewhere   |
| `ANTHROPIC_CUSTOM_HEADERS`                                                     | Extra request headers, `Name: Value`, one per line                                                                     |
| `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `CLAUDE_CODE_USE_FOUNDRY` | Use Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry                                                 |
| `HTTPS_PROXY`, `HTTP_PROXY`, `NO_PROXY`                                        | Corporate proxy, and the hosts that bypass it                                                                          |

Gateways and model routers usually attach to Claude Code through these settings, and [the best Claude Code routers](/blog/model-routers-claude-code-codex) are ranked side by side. Auto, the Mac app for all your coding agents, adds itself to Claude Code's `settings.json` when you enable it, after saving a copy of the file; your other settings stay as they are, and disabling Claude Code in Auto's settings switches it back. See [Auto](https://autorouter.com/) for setup.

## Which environment variables choose Claude Code's model and effort?

Claude Code takes its model from `ANTHROPIC_MODEL` when no `--model` flag or `/model` choice overrides it, and from these related variables:

| Variable                                                        | What it does                                                                  |
| --------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `ANTHROPIC_MODEL`                                               | Model for sessions launched with it                                           |
| `ANTHROPIC_DEFAULT_MODEL`                                       | Model new sessions start on when nothing else sets one                        |
| `ANTHROPIC_DEFAULT_OPUS_MODEL`, `_SONNET_MODEL`, `_HAIKU_MODEL` | The model ID each alias resolves to; the Haiku one also runs background tasks |
| `CLAUDE_CODE_SUBAGENT_MODEL`                                    | Default model for subagents and teammates that have none set                  |
| `CLAUDE_CODE_EFFORT_LEVEL`                                      | `low`, `medium`, `high`, `xhigh` or `max`; overrides `--effort` and `/effort` |
| `MAX_THINKING_TOKENS`                                           | Fixed extended-thinking budget; `0` turns thinking off                        |

## Which environment variables set Claude Code's timeouts and limits?

Raise these when long commands, slow networks or large tool results get cut off. All times are in milliseconds.

![API requests get 10 minutes; MCP startup gets 30 seconds. API request, 600 s; Longest shell command, 600 s; Shell command, 120 s; MCP server startup, 30 s. Source: Anthropic's Claude Code environment variable and settings docs, checked November 13, 2026.](https://auto.sh/blog/images/claude-code-environment-variables/3-default-timeouts.png)

Defaults from Anthropic's reference. Each variable takes milliseconds: 600 seconds is `600000`.

| Variable                          | Default             | What it limits                                                                  |
| --------------------------------- | ------------------- | ------------------------------------------------------------------------------- |
| `API_TIMEOUT_MS`                  | 600000 (10 minutes) | Time each API request has to receive its response headers                       |
| `BASH_DEFAULT_TIMEOUT_MS`         | 120000 (2 minutes)  | Default timeout for a foreground shell command                                  |
| `BASH_MAX_TIMEOUT_MS`             | 600000 (10 minutes) | Longest timeout Claude can set for a shell command                              |
| `MCP_TIMEOUT`                     | 30000 (30 seconds)  | MCP server startup                                                              |
| `MAX_MCP_OUTPUT_TOKENS`           | 25000 tokens        | Size of an MCP tool response; a warning shows above 10,000                      |
| `CLAUDE_CODE_MAX_OUTPUT_TOKENS`   | Varies by model     | Output tokens per request; higher values leave less room before auto-compaction |
| `CLAUDE_CODE_AUTO_COMPACT_WINDOW` | Varies by model     | How full the context gets before compaction, 100,000 to 1,000,000 tokens        |
| `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` | Not set             | Percentage of that window at which compaction starts; can only lower it         |

## Which environment variables control updates, telemetry and privacy?

Most on/off variables accept `1`, `true`, `yes` or `on`, but three read only whether they are set at all: `DISABLE_TELEMETRY`, `DISABLE_ERROR_REPORTING` and `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`. For those, `0` and `false` still turn the behavior on; unset the variable to turn it off ([Anthropic](https://code.claude.com/docs/en/env-vars#variables)).

| Variable                                   | What it does                                                                                   |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| `DISABLE_AUTOUPDATER`                      | Stops background updates; `claude update` still works                                          |
| `DISABLE_UPDATES`                          | Blocks every update, manual ones included                                                      |
| `CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE`  | Lets Claude Code run the Homebrew or WinGet upgrade for you                                    |
| `DISABLE_TELEMETRY`                        | Opts out of telemetry and feature-flag fetching                                                |
| `DISABLE_ERROR_REPORTING`                  | Opts out of error reporting                                                                    |
| `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | Turns off auto-updates, telemetry, error reporting, `/feedback` and other nonessential traffic |
| `DISABLE_PROMPT_CACHING`                   | Turns off prompt caching for all models, which makes requests cost more                        |
| `CLAUDE_CONFIG_DIR`                        | Moves settings, history and plugins from `~/.claude`, for example to run two accounts          |
| `CLAUDE_CODE_SHELL`                        | Path to the `bash` or `zsh` that runs shell commands                                           |

If you use an environment block to connect a model provider, see what carries over with the [Claude Code config checker](/switch/claude-code-env).

## Questions

### Why isn't my Claude Code environment variable taking effect?

The usual causes are a session started before you ran `export`, a settings file that sets the same variable and wins, or a project settings file trying to set a variable only user or managed settings may set. Run `echo $NAME` in the same terminal, restart `claude`, and run `claude doctor` to see settings errors.

### How do I unset a variable that my shell profile exports?

Run `unset NAME` in your shell, or, if you can't change the profile, set the variable to an empty string in your settings file's `env` block. Claude Code treats the empty value as unset for provider selection, though subprocesses still inherit it.

### Can I run two Claude accounts side by side?

Yes. Give each its own config folder with `CLAUDE_CONFIG_DIR`, for example `alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'`. Anthropic's docs suggest this alias; in a settings file, write the absolute path instead of `~`. [How to use multiple Claude accounts in Claude Code](/blog/claude-code-multiple-accounts) walks through the full setup and the other ways to switch.

### Which variables does an MCP server use?

Claude Code itself reads `MCP_TIMEOUT`, `MAX_MCP_OUTPUT_TOKENS` and `ENABLE_TOOL_SEARCH`. A server's own keys go in its `--env` flags or its `.mcp.json` entry, which can expand `${VAR}` from your environment; [how to add an MCP server to Claude Code](/blog/claude-code-mcp-servers) shows both.

### Where do I set variables if I haven't installed Claude Code yet?

Install first; the variables do nothing until `claude` runs. [How to install Claude Code on a Mac](/blog/install-claude-code-mac) walks through it, including the `CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE` setting for Homebrew installs.

## Sources

- [Environment variables](https://code.claude.com/docs/en/env-vars), Anthropic, checked November 13, 2026
- [Settings](https://code.claude.com/docs/en/settings), Anthropic, checked November 13, 2026
- [Model configuration](https://code.claude.com/docs/en/model-config), Anthropic, checked November 13, 2026
- [Advanced setup](https://code.claude.com/docs/en/setup), Anthropic, checked November 13, 2026

## Read next

- [How to choose and change models in Codex and Claude Code](https://auto.sh/blog/models-in-codex-and-claude-code.md): To give each task the right model, use Auto, the Mac app for all your coding agents: it adds models from every leading provider to the picker you already use (Claude Code, Codex, Cursor, etc.) and can pick one for each turn. To choose yourself, give hard, multi-file work a frontier model such as Claude Opus 5.5 or GPT-6.2 Astra and quick edits a fast one such as Claude Haiku 5.5 or GPT-6 Luna. Switch with /model in either app, a launch flag for one session, or a settings file for every session.
- [How to see which model handled each turn, and what it cost](https://auto.sh/blog/see-what-each-turn-costs.md): Use Auto, the Mac app for all your coding agents: while it is the model selected, every turn shows its model, what it cost and why. Natively, Claude Code's OpenTelemetry logs the model and estimated cost of every request, and a prompt.id groups them into turns; claude -p --output-format json reports cost by model for one run. In Codex, codex exec --json reports each turn's tokens, which you price with OpenAI's credit rates.
- [How to use Codex in Claude Code](https://auto.sh/blog/codex-in-claude-code.md): Use Auto, the Mac app for all your coding agents, to run GPT as Claude Code's own model on your ChatGPT plan: connect the plan, enable Claude Code, and pick a GPT model or Auto with `/model`. To call Codex itself from Claude Code, install OpenAI's Codex plugin with `/plugin marketplace add openai/codex-plugin-cc` and `/plugin install codex@openai-codex`, run `/codex:setup`, then use `/codex:review` for a second review or `/codex:rescue` to hand off a task. The plugin runs on your ChatGPT plan's Codex limits or an OpenAI API key.

Tags: [Claude Code](https://auto.sh/blog/tags/claude-code.md), [Guides](https://auto.sh/blog/tags/guides.md)

Drafted with AI from the sources linked above, then checked and edited by the Auto team.

Auto is a Mac app for AI model routing in Codex, Claude Code, Cursor and other supported coding agents. It uses eligible connected subscriptions first. See [setup](https://auto.sh/setup.md) and [pricing](https://auto.sh/pricing).
