Documentation

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:

PropertyConsequence
It is an array of objects, not a map"KEY": "value" is silently ignored — the panel starts with no variables
It is machine scopedEvery VS Code window on that computer is affected, not just the current folder
It shares the array with unrelated variablesProxy settings or NODE_EXTRA_CA_CERTS live in the same array — overwrite it and they are gone
It is read once, at agent spawnEditing 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
# macOS
2
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

SurfaceApplies toPersists
Shell export (~/.zshrc, ~/.bashrc, Windows environment variables)claude CLI started from a shellYes, per shell session
env block in settings.json (~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json)CLI, VS Code extension and Agent SDKYes, per settings scope
claudeCode.environmentVariablesThe VS Code extension panel onlyYes, machine wide

The settings.json scopes are worth distinguishing:

FileScope
~/.claude/settings.jsonYou, in every project
.claude/settings.jsonEveryone in the project (commit it)
.claude/settings.local.jsonYou, in this project only (git-ignored)
Managed settingsEveryone 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.json field (ANTHROPIC_MODEL beats model, for example).
  • --model on the command line and /model in a session beat ANTHROPIC_MODEL.
  • ANTHROPIC_API_KEY beats 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 ~/.bashrc
2
export ANTHROPIC_BASE_URL="https://www.codebyai.net/api/agent"
3
export ANTHROPIC_AUTH_TOKEN="sk-proj-xxxx"
4
export API_TIMEOUT_MS=600000
5
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

VariablePurpose
ANTHROPIC_API_KEYAPI key sent as the X-Api-Key header. Always used in -p mode
ANTHROPIC_AUTH_TOKENCustom Authorization header value, prefixed with Bearer
CLAUDE_CODE_OAUTH_TOKENOAuth access token for Claude.ai auth, for SDK and automated environments
CLAUDE_CODE_OAUTH_REFRESH_TOKENRefresh token exchanged without a browser by claude auth login
CLAUDE_CODE_OAUTH_SCOPESSpace-separated scopes the refresh token was issued with

Endpoint and provider routing

VariablePurpose
ANTHROPIC_BASE_URLOverride 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 / _FOUNDRYRoute through Amazon Bedrock, Google Vertex AI or Microsoft Foundry
ANTHROPIC_BEDROCK_BASE_URL / ANTHROPIC_VERTEX_BASE_URL / ANTHROPIC_FOUNDRY_BASE_URLOverride per provider endpoint
HTTP_PROXY / HTTPS_PROXY / NO_PROXYOutbound proxy for network connections
CLAUDE_CODE_SKIP_BEDROCK_AUTH and siblingsSkip provider auth when an LLM gateway signs requests itself

Model selection

VariablePurpose
ANTHROPIC_MODELModel 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 / _DESCRIPTIONAdd a custom entry to the /model picker
CLAUDE_CODE_SUBAGENT_MODELModel used by subagents
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYSet 1 to populate /model from the gateway's /v1/models
MAX_THINKING_TOKENSExtended thinking budget; 0 disables thinking on the Anthropic API
CLAUDE_CODE_MAX_OUTPUT_TOKENSMaximum output tokens per request

Timeouts and retries

VariableDefaultPurpose
API_TIMEOUT_MS600000Timeout for API requests, in milliseconds
BASH_DEFAULT_TIMEOUT_MS120000Default timeout for long-running Bash commands
BASH_MAX_TIMEOUT_MS600000Maximum timeout the model may set for Bash
CLAUDE_CODE_MAX_RETRIES10Retries for failed API requests

Proxy and gateway compatibility

These are the variables that decide whether a third-party endpoint works at all:

VariablePurpose
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC1 turns off the autoupdater, feedback command, error reporting and telemetry in one switch
CLAUDE_CODE_ATTRIBUTION_HEADER0 drops the attribution block from the system prompt, which improves prompt-cache hit rates behind a gateway
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS1 strips anthropic-beta headers a proxy may reject
CLAUDE_CODE_DISABLE_THINKINGOmits the thinking parameter entirely
ENABLE_TOOL_SEARCHtrue / false / auto: controls MCP deferred tool loading on a custom ANTHROPIC_BASE_URL
CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACKPrevents a mid-stream failure from re-running tool calls non-streamed
DISABLE_PROMPT_CACHINGTurns prompt caching off (debugging only — it raises cost)

Diagnostics and paths

VariablePurpose
DEBUG1 (or true, yes, on) enables debug mode, same as --debug
CLAUDE_CODE_DEBUG_LOG_LEVELMinimum log level: verbose, debug, info, warn, error
CLAUDE_CONFIG_DIROverride the configuration directory, default ~/.claude
CLAUDE_CODE_SIMPLE1 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.