Claude Code Environment Variables
Every Claude Code environment variable: what it does, where to set it, and how it reaches the VS Code panel through claudeCode.environmentVariables.
Claude Code is configured almost entirely through environment variables. Authentication, the API endpoint, the model, retry and timeout behaviour, and every compatibility switch for proxies and gateways are environment variables — not command-line flags, and not fields in a config wizard. If a Claude Code setup does not behave the way you expect, this page is the checklist: which variable, which file, which precedence rule.
What claudeCode.environmentVariables is
claudeCode.environmentVariables is the VS Code setting that hands environment variables to the Claude Code extension panel. It is a plain array of { "name": ..., "value": ... } pairs stored in your VS Code user settings.json:
1 "claudeCode.environmentVariables": [2 { "name": "ANTHROPIC_BASE_URL", "value": "https://www.codebyai.net/api/agent" },3 { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-proj-xxxx" }4 ]
Four properties of this array are worth knowing before you edit it, because all four surprise people:
| Property | Consequence |
|---|---|
| It is an array of objects, not a map | "KEY": "value" is silently ignored — the panel starts with no variables |
| It is machine scoped | Every VS Code window on that computer is affected, not just the current folder |
| It shares the array with unrelated variables | Proxy settings or NODE_EXTRA_CA_CERTS live in the same array — overwrite it and they are gone |
| It is read once, at agent spawn | Editing it does nothing until Developer: Reload Window (or a VS Code restart) |
Why a shell export does not reach the extension panel
The claude CLI inherits the environment of the process that started it, so export ANTHROPIC_BASE_URL=... in ~/.zshrc works. The extension does not: it spawns its agent process from the VS Code window process, so the panel sees the desktop/login environment that VS Code was started with — never the shell you typed export into.
That is the cause of the most common Claude Code misconfiguration: the terminal works, the extension panel keeps talking to the default endpoint. Either launch VS Code from that terminal (so it inherits the variables — but then every window is routed), or set claudeCode.environmentVariables, which is the extension's own escape hatch.
Check what the panel actually sees
This prints the names the extension will inject, masking anything that looks like a credential:
1 # macOS2 S="$HOME/Library/Application Support/Code/User/settings.json"3 # Linux: S="$HOME/.config/Code/User/settings.json"4 # Windows: S="$APPDATA/Code/User/settings.json"5 6 jq -r '.["claudeCode.environmentVariables"] // [] | .[] | "\(.name)"' "$S"
No output means the panel inherits the VS Code process environment — the variables must come from somewhere else.
The three places a variable can be set
| Surface | Applies to | Persists |
|---|---|---|
Shell export (~/.zshrc, ~/.bashrc, Windows environment variables) | claude CLI started from a shell | Yes, per shell session |
env block in settings.json (~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json) | CLI, VS Code extension and Agent SDK | Yes, per settings scope |
claudeCode.environmentVariables | The VS Code extension panel only | Yes, machine wide |
The settings.json scopes are worth distinguishing:
| File | Scope |
|---|---|
~/.claude/settings.json | You, in every project |
.claude/settings.json | Everyone in the project (commit it) |
.claude/settings.local.json | You, in this project only (git-ignored) |
| Managed settings | Everyone in the organisation |
1 {2 "env": {3 "ANTHROPIC_BASE_URL": "https://www.codebyai.net/api/agent",4 "API_TIMEOUT_MS": "600000"5 }6 }
Precedence rules
- An environment variable beats the equivalent
settings.jsonfield (ANTHROPIC_MODELbeatsmodel, for example). --modelon the command line and/modelin a session beatANTHROPIC_MODEL.ANTHROPIC_API_KEYbeats the interactive subscription login in interactive mode; in-p(print) mode the API key is always used.- Variables are read at process start. Nothing reloads them mid-session: restart
claude, or run Developer: Reload Window in VS Code.
Pointing Claude Code at Code By AI
Code By AI exposes an Anthropic-compatible endpoint, so the only variables involved are the endpoint and the token that goes with it. Pick the surface that matches how you start Claude Code.
Terminal / CLI
1 # ~/.zshrc or ~/.bashrc2 export ANTHROPIC_BASE_URL="https://www.codebyai.net/api/agent"3 export ANTHROPIC_AUTH_TOKEN="sk-proj-xxxx"4 export API_TIMEOUT_MS=6000005 export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
VS Code extension
1 "claudeCode.environmentVariables": [2 { "name": "ANTHROPIC_BASE_URL", "value": "https://www.codebyai.net/api/agent" },3 { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-proj-xxxx" },4 { "name": "API_TIMEOUT_MS", "value": "600000" },5 { "name": "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC", "value": "1" }6 ],
Reload the window, then check the panel header shows the gateway endpoint. The step-by-step version, with Windows command-line equivalents, is in Claude Code configuration.
ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer <value>, which is what the Code By AI gateway expects. ANTHROPIC_API_KEY is sent as X-Api-Key instead — use one or the other, never both, or the wrong one may win.
Variable reference
Authentication
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY | API key sent as the X-Api-Key header. Always used in -p mode |
ANTHROPIC_AUTH_TOKEN | Custom Authorization header value, prefixed with Bearer |
CLAUDE_CODE_OAUTH_TOKEN | OAuth access token for Claude.ai auth, for SDK and automated environments |
CLAUDE_CODE_OAUTH_REFRESH_TOKEN | Refresh token exchanged without a browser by claude auth login |
CLAUDE_CODE_OAUTH_SCOPES | Space-separated scopes the refresh token was issued with |
Endpoint and provider routing
| Variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL | Override the API endpoint (proxy or gateway). A non-first-party host disables MCP tool search unless ENABLE_TOOL_SEARCH=true |
CLAUDE_CODE_USE_BEDROCK / _VERTEX / _FOUNDRY | Route through Amazon Bedrock, Google Vertex AI or Microsoft Foundry |
ANTHROPIC_BEDROCK_BASE_URL / ANTHROPIC_VERTEX_BASE_URL / ANTHROPIC_FOUNDRY_BASE_URL | Override per provider endpoint |
HTTP_PROXY / HTTPS_PROXY / NO_PROXY | Outbound proxy for network connections |
CLAUDE_CODE_SKIP_BEDROCK_AUTH and siblings | Skip provider auth when an LLM gateway signs requests itself |
Model selection
| Variable | Purpose |
|---|---|
ANTHROPIC_MODEL | Model to use. Overridden by --model and /model |
ANTHROPIC_DEFAULT_SONNET_MODEL / _HAIKU_ / _OPUS_ | Pin the default model ID for a tier |
ANTHROPIC_CUSTOM_MODEL_OPTION / _NAME / _DESCRIPTION | Add a custom entry to the /model picker |
CLAUDE_CODE_SUBAGENT_MODEL | Model used by subagents |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY | Set 1 to populate /model from the gateway's /v1/models |
MAX_THINKING_TOKENS | Extended thinking budget; 0 disables thinking on the Anthropic API |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Maximum output tokens per request |
Timeouts and retries
| Variable | Default | Purpose |
|---|---|---|
API_TIMEOUT_MS | 600000 | Timeout for API requests, in milliseconds |
BASH_DEFAULT_TIMEOUT_MS | 120000 | Default timeout for long-running Bash commands |
BASH_MAX_TIMEOUT_MS | 600000 | Maximum timeout the model may set for Bash |
CLAUDE_CODE_MAX_RETRIES | 10 | Retries for failed API requests |
Proxy and gateway compatibility
These are the variables that decide whether a third-party endpoint works at all:
| Variable | Purpose |
|---|---|
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC | 1 turns off the autoupdater, feedback command, error reporting and telemetry in one switch |
CLAUDE_CODE_ATTRIBUTION_HEADER | 0 drops the attribution block from the system prompt, which improves prompt-cache hit rates behind a gateway |
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS | 1 strips anthropic-beta headers a proxy may reject |
CLAUDE_CODE_DISABLE_THINKING | Omits the thinking parameter entirely |
ENABLE_TOOL_SEARCH | true / false / auto: controls MCP deferred tool loading on a custom ANTHROPIC_BASE_URL |
CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK | Prevents a mid-stream failure from re-running tool calls non-streamed |
DISABLE_PROMPT_CACHING | Turns prompt caching off (debugging only — it raises cost) |
Diagnostics and paths
| Variable | Purpose |
|---|---|
DEBUG | 1 (or true, yes, on) enables debug mode, same as --debug |
CLAUDE_CODE_DEBUG_LOG_LEVEL | Minimum log level: verbose, debug, info, warn, error |
CLAUDE_CONFIG_DIR | Override the configuration directory, default ~/.claude |
CLAUDE_CODE_SIMPLE | 1 runs with a minimal system prompt and only Bash and file tools |
Troubleshooting
The variable seems to be ignored. Check the surface first. A shell export is invisible to the VS Code extension panel; claudeCode.environmentVariables is invisible to the CLI. Then check the restart: environment variables are read once, at process start.
401 or invalid api key after switching endpoints. ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are sent in different headers. A leftover ANTHROPIC_API_KEY in the same scope will win in -p mode — remove it when you authenticate with a token.
Every request fails through a proxy. Add CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1; some proxies reject the beta headers Claude Code sends by default.
Requests time out on long generations. Raise API_TIMEOUT_MS (the default is ten minutes) rather than retrying — the timeout is generous but a large diff can exceed it.
The /model picker is empty on a gateway. Set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 so the picker is filled from the gateway's /v1/models, or name the model explicitly with ANTHROPIC_MODEL.
Prompt cache hit rate is low behind a gateway. Set CLAUDE_CODE_ATTRIBUTION_HEADER=0: the attribution block changes between sessions and invalidates the cached prefix.
FAQ
Where does Claude Code read environment variables from?
From the process environment it was started with, merged with the env block of the applicable settings.json files. The environment variable wins when both define the same behaviour. The VS Code extension panel is a separate process tree and needs claudeCode.environmentVariables instead.
Do I need to restart after changing a variable?
Yes. Claude Code reads its configuration at startup. Restart claude for the CLI, or run Developer: Reload Window in VS Code for the extension.
Which wins, ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN?
ANTHROPIC_API_KEY in -p mode, and it also overrides an interactive subscription login. If you route through a gateway that authenticates with a bearer token, unset ANTHROPIC_API_KEY to remove the ambiguity.
Can I use a different model without changing variables?
Yes — --model at launch and /model inside a session both override ANTHROPIC_MODEL. Variables set the default, flags override the variable.
Claude Code, Codex and Gemini all work through the same endpoint and the same key on Code By AI, from 1/6 of the official API price. See the price comparison or top up and get a key.