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 79 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: An official docs page names this item. | 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: An official docs page names this item. | Sets the Authorization header to Bearer plus the value. It also counts as a credential for gateway model discovery. | Text. Claude Code reads it on each access | All sessions. Not set from project env before trust |
ANTHROPIC_ | Documented: An official docs page names this item. | Sets the workspace API key for Claude Platform on AWS. When it is set, Claude Code skips the AWS credential chain for that client. | Text. The 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: An official docs page names this item. | Sets the directory for Anthropic profile files. Claude Code reads configs and credentials files from it. | Text. Wins over XDG_. Claude Code does not use it when a helper returns null for the current mode | Profile and federation sign-in, all. Not set from project env before trust |
ANTHROPIC_ | Documented: An official docs page names this item. | Gives the 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: An official docs page names this item. | Gives the 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: An official docs page names this item. | Gives the 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: An official docs page names this item. | 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_. The name is also in a list of secret-like env names | Bundled SDK federation sign-in. Not set from project env before trust |
ANTHROPIC_ | Documented: An official docs page names this item. | The bundled SDK reads the OIDC identity token from this file path for workload identity federation. | Text. It becomes identity_ with source file. The SDK uses it 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: An official docs page names this item. | Gives the 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: An official docs page names this item. | 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: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | 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: An official docs page names this item. | Gives the 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: An official docs page names this item. | Gives the 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: Only the program shows this item. It can change without notice. | Points to a JSON file with a gateway token or access token for a background session. | Text. Claude Code reads the file once. Then it deletes the file. Then it removes the var. It retries if the file is busy | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | Holds the shared secret for the PTY link of a background session. | Text. Claude Code generates and sets it. In exec mode, Claude Code removes it from the child env | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Holds the shared secret for the rendezvous socket of a background session. | Text. Claude Code sets it. The session reads it once. Then it deletes it | Background sessions. Not set from project env before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Points to a tokens file with the rendezvous and claim secrets for a background session. | Text. Claude Code reads the file once. Then it deletes the file. Then it removes the var | Background sessions. Not set from project env before trust |
CLAUDE_ | Documented: An official docs page names this item. | 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: Only the program shows this item. It can change without notice. | 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: An official docs page names this item. | 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. The built-in default then stays | All sessions with api. Project env can set it before trust |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Gives a bearer token for requests to the artifacts frame host. | Text. Claude Code sends it 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: Only the program shows this item. It can change without notice. | Names the claude.ai Project that the usage reports of this session are tied to. At startup Claude Code shows a notice with the Project, and a bad value gives a warning. | Text. A Project UUID or a claude_ ID. Any other value is ignored with a warning. The attribution key of a settings file and an organization default are other sources | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | Replaces the OAuth base URL and endpoints with a custom host. Throws if the URL is not on the approved endpoint list. | Text. Claude Code removes a trailing slash. Only fedstart style hosts pass the check | All sessions, first-party auth |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: An official docs page names this item. | 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: Only the program shows this item. It can change without notice. | Turns off the sign-in that a host app, such as the desktop app, hands to Claude Code. | On or off. Off by default. Since 2. | Host apps. The env of managed settings can set it |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Turns XAA on when set to 1 | 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. 1 turns it on. See MCP Authentication | MCP OAuth |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. A feature flag or server gate decides by default. This variable overrides it | Forces the Windows Credential Manager path on when set to 1. | Text. Else the cached a feature flag decides | Windows |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Reads the gateway token from this open file descriptor. Then it removes the var from the env. | A number. Claude Code ignores it with CLAUDE_ or an IPC channel | Hosts that spawn Claude Code |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Names the env var that holds the credential a host app supplies. Its presence counts as host-managed auth. | Text. Claude Code skips reserved names. It removes the variable from some child envs | Host apps that embed Claude Code |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | Names a credentials file that a host app owns. Claude Code tests paths against it. It also 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: Only the program shows this item. It can change without notice. | 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. Claude Code removes it in other child envs | Host apps with a gateway, set by Claude Code |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets a wait in ms for OAuth 401 recovery. Where the wait is used was not traced. | A number of milliseconds. Default 0, or a built-in value in a session with CLAUDE_ | All sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: An official docs page names this item. | 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: An official docs page names this item. | 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: An official docs page names this item. | Gives an OAuth access token for claude.ai auth that wins over stored login. | Text. Counts as an auth source. Claude Code drops it from shell child envs | All sessions, SDK and automation |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | Sets the organization UUID. Claude Code sends it as X- with a sk- session key. It also uses it 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: Only the program shows this item. It can change without notice. | 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: Only the program shows this item. It can change without notice. | Claude Code sets it in the environment of the proxy auth helper command. It holds the challenge of the proxy. Claude Code sets it only when there is one. | Text. Claude Code sets it for the helper. The helper itself needs CLAUDE_ | Proxy auth helper only. Also set for SELF_ |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Claude Code sets it in the environment of the proxy auth helper command. It holds the host name of the proxy. | Text. Claude Code sets it for the helper, when the proxy URL has a host | Proxy auth helper only. Also set for SELF_ |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Claude Code sets it in the environment of the proxy auth helper command. It holds the URL of the proxy. | Text. Claude Code sets it for the helper, when a proxy URL is known | Proxy auth helper only. Also set for SELF_ |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Gives the rate limit tier for a token from CLAUDE_. | Text. Claude Code sets it from a background auth snapshot. Used with CLAUDE_ | Sessions using an env OAuth token |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Tells Claude Code that the SDK host can refresh host auth tokens. Claude Code then asks the host for a new token when needed. | Claude Code sets it to 1 in the SDK child env when the host supports it. The wait uses CLAUDE_ | SDK and print mode. Claude Code sets it |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Tells Claude Code that the SDK host can refresh the OAuth token. Claude Code then requests a refresh from the host. | Claude Code sets it to 1 in the SDK child env when the host supports it. It takes effect only for some entrypoints | SDK and print mode. Claude Code sets it |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Tells Claude Code that the SDK host can hand it a second token for the cloud sessions API when asked. Added in 2.. | On or off. It takes effect only with CLAUDE_ and a supported entrypoint | SDK and print mode. Set by the SDK host |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Holds a second token that authorizes the cloud sessions API. The host can set it while the process runs, with an update_ message. Added in 2.. | Text. The message accepts only CLAUDE_, CLAUDE_, and this name. Claude Code drops it from the variables it copies to a new cloud session. A value that fails its check is refused | SDK and print mode. Set by a host |
CLAUDE_ | Documented: An official docs page names this item. | Holds the session access token for remote sessions. Claude Code sends it as Authorization:, or as a cookie when it starts with sk-. | Text. Falls back to the token file | Remote and ingress sessions. Claude Code sets it on refresh |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Gives the subscription type for a token supplied through CLAUDE_. Claude Code also sets it from a background auth snapshot. | Text. Claude Code uses it with CLAUDE_ | OAuth token auth and background sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Supplies the account email when a host passes the account by env. Claude Code also uses it as user. in telemetry and in the user context. | Text. Account use needs CLAUDE_ and CLAUDE_ too | SDK hosts and remote runs |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Names a file descriptor that holds the WebSocket session token. Claude Code reads the token at startup. | Text. Claude Code reads it next to the API key and gateway descriptor reads | Remote and SDK URL sessions |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the API base URL in the local OAuth config. | Text, http by default. Claude Code removes a trailing slash | Local OAuth config |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the claude.ai origin and authorize URL in the local OAuth config. | Text, http by default. Claude Code removes a trailing slash | Local OAuth config |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Sets the console authorize URL in the local OAuth config. | Text, http by default. Claude Code removes a trailing slash | Local OAuth config |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Overrides the config directory that names the secure-storage credentials entry. | A path | - |
CLAUDE_ | Documented: An official docs page names this item. | Sets the path of the file that holds the session ingress token. A set value also makes the entrypoint remote. | A path | - |
CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Supplies the trusted device token. It wins over the stored token and stops trusted-device enrollment. | Text (a secret) | - |
DISABLE_ | Documented: An official docs page names this item. | Hides the / command. | On or off | - |
DISABLE_ | Documented: An official docs page names this item. | Hides the / command. | On or off | - |
GH_ | Documented: An official docs page names this item. | Gives the token for a GitHub Enterprise host. Claude Code uses it when GH_ names that host. Claude Code sets it to an empty value for gh auth token and removes it for the gh repo check. The cloud gh shim leaves it alone and runs the real gh. | Text. The program exempts it from the name match of CLAUDE_. A run with the scrub on still showed it in a Bash child. Hooks and stdio MCP servers were not run | GitHub features. Not set from project env before trust |
GH_ | Documented: An official docs page names this item. | Gives the token for github.com. Claude Code uses it first for GitHub API calls. Claude Code sets it to an empty value when it runs gh auth token to read your stored gh login. Claude Code removes it for the gh repo check when GH_ names another host. In cloud sessions a gh shim replaces it with the text proxy- unless you set a real token. | Text. The program exempts it from the name match of CLAUDE_. A run with the scrub on still showed it in a Bash child. Hooks and stdio MCP servers were not run | GitHub features. Not set from project env before trust |
GITHUB_ | Documented: An official docs page names this item. | Second name for the GitHub Enterprise token, after GH_. Handled the same way. | Text. The program exempts it from the name match of CLAUDE_. A run with the scrub on still showed it in a Bash child. Hooks and stdio MCP servers were not run | GitHub features. Not set from project env before trust |
GITHUB_ | Documented: An official docs page names this item. | Second name for the github.com token, after GH_. Handled the same way. | Text. The program exempts it from the name match of CLAUDE_. A run with the scrub on still showed it in a Bash child. Hooks and stdio MCP servers were not run | GitHub features. Not set from project env before trust |
MCP_ | Documented: An official docs page names this item. | Gives the OAuth client secret for MCP servers with pre-set credentials, without a prompt. | Text (a secret). Skips the prompt of -- | - |
MCP_ | Documented: An official docs page names this item. | Fixes the port of the MCP OAuth redirect callback. | A number. Same as -- | - |
MCP_ | Undocumented: Only the program shows this item. It can change without notice. | Overrides the OAuth client metadata document URL that MCP OAuth uses. | A URL | - |
MCP_ | Undocumented: Only the program shows this item. It can change without notice. Gated: Works only behind a flag or a server gate. Needs CLAUDE_CODE_ENABLE_XAA | Gives the identity provider client secret for the MCP cross-app access (XAA) setup command. | Text (a secret). Read by claude mcp xaa setup -- | - |
USE_ | Undocumented: Only the program shows this item. It can change without notice. | Points OAuth and bridge URLs at a local server. It switches the bridge to ws:// and trusts localhost hosts. | On or off. A dev OAuth and bridge setup uses it. Do not use it for normal work | All sessions, development only |
USE_ | Undocumented: Only the program shows this item. It can change without notice. | 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.
Claude Code sets some variables on this page for remote sessions and refreshes them. 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.312 binary) and the Environment Variables page of the official docs.