Skip to main content
Claude Code reads environment variables at startup. These variables let you configure authentication, point to custom API endpoints, tune runtime behavior, and control which features are active — without modifying settings files.

Authentication

string
API key for authenticating directly with the Anthropic API. When set, Claude Code uses this key instead of (or in addition to) OAuth credentials. Takes priority over OAuth when present in most contexts.
string
Alternative authentication token. Used in contexts where ANTHROPIC_API_KEY is not applicable.
string
Override the Anthropic API base URL. Useful for pointing Claude Code at a proxy, staging environment, or compatible third-party endpoint.
string
Claude Code-specific API base URL override. Takes precedence over ANTHROPIC_BASE_URL when set.
string
Base URL for AWS Bedrock API access. Set this when routing Claude Code through a Bedrock endpoint.
string
Google Cloud project ID for Vertex AI access. Required when using Claude Code through Google Cloud’s Vertex AI platform.
string
Set to 1 or true to use AWS Bedrock as the API provider.
string
Set to 1 or true to use Anthropic Foundry as the API provider.
string
OAuth access token to use for authentication directly, bypassing the interactive login flow. Useful for automated environments.

Configuration paths

string
default:"~/.claude"
Override the directory where Claude Code stores its configuration, settings, and transcripts. Defaults to ~/.claude in your home directory.
string
Override the path to the managed settings file. Useful in enterprise environments where the default platform path is not appropriate.

Model selection

string
Default model to use. Overridden by the model setting in settings files and by explicit --model flags.
string
Model to use for sub-agent tasks spawned by the main agent. When not set, sub-agents use the same model as the main session.
string
Model to use when running in auto mode. Defaults to the main session model when not specified.

Behavior toggles

string
Set to 1 or true to enable remote/container mode. In this mode, Claude Code adjusts its behavior for non-interactive environments — extended API timeouts (120s vs. 300s), suppressed interactive prompts, and adapted output formatting.
string
Set to 1 or true (or pass --bare) to run in bare mode. Bare mode skips hooks, LSP integration, plugin sync, skill directory walks, attribution, background prefetches, and all keychain/credential reads. Authentication must be provided via ANTHROPIC_API_KEY or apiKeyHelper in --settings. Useful for lightweight scripted use.
string
Set to 1 or true to disable automatic context compaction. When set, Claude Code will not compact the conversation context even when it approaches the model’s context limit.
boolean
Set to 1 or true to disable background task execution. When enabled, the run_in_background parameter is removed from Bash and PowerShell tools, and Claude cannot run shell commands as background processes.
string
Set to 1 or true to disable extended thinking for all API calls, regardless of model support.
string
Set to 1 or true to disable automatic memory. When disabled, Claude does not read from or write to the auto-memory directory. Set to 0 or false to explicitly enable it (useful when other conditions would disable it, such as bare mode).Auto-memory is also disabled automatically in bare mode (CLAUDE_CODE_SIMPLE) and remote mode (CLAUDE_CODE_REMOTE) unless explicitly enabled.
string
Set to 1 or true to completely disable loading of all CLAUDE.md memory files. Claude will not read any CLAUDE.md, CLAUDE.local.md, or .claude/rules/*.md files.
string
Set to 1 or true to suppress analytics, telemetry, and other non-essential network requests.
string
Set to 1 or true to load CLAUDE.md files from directories added via --add-dir. By default, additional directories do not have their CLAUDE.md files loaded.
string
Set to 1 or true to reset the working directory back to the original project root after each Bash command. Prevents one command from changing the CWD for subsequent commands.

Resource limits

number
Override the maximum number of output tokens per API response. When not set, Claude Code uses the model’s default maximum. Useful for controlling costs in automated workflows.
number
Override the maximum context window size. When set, Claude Code uses this value instead of the model’s reported context limit.
number
Maximum number of characters captured from Bash command output. Output exceeding this limit is truncated. Useful for preventing very large command outputs from consuming context.
number
Override the API request timeout in milliseconds. Defaults to 300,000ms (5 minutes) for standard mode and 120,000ms (2 minutes) in remote mode.

Telemetry and observability

string
Set to 1 or true to enable OpenTelemetry export of traces, metrics, and logs. Requires additional OTEL configuration (endpoint, headers, etc.) to be set via standard OpenTelemetry environment variables.
string
Path to a file where Claude Code writes a JSONL transcript of the session. Each line is a JSON object representing a conversation event.

Node.js runtime

string
Standard Node.js options passed to the runtime. Claude Code reads this to detect flags like --max-old-space-size and adjusts its behavior accordingly. Claude Code itself sets this internally to configure heap size for large sessions.
Avoid setting NODE_OPTIONS to values that include code execution flags. Claude Code validates shell environments and treats some NODE_OPTIONS values as requiring confirmation before running Bash commands.

Host platform override

string
Override the reported host platform for analytics. Accepts "win32", "darwin", or "linux". Useful when Claude Code runs in a container (where process.platform reports the container OS) but the actual host platform differs.

Cloud provider region overrides

Claude Code supports per-model Vertex AI region overrides. Set the corresponding environment variable to route a specific model to a different region.
The default Vertex region is controlled by CLOUD_ML_REGION (defaults to us-east5).

AWS credentials

For Bedrock access, Claude Code respects standard AWS credential environment variables:
string
AWS region for Bedrock API calls. Falls back to AWS_DEFAULT_REGION, then defaults to us-east-1.
string
Fallback AWS region when AWS_REGION is not set.

Setting environment variables for all sessions

You can set environment variables that apply to every Claude Code session using the env field in your settings file, rather than setting them in your shell profile:
See Settings for documentation on the env field.