# Claude Code environment variables: the ones that matter

> The documented Claude Code environment variables by group, the ones that affect security and telemetry, and how the env key in settings.json works.

Claude Code reads a long list of environment variables, and the official reference documents them all in one table. Most tune timeouts and display. A handful decide which credential Claude Code uses, what it sends to Anthropic and what its child processes can see. You can export a variable in your shell or put it in the `env` key of a settings file. Where both set the same variable, the settings file value usually wins.

## Set them in the shell or in settings

A shell export lasts for that terminal session. An `env` entry in a settings file applies every time `claude` runs. The documented files are `~/.claude/settings.json` for every project, `.claude/settings.json` for a shared project, `.claude/settings.local.json` for you in one project, and managed settings for an organization.

```json
{
  "env": {
    "DISABLE_TELEMETRY": "1",
    "DISABLE_ERROR_REPORTING": "1",
    "CLAUDE_CODE_SUBPROCESS_ENV_SCRUB": "1"
  }
}
```

Values are copied as written, so `~` and `$HOME` are not expanded. To cancel a variable you cannot unset, set it to an empty string. Project and local files cannot set some variables, including `CLAUDE_CONFIG_DIR`, the OpenTelemetry exporter variables and `CLAUDE_CODE_OAUTH_TOKEN`. Set those in your shell. Plain-text values in `env` reach every subprocess, so keep API keys out of a committed `.claude/settings.json`. The reference points to `apiKeyHelper` for API credentials. [Claude Code API key guide](https://www.excellent.so/guides/claude-code-api-key)

## The groups in the reference

The reference is one large table. These are the families it contains.

| Group | Examples |
| --- | --- |
| Authentication and providers | `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL`, `AWS_BEARER_TOKEN_BEDROCK` |
| Models | `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, `CLAUDE_CODE_EFFORT_LEVEL` |
| Timeouts and retries | `API_TIMEOUT_MS`, `BASH_DEFAULT_TIMEOUT_MS`, `CLAUDE_CODE_MAX_RETRIES` |
| Network and proxies | `CLAUDE_CODE_CERT_STORE`, `CLAUDE_CODE_CLIENT_CERT` |
| Telemetry and updates | `DISABLE_TELEMETRY`, `DISABLE_ERROR_REPORTING`, `DISABLE_AUTOUPDATER` |
| MCP | `CLAUDE_CODE_MCP_ALLOWLIST_ENV`, `CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT` |
| Tools | `CLAUDE_CODE_DISABLE_WEB_FETCH`, `CLAUDE_CODE_MAX_WEB_SEARCHES_PER_SESSION` |
| Session data | `CLAUDE_CONFIG_DIR`, `CLAUDE_CODE_SKIP_PROMPT_HISTORY` |

## The ones that matter for security

`ANTHROPIC_API_KEY` is sent as the `X-Api-Key` header. If you have a subscription and this variable is also set, Claude Code uses the key once you approve it. In `-p` mode it is always used when present. Run `unset ANTHROPIC_API_KEY` to fall back to your subscription.

For data leaving your Mac, the documented opt-outs are separate switches:

- `DISABLE_TELEMETRY` stops usage metrics. Any non-empty value opts out, including `0`. It also disables feature-flag fetching.
- `DISABLE_ERROR_REPORTING` stops error reports. Again, any non-empty value opts out.
- `DISABLE_FEEDBACK_COMMAND=1` disables `/feedback`, and also `/bug` and `/share`.
- `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` covers auto-updates, telemetry, error reporting, `/feedback`, release notes and feature-flag fetching in one step.

The data usage page says the WebFetch hostname check is not affected by the nonessential-traffic variable. Its opt-out is `skipWebFetchPreflight` in settings. The same page says metrics do not include your code, prompts or file paths.

For what child processes can see, set `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1`. It removes credentials from the environments of Bash commands, hooks and stdio MCP servers, matching by variable name or by the shape of the value. The reference calls it one layer to use beside narrow permission rules. `CLAUDE_CODE_DISABLE_WEB_FETCH` turns off WebFetch.

For what stays on disk, `CLAUDE_CODE_SKIP_PROMPT_HISTORY=1` skips writing prompt history and session transcripts. Sessions started with it do not appear in `--resume` or `--continue`. [History and logs guide](https://www.excellent.so/guides/claude-code-history-and-logs)

## Check what is set

Run `/status` inside Claude Code to see the active settings sources and which credential is in use. Shell variables are read at startup, so they take effect the next time you launch `claude`. Changes to `env` in a settings file apply to a running session when the file is saved, though startup-only features keep their startup values. Removing a variable from the file does not unset it in the running session.

Checked against the vendor documentation on November 25, 2026. [Environment variables](https://code.claude.com/docs/en/env-vars) · [Data usage](https://code.claude.com/docs/en/data-usage) · [Settings](https://code.claude.com/docs/en/settings)

## What Excellent adds

Excellent’s free scan reads supported logs on the Mac and reports findings for review. It reads Claude Code session logs. For a local report without installing an app, [run the free scan](https://www.excellent.so/scan). Its script uses Python 3.9 or later when your Mac has it and the shell when it doesn’t, reads the logs locally and makes no network requests. [See a sample report](https://www.excellent.so/r/sample).

Excellent Pro adds checks before supported actions, including keys typed into commands. It blocks some steps and asks before others. Pro is US-only for now. [Pricing](https://www.excellent.so/pricing) · [Keeping keys and your email out of agent logs](https://www.excellent.so/guides/keep-keys-and-email-out-of-agent-logs)

Source: https://www.excellent.so/guides/claude-code-environment-variables
