← Claude Docs

Environment variables - Claude Code Docs

Claude Docs · April 8, 2026
ANTHROPIC_API_KEYAPI key sent as X-Api-Key header. When set, this key is used instead of your Claude Pro, Max, Team, or Enterprise subscription even if you are logged in. In non-interactive mode (-p), the key is always used when present. In interactive mode,

Detailed Analysis

Claude Code's environment variable system constitutes a comprehensive configuration layer that governs authentication, model selection, runtime behavior, shell interaction, and enterprise deployment across a wide range of infrastructure contexts. The documentation enumerates dozens of variables spanning API key management, custom headers, endpoint overrides for cloud platforms such as Amazon Bedrock, Google Vertex AI, and Microsoft Foundry, as well as fine-grained controls over timeout thresholds, bash command behavior, and agent orchestration. Notably, `ANTHROPIC_API_KEY` carries a dual-mode behavior: in non-interactive (pipeline) mode it is always applied when present, while in interactive mode users receive a one-time approval prompt before it overrides an active Claude Pro, Max, Team, or Enterprise subscription — a design choice that preserves user agency while accommodating automated workflows. Variables like `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_CUSTOM_HEADERS`, and `ANTHROPIC_BASE_URL` provide lower-level HTTP control, enabling teams to route traffic through proxies, gateways, or internally managed endpoints without modifying source code.

The model configuration subsystem is notably granular, with distinct environment variables for each tier of the Haiku, Sonnet, and Opus model families, including separate variables for model ID, display name, description, and supported capabilities. This architecture allows enterprise deployments to substitute custom or gateway-specific models into the `/model` picker without displacing built-in aliases, using variables such as `ANTHROPIC_CUSTOM_MODEL_OPTION`, `ANTHROPIC_CUSTOM_MODEL_OPTION_NAME`, and `ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION`. The deprecation of `ANTHROPIC_SMALL_FAST_MODEL` in favor of `ANTHROPIC_DEFAULT_HAIKU_MODEL` signals an ongoing maturation of Claude Code's configuration API, where earlier ad hoc naming conventions are being replaced by a more systematic and extensible taxonomy aligned with Anthropic's public model tier branding.

Several variables address the operational realities of agentic and multi-process environments. `CLAUDECODE`, set to `1` in all shell environments spawned by Claude Code's Bash tool and tmux sessions, allows scripts to detect programmatically whether they are executing inside a Claude Code context — a sentinel mechanism common in developer tooling ecosystems. `CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS` offers SDK consumers a blank-slate mode that suppresses built-in subagent types such as Explore and Plan, supporting custom orchestration pipelines that require precise control over agent behavior. Meanwhile, `CLAUDE_AUTO_BACKGROUND_TASKS` and `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` expose levers for managing long-running task lifecycles and context window compaction thresholds, respectively — reflecting the increasing prominence of extended, multi-turn agentic workflows that strain conventional request-response models.

The breadth of cloud provider integration variables — spanning AWS Bedrock, Google Vertex AI, and Microsoft Foundry, each with dedicated base URL, region, project ID, and API key variables — illustrates Anthropic's strategic positioning of Claude Code as an enterprise-grade tool compatible with major cloud procurement and compliance frameworks. Organizations operating under data residency or network egress constraints can use `ANTHROPIC_BEDROCK_BASE_URL` or `ANTHROPIC_VERTEX_BASE_URL` alongside internal LLM gateway infrastructure without code-level changes, lowering the barrier to regulated-industry adoption. The corresponding disabling of MCP tool search when `ANTHROPIC_BASE_URL` points to a non-first-party host — with opt-in re-enablement via `ENABLE_TOOL_SEARCH=true` — reflects a conservative security posture around third-party proxy trust boundaries.

Taken together, Claude Code's environment variable architecture reflects a deliberate design philosophy: expose maximum configurability at the process level without requiring persistent changes to version-controlled settings files, while enforcing sensible defaults and safe fallback behaviors. The support for truthy boolean conventions (`1`, `true`, `yes`, `on`) and the hard ceiling on `API_TIMEOUT_MS` at 2,147,483,647 milliseconds — above which integer overflow causes immediate request failure — indicate attention to operational edge cases that surface in production deployments. This level of environmental configurability situates Claude Code alongside mature developer infrastructure tools, suggesting Anthropic's intent to make it a first-class citizen in enterprise CI/CD pipelines, cloud-native development environments, and SDK-driven agent frameworks rather than a standalone interactive assistant.

Read original article →