# Claude Code environment variables and where to set them

Authors: AutoRouter
Author profile: https://autorouter.com/about
Published: 2026-11-15T18:20:00.000Z
Reading time: 6 min
Canonical: https://autorouter.com/blog/claude-code-environment-variables
Publisher: AutoRouter, the Mac app that routes Codex, Claude Code and other AI tools to every model (https://autorouter.com)

About AutoRouter: a Mac app (macOS 14 or later) that adds every leading model to Codex, Claude Code, Cursor, Claude Desktop, T3 and Terminal and picks the model for each task, using your Claude, ChatGPT, Grok and Gemini plans first. Install from https://autorouter.com/AutoRouter.dmg, or ask your agent to follow https://autorouter.com/setup.md. Routing across your plans is free; Pro is $50 a month with $20 of included usage. Unrelated to OpenRouter's Auto Router.

> 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.

## 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://autorouter.com/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://autorouter.com/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. AutoRouter, the Mac app for Codex and Claude Code, 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 AutoRouter's settings switches it back. See [AutoRouter](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://autorouter.com/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                                           |

## 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 `~`.

### 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 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 install Claude Code on a Mac](https://autorouter.com/blog/install-claude-code-mac.md): To install Claude Code on a Mac, open Terminal, run `curl -fsSL https://claude.ai/install.sh | bash`, then open a new window and run `claude --version`. The native installer needs macOS 13 or later, doesn't need Node.js and updates itself; Homebrew (`brew install --cask claude-code`) and npm (Node.js 22 or later) also work. Run `claude` in your project and sign in with a Pro, Max, Ultra, Team, Enterprise or Console account, since the free Claude plan doesn't include Claude Code.
- [How to check your Claude Code usage](https://autorouter.com/blog/check-claude-code-usage.md): Run /usage in Claude Code to see your plan usage bars, a breakdown of what used your plan, and, for API users, a session token and cost estimate. Add a status line to keep plan and context usage on screen. AutoRouter, the Mac app for Codex and Claude Code, also shows the model and cost of every turn.
- [How Claude Code plan mode works, and which model plans](https://autorouter.com/blog/claude-code-plan-mode.md): Claude Code plan mode has Claude read your code and propose a plan without editing any files until you approve it. Turn it on with Shift+Tab, by starting a prompt with /plan, or with claude --permission-mode plan. Planning runs on your session's model unless you pick opusplan, which plans on Opus and builds on Sonnet; AutoRouter, the Mac app for Codex and Claude Code, instead picks a model for each turn while it is selected.

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

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