Auth and Accounts
These variables tell Claude Code who you are. They carry API keys, bearer tokens, OAuth data, and the commands that fetch credentials for you. Put secrets in your shell or a secrets manager, not in a file you commit.
This page lists 71 variables. ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are the common ones. Run /login for a stored login. Project settings cannot set some of them before you trust the folder.
Example
export ANTHROPIC_API_KEY="sk-ant-your-key"
claude
Claude Code sends the key as the x-api-key header.
Variables
The table is sorted by name. See Environment Variables for what each column and badge means.
| Variable | Status | What it does | Values and default | Notes |
|---|---|---|---|---|
ANTHROPIC_ | Documented | Sets the API key that Claude Code sends to the API. It takes precedence over a profile sign-in. | Text | All sessions. Not set from project env before trust |
ANTHROPIC_ | Documented | Sets the Authorization header to Bearer plus the value. Also counts as a credential for gateway model discovery. | Text. Read on each access | All sessions. Not set from project env before trust |
ANTHROPIC_ | Documented | Workspace API key for Claude Platform on AWS. When it is set, Claude Code skips the AWS credential chain for that client. | Text. Code removes it for a moment while it builds a client that uses the AWS chain | Provider anthropic. Not set from project env before trust |
ANTHROPIC_ | Documented | Sets the directory for Anthropic profile files. Claude Code reads configs and credentials files from it. | Text. Wins over XDG_. Unused when a helper returns null for the current mode | Profile and federation sign-in, all. Not set from project env before trust |
ANTHROPIC_ | Documented | Federation rule ID for workload identity federation. With ANTHROPIC_ it selects the env- federation credential. | Text. ANTHROPIC_ is an optional third value | All sessions. Not set from project env before trust |
ANTHROPIC_ | Documented | API key for Microsoft Foundry. When it is set, Claude Code does not build the Azure default credential. | Text. The Foundry client reads the key. ANTHROPIC_ wins over it | Provider foundry. Project env can set it before trust |
ANTHROPIC_ | Documented | Bearer token for Microsoft Foundry. It wins over the API key and over the Azure default credential. | Text. The token provider returns it on each request | Provider foundry. Not set from project env before trust |
ANTHROPIC_ | Documented | The bundled SDK uses it as the OIDC identity token for workload identity federation when no config file gives one. | Text. Used with ANTHROPIC_ and ANTHROPIC_. Also in a list of secret-like env names | Bundled SDK federation sign-in. Not set from project env before trust |
ANTHROPIC_ | Documented | The bundled SDK reads the OIDC identity token from this file path for workload identity federation. | Text. Becomes identity_ with source file. Used when the org ID and rule ID are set and no config file exists | Bundled SDK federation sign-in. Not set from project env before trust |
ANTHROPIC_ | Documented | Organization ID for workload identity federation. Set it with ANTHROPIC_. | Text. Together they form the env- federation identity. The SDK also reads it as a fallback | All sessions. Not set from project env before trust |
ANTHROPIC_ | Documented | Names the Anthropic profile to sign in with. | Text, profile by default. An explicit value makes the profile mode profile- | All sessions. Not set from project env before trust |
ANTHROPIC_ | Undocumented | The bundled SDK sends it as the OAuth scope in workload identity federation. A config file value wins. | Text. Fills authentication. when the config does not set it | Bundled SDK federation sign-in. Not set from project env before trust |
ANTHROPIC_ | Undocumented | The bundled SDK uses it as service_ in workload identity federation. | Text. Fills authentication. when the config does not set it | Bundled SDK federation sign-in. Not set from project env before trust |
ANTHROPIC_ | Documented | Workspace ID for workload identity federation. It is optional in the env- identity. | Text. The SDK also reads it as a fallback | All sessions. Not set from project env before trust |
AWS_ | Documented | Amazon Bedrock API key. Claude Code sends it as a Bearer token and skips the AWS credential chain. | Text. Used for Bedrock and Mantle clients | Providers bedrock and mantle. Not set from project env before trust |
CLAUDE_ | Undocumented | Points to a JSON file with a gateway token or access token for a background session. | Text. Claude Code reads the file once, deletes the file, and removes the var. Retries if the file is busy | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Carries the claim token for a spare background session. | Text. A tokens file can replace it | Spare background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Passes the rate limit tier of the dispatcher account to a background session. | Text. Used only when CLAUDE_ is bg. The dispatcher sets it | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Passes the subscription type of the dispatcher account to a background session. | Text. Used only when CLAUDE_ is bg. The dispatcher sets it | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Holds the shared secret for the PTY link of a background session. | Text. Claude Code generates and sets it. It is removed from child env in exec mode | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Holds the shared secret for the rendezvous socket of a background session. | Text. Claude Code sets it. The session reads it once and deletes it | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Points to a tokens file with the rendezvous and claim secrets for a background session. | Text. Claude Code reads the file once, deletes the file, and removes the var | Background sessions. Not set from project env before trust |
CLAUDE_ | Documented | Gives the account UUID when the host supplies the account. It fills account info and telemetry ids. | Text. With CLAUDE_ and CLAUDE_ it builds the account record in some host modes | Host-managed and SDK sessions. Not set from project env before trust |
CLAUDE_ | Undocumented | Names a file descriptor from which Claude Code reads the API key at startup. | A number. A reader function runs at startup when it is set. The debug auth dump shows if it is set | SDK and host launches. Not set from project env before trust |
CLAUDE_ | Documented | Sets how often Claude Code refreshes credentials from api. | A number of milliseconds, stays by default. Whole number of 0 or more. A negative value logs an error and the built-in default stays | All sessions with api. Project env can set it before trust |
CLAUDE_ | Undocumented | Gives a bearer token for requests to the artifacts frame host. | Text. Sent as Authorization: plus the value, only when the frame host mode is active | Artifacts frame requests. Not set from project env before trust |
CLAUDE_ | Undocumented | Makes a remote child session exit when an OAuth 401 stays unrecovered for this long. The runner then restarts it with fresh credentials. | A number of milliseconds, 600000 by default. Whole number, minimum 0. A value of 0 turns the exit off | Remote child sessions |
CLAUDE_ | Undocumented | Replaces the OAuth base URL and endpoints with a custom host. Throws if the URL is not on the approved endpoint list. | Text. A trailing slash is removed. Only fedstart style hosts pass the check | All sessions, first-party auth |
CLAUDE_ | Undocumented | Sets the OAuth client id for Claude Design login. A build without a registered client shows an error that asks for this variable. | Text. A value starting with 00000000- counts as unset | Claude Design login |
CLAUDE_ | Documented | Makes each process run gcp or aws itself without the cross-process lock. | On or off. Code gates the auth refresh lock on its negation | Bedrock and Vertex with auth refresh |
CLAUDE_ | Undocumented | Turns on the proxy setting so a helper command can mint proxy auth headers. | On or off, off by default. Cache TTL comes from CLAUDE_, default 300000 | Proxy setups |
CLAUDE_ | Undocumented | Turns on XAA for MCP OAuth and unlocks the xaa setting. | On or off, off by default. Without it, MCP OAuth with oauth. fails with XAA is not enabled | MCP OAuth |
CLAUDE_ | Undocumented | Sets the directory for the workload identity federation token cache. | Text. Default is a credentials/ folder in the config dir | Federated auth, eval harness copies it |
CLAUDE_ | Undocumented Gated | Forces the Windows Credential Manager path on when set to 1. | Text. Else the cached a feature flag decides | Windows |
CLAUDE_ | Undocumented | Reads the gateway token from this open file descriptor, then removes the var from the env. | A number. Ignored with CLAUDE_ or an IPC channel | Hosts that spawn Claude Code |
CLAUDE_ | Undocumented | Names the env var that holds the credential a host app supplies. Its presence counts as host-managed auth. | Text. Reserved names are skipped. Removed from some child envs | Host apps that embed Claude Code |
CLAUDE_ | Undocumented | Passes a timeout to the request that asks the SDK host to refresh the auth token. | A number of milliseconds. Used only when CLAUDE_ is set. An invalid value means no timeout | SDK host, stream-json print mode |
CLAUDE_ | Undocumented | Names a credentials file that a host app owns. Claude Code tests paths against it and adds it to a path list built with the sandbox rules. | Text. Also turns on the gateway lineage check together with CLAUDE_. Its name is kept from children | Host apps with a gateway |
CLAUDE_ | Undocumented | Marks a session as gateway-managed by the host. It counts only when CLAUDE_ is also set. | On or off. Claude Code sets it to 1 for child processes when its lineage check passes. It is removed in other child envs | Host apps with a gateway, set by Claude Code |
CLAUDE_ | Undocumented | Overrides the OAuth client id for login and for refresh-token login. | Text. When set it also clears the registered plugin and project scope flags | All sessions, OAuth |
CLAUDE_ | Documented | Lets claude auth login exchange a refresh token with no browser. Needs CLAUDE_. | Text. Startup stops with an error when the scopes are missing. A used token cannot be reused | claude auth login |
CLAUDE_ | Documented | Gives the scopes that the refresh token was issued with. It also sets the scopes of CLAUDE_. | Text, scope by default. Docs mention only the refresh token use | All sessions, OAuth |
CLAUDE_ | Documented | Gives an OAuth access token for claude.ai auth that wins over stored login. | Text. Counts as an auth source. Dropped from shell child envs | All sessions, SDK and automation |
CLAUDE_ | Undocumented | Counts as an OAuth token source like CLAUDE_. The code shown only tests that it is set. | Text. Remote sessions print set or unset for it in an error message | All sessions, remote sessions |
CLAUDE_ | Undocumented | Sets the organization UUID. Sent as X- with a sk- session key and used as the org ID before the OAuth profile lookup. | Text. With CLAUDE_ and CLAUDE_ it builds the oauth. A self-hosted runner passes it to sessions | All sessions, mostly cloud and runner sessions |
CLAUDE_ | Undocumented | Sets the time-to-live of the proxy auth helper result. The helper itself needs CLAUDE_. | A number of milliseconds, constant by default. Whole number in ms of 0 or more. Negative or unset gives an internal default constant | All sessions, when the proxy auth helper is on |
CLAUDE_ | Undocumented | Gives the rate limit tier for a token from CLAUDE_. | Text. Set by Claude Code from a background auth snapshot. Used with CLAUDE_ | Sessions using an env OAuth token |
CLAUDE_ | Undocumented | Tells Claude Code that the SDK host can refresh host auth tokens. Claude Code then asks the host for a new token when needed. | Set by Claude Code in the SDK child env to 1 when the host supports it. The wait uses CLAUDE_ | SDK and print mode. Set by Claude Code |
CLAUDE_ | Undocumented | Tells Claude Code that the SDK host can refresh the OAuth token. Claude Code then requests a refresh from the host. | Set by Claude Code in the SDK child env to 1 when the host supports it. It takes effect only for some entrypoints | SDK and print mode. Set by Claude Code |
CLAUDE_ | Documented | Holds the session access token for remote sessions. It is sent as Authorization:, or as a cookie when it starts with sk-. | Text. Falls back to the token file | Remote and ingress sessions. Set by Claude Code on refresh |
CLAUDE_ | Undocumented | Gives the subscription type for a token supplied through CLAUDE_. Claude Code also sets it from a background auth snapshot. | Text. It is used with CLAUDE_ | OAuth token auth and background sessions |
CLAUDE_ | Undocumented | Supplies the account email when a host passes the account by env. It is also used as user. in telemetry and in the user context. | Text. Account use needs CLAUDE_ and CLAUDE_ too | SDK hosts and remote runs |
CLAUDE_ | Undocumented | Names a file descriptor that holds the WebSocket session token. Claude Code reads the token at startup. | Text. Read next to the API key and gateway descriptor reads | Remote and SDK URL sessions |
CLAUDE_ | Undocumented | Sets the API base URL in the local OAuth config. | Text, http by default. Trailing slash removed | Local OAuth config |
CLAUDE_ | Undocumented | Sets the claude.ai origin and authorize URL in the local OAuth config. | Text, http by default. Trailing slash removed | Local OAuth config |
CLAUDE_ | Undocumented | Sets the console authorize URL in the local OAuth config. | Text, http by default. Trailing slash removed | Local OAuth config |
CLAUDE_ | Undocumented | Overrides the config directory that names the secure-storage credentials entry. | A path | - |
CLAUDE_ | Documented | Sets the path of the file that holds the session ingress token. A set value also makes the entrypoint remote. | A path | - |
CLAUDE_ | Undocumented | Supplies the trusted device token. It wins over the stored token and stops trusted-device enrollment. | Text (a secret) | - |
DISABLE_ | Documented | Hides the / command. | On or off | - |
DISABLE_ | Documented | Hides the / command. | On or off | - |
GH_ | Documented | Token for a GitHub Enterprise host. Used when GH_ names that host. Claude Code blanks it when it runs gh. | Text. The scrub list was not checked | GitHub features. Not set from project env before trust |
GH_ | Documented | Token for github.com. Claude Code uses it first for GitHub API calls and blanks it when it runs gh. | Text. The scrub list was not checked | GitHub features. Not set from project env before trust |
GITHUB_ | Documented | Second name for the GitHub Enterprise token, after GH_. Claude Code blanks it when it runs gh. | Text. The scrub list was not checked | GitHub features. Not set from project env before trust |
GITHUB_ | Documented | Second name for the github.com token, after GH_. Claude Code blanks it when it runs gh. | Text. The scrub list was not checked | GitHub features. Not set from project env before trust |
MCP_ | Documented | Gives the OAuth client secret for MCP servers with pre-set credentials, without a prompt. | Text (a secret) | - |
MCP_ | Documented | Fixes the port of the MCP OAuth redirect callback. | A number | - |
MCP_ | Undocumented | Overrides the OAuth client metadata document URL that MCP OAuth uses. | A URL | - |
MCP_ | Undocumented | Gives the identity provider client secret for the MCP cross-app access (XAA) setup command. | Text (a secret) | - |
USE_ | Undocumented | Points OAuth and bridge URLs at a local server. It switches the bridge to ws:// and trusts localhost hosts. | On or off. Used in a dev OAuth and bridge setup. Not for normal use | All sessions, development only |
USE_ | Undocumented | Points OAuth and bridge URLs at staging. The bridge uses wss://. | On or off. Claude Code sets it to 1 for remote sessions when the api_ contains staging | All sessions, set by Claude Code for staging cloud |
How It Works
When several credentials exist, Claude Code uses the first one in its own order.
The official docs list the order on the Authentication page.
ANTHROPIC_API_KEY takes precedence over a profile sign-in.
Some variables on this page are set by Claude Code for remote sessions and refreshed by it. Do not set those by hand.
Related Pages
- Environment Variables: how Claude Code reads variables and which value wins.
- Settings: Auth Keys
- Undocumented Items: every item that only the program shows.
Source: the program (variable names found in the 2.1.304 binary) and the Environment Variables page of the official docs.