On this page

Set variables in the process that starts the agent. A change in another terminal does not update a running process. Prefer account management for credentials and models.json for new model connections.

Never put tokens in prompts, issue reports, example JSON, or commands saved in shell history. Endpoint overrides can send credentials and conversation data to another server; use only endpoints you operate or trust.

Credential inputs

VariablePurpose
CODEX_ACCESS_TOKENExternal OpenAI coding bearer token; does not supply a refresh token
CODEX_ACCOUNT_IDExplicit account identity accompanying that token
CODEX_ID_TOKENAlternative identity information used to derive account identity
CODEX_AUTH_JSONSerialized external OpenAI authentication record; prefer importing an existing valid login rather than manufacturing OAuth fields
CODEX_HOMEDirectory containing auth.json; default ~/.codex
OPENAI_OAUTH_CLIENT_IDOverride the OAuth application client ID; normally leave unset and use the shipped application
GROK_AUTH_JSONExternal Grok OAuth record; when valid, preferred over GROK_ACCESS_TOKEN for the environment source
GROK_ACCESS_TOKENExternal Grok bearer token without a refresh grant
XAI_OAUTH_CLIENT_IDOverride xAI OAuth application client ID; normally leave unset
OPENROUTER_API_KEYExternal API-billed OpenRouter credential
GOOGLE_API_KEYExternal Gemini API credential; preferred over GEMINI_API_KEY
GEMINI_API_KEYAlternative external Gemini API credential
MODEL_API_KEYSecret named by the shipped direct Meta model connection
OPENAI_API_KEYDirect auxiliary OpenAI authentication such as dictation; exporting this alone is not the coding-account selector

Enabled managed credentials can take precedence over environment sources. OpenAI combines eligible managed and external accounts and suppresses duplicate account identities; this is not a simple last-variable-wins rule. See provider authentication and billing.

Direct-provider transport overrides

These variables change existing provider clients, not the model catalog. Nonempty string overrides are accepted as supplied. Integer timeout strings must parse completely; invalid or empty values fall back to the client's default. Use positive timeouts rather than relying on transport-specific behavior of zero or negative values. The default is 600 seconds for the clients below.

VariableDefault / interpretation
OPENROUTER_BASE_URLhttps://openrouter.ai/api/v1
OPENROUTER_MODEL_MAPEmpty; comma-separated exact source=target mappings
OPENROUTER_DEFAULT_MODELopenai/gpt-5.1; fallback when the request has no usable OpenRouter slug
OPENROUTER_TIMEOUT_SECONDS600; provider request timeout
OPENROUTER_HTTP_REFERERAbsent; optional HTTP-Referer attribution header
OPENROUTER_APP_TITLEAbsent; optional X-Title attribution header
XAI_GROK_BASE_URLNative xAI API base; leave unset for normal direct access
XAI_GROK_MODEL_MAPEmpty; comma-separated exact source=target mappings
XAI_GROK_DEFAULT_MODELgrok-4.6
XAI_GROK_TIMEOUT_SECONDS600; provider request timeout
XAI_GROK_CLIENT_VERSIONShipped client identity; override only for a known compatibility requirement
GEMINI_BASE_URLDirect Gemini API endpoint; distinct from subscription Code Assist
GEMINI_CODE_ASSIST_BASE_URLhttps://cloudcode-pa.googleapis.com/v1internal
GEMINI_DEFAULT_MODELgemini-3.7-flash
GEMINI_TIMEOUT_SECONDS600; provider request timeout

Model-map entries trim whitespace around both sides and ignore malformed or empty entries. Duplicate source keys retain the final entry. For example, source-a=target-a,source-b=target-b describes two exact replacements, not wildcard rules. Do not use mapping to claim a model has another model's capabilities or context limit.

Organization-gateway xAI routing deliberately preserves advertised model names, uses the gateway's native endpoint and disables redirects. Direct xAI environment overrides do not redirect that authenticated gateway route.

OPENROUTER_TIMEOUT_SECONDS=900 agent-cli --provider openrouter

Use /session-info and a small request to verify the intended provider. Increasing a timeout does not resolve an invalid key, unknown model, incompatible endpoint or exhausted account quota. Remove the override to return to the shipped transport default.

Local helpers and browser selection

VariableBehavior
CLAUDE_CODE_EXECUTABLESelect the Claude Code executable for authentication/runtime discovery; use a trusted installed program
HASKELL_AGENT_APPLE_SESSION_TITLESelect the on-device title helper; normal discovery uses PATH or a supported local build
BROWSERSingle executable name or path, launched with the authorization URL as one argument; not a shell command with flags
XAI_STT_LANGUAGEDictation language; defaults to English, for example pt for Portuguese

Without BROWSER, browser launching tries open and then xdg-open. If you supply a browser executable and it cannot launch, correct or unset the variable; an arbitrary command string will not be interpreted by a shell. Remote/headless sessions still need a way to complete the provider's browser authorization.

Local runtime paths

These are advanced local-process coordination controls. Use the same values in processes that must observe or contact one another. Do not point them at a shared, untrusted directory; these endpoints are not a network deployment API.

VariableDefault / purpose
HASKELL_AGENT_OBSERVATION_DIRECTORY~/.haskell-agent/observation; session observation socket directory
HASKELL_AGENT_INBOX_DIRECTORY~/.haskell-agent/inbox; session inbox socket directory
HASKELL_AGENT_EXECUTABLEOverride the agent executable used for managed external process launches

Leave directory overrides unset instead of supplying an empty value. Observation and inbox services are ancillary; failing to create their endpoint can leave execution running without that coordination facility. Check the chosen directory and its permissions rather than repeatedly starting duplicate agents.

MCP entry environment is separate

MCP_ACCESS_TOKEN and MCP_OAUTH_TOKEN_FILE are read from a server entry's env map. They are not interchangeable with a provider API key. Use the MCP authentication reference for managed OAuth and legacy token-file behavior.