# Claude Code Environment Variables That Actually Matter

> Claude Code reads dozens of environment variables. Here are the ones worth setting on a build agent, and the three with side effects you did not want.

URL: https://www.matthewswong.com/en/blog/claude-code-env-vars-reference-guide/

- Author: Matthews Wong (https://www.matthewswong.com/en/about/)
- Published: 2026-08-27
- Updated: 2026-08-27
- Category: DevOps

> **Key takeaway:** Claude Code reads dozens of environment variables, and about fifteen are worth knowing. The most useful group tunes timeouts and limits for automation, where the interactive defaults are wrong. The most dangerous group are three switches whose effects reach further than their names suggest.

I once spent a morning working out why a pipeline sat for eleven minutes before failing. The answer was the retry count: the default is ten, which is generous and correct when a person is watching and would rather wait than start over, and completely wrong for a build agent that should have failed in thirty seconds and told someone.

That is the theme of this post. The defaults are chosen for an interactive session on a laptop, and a build agent, a container image, or a multi-tenant host wants different ones. Here is where environment variables sit in the precedence order, the groups worth setting deliberately, the switches that turn more off than you expect, and the two variables your own scripts can read.

## Where environment variables sit

Environment variables generally beat settings files, which is what makes them right for CI and wrong for a personal preference you will want to change later. If you find yourself exporting the same variable in every shell, it probably belongs in a settings file instead — and if you find a settings file being ignored, an environment variable is the first thing to check.

One consequence catches people out: a variable set for one project months ago is still set, and still wins. Authentication is the usual casualty, but the same applies to a model pin or a timeout you set once for a slow network and forgot. Check what the running session actually resolved rather than what you believe your configuration says.

## Timeouts and limits, for anything automated

This is the group with the best return on attention. The API timeout defaults to ten minutes, which is right for a long thinking turn on a slow link and far too patient for a pipeline. The retry count defaults to ten, which is the variable behind most mysterious multi-minute delays before a failure. And the Bash defaults bound how long a command may run and how much of its output comes back.

> The output cap is worth raising before you go hunting for a bug. By default Claude reads back 30,000 characters of Bash output, and a truncated test log looks exactly like a test suite that stopped early. The hard maximum is 150,000 — raising it costs tokens on a noisy command, so raise it for the run where you need the whole log rather than leaving it high everywhere.

## Authentication and model pinning

Two groups that overlap more than they look. Authentication variables select and supply a credential; model variables decide what an alias resolves to. On a cloud provider both matter, because the aliases resolve to a built-in default that can lag the newest release. The table below is the shape of it rather than the full list.

| Variable group | What to know |
| --- | --- |
| The API key variable | Overrides your subscription completely and silently. This is the single most common cause of confusing authentication behaviour |
| The provider switches | One variable per cloud provider selects where inference runs. The provider's own credentials and region settings then apply |
| The default-model pins | One per alias. On a third-party deployment, pinning is how you control when your team moves to a new model |
| The base URL variables | Point Claude Code at a gateway. Note that pointing the main one at a non-first-party host turns off MCP tool search by default |

## The switches that turn things off

Four of these come up constantly in locked-down environments, and one of them is much broader than its name. Auto-updates, telemetry and error reporting each have their own variable and do what they say. The non-essential-traffic switch is the blunt instrument.

> That last switch turns off feature-flag fetching along with telemetry and push notifications, which means it also disables features that depend on flag fetching — quietly, with no error to tell you which ones. Set it because your security posture requires it, not to reduce noise, and expect a handful of capabilities to be absent afterwards. The same logic applies to the do-not-track family.

## Storage, and hosting more than one tenant

Three variables control where state lives, and the second one exists specifically for hosts that embed Claude Code. By default the project folder is derived from the whole working directory path, which is fine on a laptop and wrong when a host wants each session in its own place. Naming it yourself requires setting the config directory too, and the value is read once at startup — so a settings file cannot supply it.

## Variables your own scripts can read

Two are set by Claude Code rather than read by it, and they are the reliable way for a hook or a wrapper to know where it is running:

- One is set in every subprocess Claude Code spawns — Bash, PowerShell, tmux, hooks, MCP servers — so a script can detect that it was invoked from a session rather than by a person.
- The other is set only in direct tool spawns and not in stdio MCP servers, which is the distinction you need when a script should behave differently inside a long-lived server.
- Between them you can make a shared script safe to run in both contexts, instead of writing two scripts or guessing from the terminal type.

## The ones with side effects

A few variables reach further than their names imply, and each has produced at least one confusing afternoon. The default Haiku model variable is the clearest example: it is read everywhere the small fast model is used, so changing it also changes conversation summarisation and other background work, not only whatever you were aiming at.

> One pairing is genuinely useful and non-obvious. Disabling the auto-updater stops Claude Code updating itself, which many organisations require — but it also stops plugin updates. Setting the plugin-update override alongside it keeps your marketplace plugins current while the CLI version stays pinned to whatever your organisation has approved.

Set the timeout and retry variables on any build agent, because the interactive defaults will otherwise turn a fast failure into a slow one. Keep the blunt traffic switch for environments that genuinely require it, and read the list of what it disables first. And whenever behaviour differs between two machines that should be identical, look at the environment before the configuration — it wins, and it is the part nobody has written down.

## Sources & further reading

- Claude Code docs — Environment variables
- Claude Code docs — Settings reference
- Claude Code docs — Model configuration
- Claude Code docs — Enterprise network configuration
- Claude Code docs — Monitoring usage with OpenTelemetry
- Claude Code docs — Data usage
- Claude Code docs — Hooks reference
- Claude Code docs — Setup

## Source links

- https://code.claude.com/docs/en/env-vars
- https://code.claude.com/docs/en/settings-reference
- https://code.claude.com/docs/en/model-config
- https://code.claude.com/docs/en/network-config
- https://code.claude.com/docs/en/monitoring-usage
- https://code.claude.com/docs/en/data-usage
- https://code.claude.com/docs/en/hooks
- https://code.claude.com/docs/en/setup

## FAQ

### Do environment variables override Claude Code settings files?

Generally yes, which is what makes them right for CI and containers and wrong for a personal preference. It also means a variable you exported for another project months ago still wins today. If a settings file appears to be ignored, check the environment first — the status and diagnostics commands show what the session actually resolved.

### Which Claude Code environment variables should I set in CI?

Lower the retry count so a pipeline fails fast instead of sitting through a long back-off, and raise the request timeout only if your network is slow. Bound Bash commands with the default and maximum timeout variables, and consider raising the Bash output cap for a run where you need a full log.

### What does disabling non-essential traffic actually turn off?

Feature-flag fetching, telemetry and error reporting collection, mobile push notifications for Remote Control, and background requests that are not essential to core functionality. Because some features depend on flag fetching, those stop working too, without an error naming them. Set it for policy reasons, not to reduce noise.

### How do I keep plugins updated but stop Claude Code updating itself?

Set the auto-updater disable variable and the plugin auto-update override together. The first pins your CLI version to whatever your organisation has approved; the second keeps marketplace plugins current. Without the second, disabling the updater also stops plugin updates.

### Can a script tell it is running inside Claude Code?

Yes. One environment variable is set in every subprocess Claude Code spawns, including Bash, PowerShell, tmux, hooks and MCP servers. A second is set only in direct tool spawns and not in stdio MCP servers, so a script can also tell those two contexts apart and behave accordingly.

---

- HTML version: https://www.matthewswong.com/en/blog/claude-code-env-vars-reference-guide/
- Bahasa Indonesia: https://www.matthewswong.com/id/blog/claude-code-env-vars-reference-guide/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
