Claude Code Environment Variables (2026)
The Problem
You need to configure Claude Code behavior through environment variables for proxy settings, API keys, model selection, MCP timeouts, or debug logging, but you do not know which variables exist or how to set them permanently.
Quick Fix
Set environment variables before launching Claude Code or add them to settings.json:
# One-time use
ANTHROPIC_MODEL=claude-sonnet-4-6 claude
# Permanent via settings
{
"env": {
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
"MCP_TIMEOUT": "10000"
}
}
What’s Happening
Claude Code reads environment variables from your shell and from the env key in settings.json files. Shell variables apply to the current session; settings.json variables apply to every session. When both are set, the shell environment takes precedence.
Settings.json supports user scope (~/.claude/settings.json) for personal configuration, project scope (.claude/settings.json) for team configuration, and managed scope for organization-wide enforcement.
Step-by-Step Fix
Essential variables
API authentication
# Direct Anthropic API
export ANTHROPIC_API_KEY=sk-ant-...
# Custom API key helper script
# Outputs key to stdout, used as X-Api-Key and Authorization: Bearer
In settings.json, use apiKeyHelper instead of storing keys directly:
{
"apiKeyHelper": "/path/to/generate-api-key.sh"
}
Model selection
# Override the default model
export ANTHROPIC_MODEL=claude-sonnet-4-6
Or set it in settings.json with the effortLevel key:
{
"effortLevel": "medium"
}
Effort levels (low, medium, high) are supported on Opus 4.6 and Sonnet 4.6.
Proxy and network configuration
# HTTP proxy for all outbound requests
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
# Corporate CA certificate for TLS inspection
export NODE_EXTRA_CA_CERTS=/path/to/corporate-ca.pem
MCP configuration variables
# MCP server startup timeout in milliseconds (default varies)
export MCP_TIMEOUT=10000
# Maximum MCP tool output tokens before warning (default: 10000)
export MAX_MCP_OUTPUT_TOKENS=50000
Provider-specific variables
AWS Bedrock
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret
export ANTHROPIC_MODEL=us.anthropic.claude-sonnet-4-6-20250514-v1:0
Google Vertex AI
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=us-east5
export ANTHROPIC_VERTEX_PROJECT_ID=your-project-id
export ANTHROPIC_MODEL=claude-sonnet-4-6@20250514
Debug and telemetry variables
# Enable telemetry
export CLAUDE_CODE_ENABLE_TELEMETRY=1
# OpenTelemetry metrics exporter
export OTEL_METRICS_EXPORTER=otlp
# Skip writing session transcripts
export CLAUDE_CODE_SKIP_PROMPT_HISTORY=1
Experimental features
# Enable agent teams
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
# New interactive init flow
export CLAUDE_CODE_NEW_INIT=1
Setting variables permanently
Add variables to ~/.claude/settings.json for all projects:
{
"env": {
"MCP_TIMEOUT": "10000",
"HTTP_PROXY": "http://proxy.example.com:8080",
"HTTPS_PROXY": "http://proxy.example.com:8080",
"NODE_EXTRA_CA_CERTS": "/path/to/corporate-ca.pem"
}
}
Add to .claude/settings.json for project-specific variables shared with your team:
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1"
}
}
Prevention
Use settings.json for variables that should persist rather than exporting them in your shell configuration. This keeps Claude Code configuration separate from your general shell environment and makes it visible to team members through project settings.
Document required environment variables in your project’s CLAUDE.md or README so new team members can configure them quickly.
Level Up Your Claude Code Workflow
The developers who get the most out of Claude Code aren’t just fixing errors — they’re running multi-agent pipelines, using battle-tested CLAUDE.md templates, and shipping with production-grade operating principles.
Configure it → Build your MCP config with our MCP Config Generator.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.
- Best Way to Set Up Claude Code for a New Project
- Claude Code Headless Linux Auth
- Claude Code TLS/SSL Connection Error Corporate Proxy Fix
- Claude Code Slow Response Fix
Common Questions
How do I get started with claude code environment variables?
Begin with the setup instructions in this guide. Install the required dependencies, configure your environment, and test with a small project before scaling to your full codebase.
What are the prerequisites?
You need a working development environment with Node.js or Python installed. Familiarity with the command line and basic Git operations is helpful. No advanced AI knowledge is required.
Can I use this with my existing development workflow?
Yes. These techniques integrate with standard development tools and CI/CD pipelines. Start by adding them to a single project and expand once you have verified the benefits.
Where can I find more advanced techniques?
Explore the related resources below for deeper coverage. The Claude Code documentation and community forums also provide advanced patterns and real-world case studies.