Skip to main content
Reference

Environment variables reference

Complete reference of all Claude Code environment variables: configuration, API keys, debugging, and advanced settings.

Overview

Claude Code reads several environment variables at startup. They let you configure the tool without modifying settings.json files, which is ideal for CI/CD environments and automated deployments.

Environment variable priority

Environment variables generally have equal or lower priority compared to options explicitly set in settings.json. Check the documentation for each option to know its exact precedence.


Essential variables

ANTHROPIC_API_KEY

FieldValue
DescriptionAnthropic API key for authentication
RequiredYes (unless logged in via claude login)
DefaultNone
Formatsk-ant-api03-...
# In your ~/.bashrc, ~/.zshrc or ~/.profile
export ANTHROPIC_API_KEY="sk-ant-api03-xxxxxxxxxxxx"
# For a single session
ANTHROPIC_API_KEY="sk-ant-..." claude --print "hello"
# In CI/CD (GitHub Actions)
# Set in Settings > Secrets > ANTHROPIC_API_KEY
# Then in the workflow:
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

API key security

Never commit ANTHROPIC_API_KEY in a versioned file. Use a secret manager (AWS Secrets Manager, HashiCorp Vault, GitHub Secrets) in production. Rotate the key immediately if it gets exposed.


CLAUDE_MODEL

FieldValue
DescriptionDefault Claude model to use
RequiredNo
Defaultclaude-sonnet-4-5
FormatAnthropic model identifier
# Use Haiku for quick sessions (3x cheaper)
export CLAUDE_MODEL="claude-haiku-4-5"
# Use Opus for complex tasks
export CLAUDE_MODEL="claude-opus-4-5"
# Override for a single command
CLAUDE_MODEL="claude-opus-4-5" claude --print "complex task"

Common model identifiers:

  • claude-haiku-4-5: Fast and affordable
  • claude-sonnet-4-5: Recommended balance
  • claude-opus-4-5: Deepest reasoning

MAX_THINKING_TOKENS

FieldValue
DescriptionToken budget allocated for internal reasoning (Extended Thinking)
RequiredNo
Default31999 (when Extended Thinking is enabled)
FormatInteger
# Reduce the budget to limit costs
export MAX_THINKING_TOKENS=10000
# Maximum budget for complex tasks
export MAX_THINKING_TOKENS=31999
# Disable thinking for a session (minimum value)
export MAX_THINKING_TOKENS=1000

Lowering this value reduces reasoning depth and associated costs. Only relevant when alwaysThinkingEnabled: true or when Extended Thinking is manually enabled.


Network and proxy variables

ANTHROPIC_BASE_URL

FieldValue
DescriptionCustom base URL for Anthropic API calls
RequiredNo
Defaulthttps://api.anthropic.com
FormatFull URL
# Enterprise proxy
export ANTHROPIC_BASE_URL="https://proxy.my-company.com/anthropic"
# Local server (development/test)
export ANTHROPIC_BASE_URL="http://localhost:8080"
# Compatible with settings.json variables
# (ANTHROPIC_BASE_URL overrides customApiUrl)

HTTP_PROXY / HTTPS_PROXY

FieldValue
DescriptionHTTP/HTTPS proxy for all outgoing connections
RequiredNo
DefaultNone
Formathttp://[user:pass@]host:port
# Proxy without authentication
export HTTP_PROXY="http://proxy.company.com:8080"
export HTTPS_PROXY="http://proxy.company.com:8080"
# Proxy with authentication
export HTTPS_PROXY="http://user:password@proxy.company.com:8080"
# SOCKS5 proxy
export HTTPS_PROXY="socks5://proxy.company.com:1080"

NO_PROXY

FieldValue
DescriptionDomains excluded from the proxy (comma-separated list)
RequiredNo
DefaultNone
FormatComma-separated domain list
# Exclude local network from the proxy
export NO_PROXY="localhost,127.0.0.1,*.intranet.company.com"
# Combine with HTTPS_PROXY
export HTTPS_PROXY="http://proxy.company.com:8080"
export NO_PROXY="localhost,127.0.0.1"

Behavior variables

DISABLE_AUTOUPDATER

FieldValue
DescriptionDisable automatic update checking and installation
RequiredNo
DefaultNot set (auto-update enabled)
Format1 or true to disable
# Disable automatic updates
export DISABLE_AUTOUPDATER=1
# Useful in CI/CD to pin the Claude Code version
# and avoid unwanted updates in production

Recommended in CI/CD for build reproducibility. Use a fixed version of Claude Code in your pipelines.


CLAUDE_CODE_MAX_OUTPUT_TOKENS

FieldValue
DescriptionMaximum number of tokens in the generated response
RequiredNo
DefaultModel limit (varies by model)
FormatInteger
# Limit long responses
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096
# Maximum for tasks needing long responses
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=16000

CLAUDE_CONFIG_DIR

FieldValue
DescriptionAlternative directory for Claude Code configuration files
RequiredNo
Default~/.claude/
FormatAbsolute path to a directory
# Use an alternative configuration directory
export CLAUDE_CONFIG_DIR="/opt/claude-config"
# Useful for multi-user environments
# or per-project isolated configurations
export CLAUDE_CONFIG_DIR="$(pwd)/.claude-config"
# In CI/CD, for a completely isolated configuration
export CLAUDE_CONFIG_DIR="/tmp/claude-ci-config"

Summary table

VariableRequiredDefaultDescription
ANTHROPIC_API_KEYYes*NoneAnthropic API key
CLAUDE_MODELNoclaude-sonnet-4-5Default model
MAX_THINKING_TOKENSNo31999Extended Thinking budget
ANTHROPIC_BASE_URLNohttps://api.anthropic.comCustom API URL
HTTP_PROXYNoNoneHTTP proxy
HTTPS_PROXYNoNoneHTTPS proxy
NO_PROXYNoNoneProxy exclusions
DISABLE_AUTOUPDATERNoNoneDisable auto-updates
CLAUDE_CODE_MAX_OUTPUT_TOKENSNoModel limitMax output tokens
CLAUDE_CONFIG_DIRNo~/.claude/Alternative config directory

*Unless authenticated via claude login (Claude.ai Max account)


Configuration examples by context

Local development

# ~/.zshrc or ~/.bashrc
export ANTHROPIC_API_KEY="sk-ant-api03-..."
export CLAUDE_MODEL="claude-sonnet-4-5"
# Optional: Extended Thinking with reduced budget
export MAX_THINKING_TOKENS=10000

CI/CD (GitHub Actions)

# .github/workflows/claude.yml
jobs:
claude-task:
runs-on: ubuntu-latest
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
CLAUDE_MODEL: claude-haiku-4-5
DISABLE_AUTOUPDATER: "1"
CLAUDE_CODE_MAX_OUTPUT_TOKENS: "4096"
steps:
- uses: actions/checkout@v4
- run: npm install -g @anthropic-ai/claude-code
- run: claude --print --max-turns 5 "Check code quality"

Enterprise environment with proxy

# /etc/environment or system profile
ANTHROPIC_API_KEY="sk-ant-..."
ANTHROPIC_BASE_URL="https://ai-proxy.my-company.com"
HTTPS_PROXY="http://web-proxy.my-company.com:8080"
NO_PROXY="localhost,127.0.0.1,*.internal.my-company.com"
DISABLE_AUTOUPDATER=1
CLAUDE_CONFIG_DIR="/opt/claude-code/config"

Next steps