Setup · 5 min read ·

Claude Code Environment Variables: A Beginner-Friendly Setup Guide

Claude Code Environment Variables: A Beginner-Friendly Setup Guide

You copied a configuration command, launched Claude Code and got the same behavior as before. Usually the missing detail is where that configuration lives. An environment variable belongs to a process and the programs it launches; it is not a universal setting for your whole computer. Here is how to configure one terminal, verify it safely and only then make the setup persistent.

Think of configuration as a note handed to the program

Imagine opening two terminal windows. You tell the first one which API endpoint to use. Unless you also configure the second, launching Claude Code there may use something different. This simple distinction explains many reports of a setup that works once and then mysteriously stops.

There are several places to record configuration: the current shell, a shell startup file, or Claude Code's own settings. Start with the current shell because it gives you a small, reversible experiment. Keep a note of the values you intend to use so you can compare them with what the application actually receives.

Choose the three values deliberately

For an API-key setup, the key identifies your access, the base URL chooses the service, and a model selection chooses what that service should run. Obtain those values from the same provider's instructions. An endpoint and a key from unrelated providers are not a working pair.

Claude Code documents ANTHROPIC_API_KEY for API-key authentication, ANTHROPIC_AUTH_TOKEN for a bearer value, and ANTHROPIC_BASE_URL for a gateway endpoint. Pick the authentication method your provider requests; do not populate every similarly named variable in the hope that one wins. The environment variable reference explains the supported meanings.

A model name is also part of the contract. A gateway may expose a specific identifier or mapping. Save its documented name with your configuration notes rather than assuming an alias from another service resolves the same way.

Bash and WSL: set values before launching the client

The following example applies to Bash, including a Bash shell inside WSL. The endpoint and key are placeholders. Replace the endpoint with the provider's documented API root. Use the hidden prompt to enter the key so its literal value does not become part of a shell command in your history.

Run Claude Code from that same shell after exporting the values. If you have an existing bearer-token configuration, inspect why it exists before choosing a different authentication method. On a managed machine, coordinate changes to shared routing with the person who maintains it.

export ANTHROPIC_BASE_URL="https://api.example.com"
read -r -s -p 'API key: ' ANTHROPIC_API_KEY
printf '\n'
export ANTHROPIC_API_KEY
claude

PowerShell uses a different assignment syntax

In PowerShell, use the env: namespace. Bash's export command is not the equivalent command in this shell. The short example below uses a visibly fake key to show the syntax; use your local secret-loading mechanism for a real credential.

The variable belongs to the PowerShell process, and programs launched from it inherit the environment. An already running editor or terminal does not automatically become a child of this newly configured shell. Microsoft explains the scopes in PowerShell environment variables.

$env:ANTHROPIC_BASE_URL = "https://api.example.com"
$env:ANTHROPIC_API_KEY = "REPLACE_WITH_YOUR_KEY"
claude

Check presence without printing the secret

For troubleshooting, you normally need to know whether a key is present, not what the key is. Avoid dumping your entire environment into a support ticket. Environment output can include credentials for unrelated services as well as the coding API.

In Bash, check the endpoint and the presence of the key with the first example. In PowerShell, the second example gives the same kind of evidence. Neither proves that the server accepts the credential; they establish what this shell is prepared to pass to the next process.

# Bash
printf 'Endpoint: %s\n' "${ANTHROPIC_BASE_URL:-unset}"
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
  printf 'API key: present\n'
else
  printf 'API key: missing\n'
fi

# PowerShell, in a separate PowerShell terminal
$env:ANTHROPIC_BASE_URL
[bool]$env:ANTHROPIC_API_KEY

If the application still behaves differently

Check the executable and shell you are actually using. On a Windows machine, a command launched in PowerShell and one launched inside Debian WSL can be different installations with different configuration files. Document the successful terminal first before copying the setup elsewhere.

Next inspect application settings. Claude Code supports configuration at different scopes; those settings can affect the value used by the application. Use the settings documentation to resolve the specific setting instead of applying a blanket rule that environment variables always override everything.

Restart the client after changing shell variables. A shell cannot retroactively replace the startup environment of a program you already launched. If you started the client from an editor, try the successful shell directly; that isolates editor launch configuration from API authentication.

Make a proven configuration persistent

After one small request works and you have confirmed the expected account was used, choose one place to keep the persistent configuration. Put non-secret shared defaults in a documented project setup. Store personal credentials in a local secret mechanism or private configuration appropriate to your environment.

Before committing any settings file, read its diff. A file being called 'local' does not by itself make its contents private. Check whether it is tracked and whether your ignore rules cover it. If a real key has already been committed or shared, remove it from use by revoking or rotating it; deleting the visible line does not invalidate the credential.

Write a short onboarding note with the shell type, endpoint, required authentication method and a harmless verification task. That gives another developer a repeatable procedure without distributing your key.

Undo the experiment cleanly

To undo a session-only Bash setup, unset the variables you introduced. In PowerShell remove the corresponding env: entries. If you also changed a profile or an application settings file, remove those entries separately and restart the client. Removing one source while another still sets the value explains a setting that keeps returning.

For Kintio or any other gateway, keep the same small verification task when changing routes. This makes differences visible before you launch a long editing session. Configuration success means the intended route handles the task, not merely that a variable assignment printed no error.

# Bash: remove only the values introduced by this experiment
unset ANTHROPIC_BASE_URL ANTHROPIC_API_KEY

# PowerShell equivalent
Remove-Item Env:ANTHROPIC_BASE_URL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_API_KEY -ErrorAction SilentlyContinue

Frequently asked questions

Does setting a variable change all terminal windows?

No. A session assignment affects that process and programs it launches. Persistent settings take effect according to the shell or application that reads them.

Why does it work in WSL but not PowerShell?

Those can use different executables, home directories and configuration. Repeat the presence checks in the exact shell that launches the failing client.

Should my API key go in a shared project file?

Keep shared instructions separate from credentials. A teammate needs to know how to load their own key, not receive yours in repository history.

Related guides

Keep your coding workflow moving

Kintio provides an Anthropic-compatible API for Claude Code and other developer tools. Review the fit for your workload before switching.

Explore Kintio →

Last updated: