Requesty
Back|JUN '26INTEGRATIONS / AGENTS
4 MIN READ|

Claude Code Environment Variables: How to Set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN

Thibault Jaigu
Thibault Jaigu
CEO & Co-Founder
Published

If you have searched for how Claude Code reads its configuration, you have probably run into a wall of half answers. The official docs list the variables, but they do not always show you exactly where to put ANTHROPIC_BASE_URL, how ANTHROPIC_AUTH_TOKEN differs from ANTHROPIC_API_KEY, or what happens when you combine them.

This guide is the reference we wished existed. It covers every environment variable that controls where Claude Code sends requests and how it authenticates, with copy and paste examples for both your shell and your settings.json.


The Short Version

Claude Code is configured almost entirely through environment variables. Three of them control routing and auth:

VariableWhat it does
ANTHROPIC_BASE_URLThe API endpoint Claude Code sends every request to. Default is Anthropic.
ANTHROPIC_AUTH_TOKENThe raw Bearer token sent in the Authorization header. Use this with a custom base URL.
ANTHROPIC_API_KEYThe standard Anthropic API key, used when talking to Anthropic directly.

If you only remember one thing: change ANTHROPIC_BASE_URL to send Claude Code somewhere else, and set ANTHROPIC_AUTH_TOKEN to authenticate against that somewhere.


ANTHROPIC_BASE_URL

ANTHROPIC_BASE_URL is the single most important variable for anyone who wants Claude Code to do something other than call Anthropic directly.

By default, Claude Code uses Anthropic's production endpoint. When you set ANTHROPIC_BASE_URL, every request the CLI makes (including its agentic sub-loops and background calls) goes to the URL you provide. The CLI behavior does not change. Only the destination does.

Shell
export ANTHROPIC_BASE_URL="https://router.requesty.ai/anthropic"

This is the mechanism behind every "use Claude Code with a custom endpoint" setup: self-hosted proxies, observability layers, and LLM gateways all work by intercepting this one variable.


ANTHROPIC_AUTH_TOKEN vs ANTHROPIC_API_KEY

This is the pair that confuses most people, so it is worth being precise.

  • ANTHROPIC_API_KEY is your Anthropic key. Claude Code uses it the way you would expect when it is talking to Anthropic.
  • ANTHROPIC_AUTH_TOKEN sets the literal Bearer token in the Authorization header. When you point Claude Code at a custom ANTHROPIC_BASE_URL that issues its own keys, this is the variable you set to that key.

The rule of thumb:

If you change ANTHROPIC_BASE_URL to a gateway or proxy, set ANTHROPIC_AUTH_TOKEN to that service's key. If you are talking to Anthropic directly, use ANTHROPIC_API_KEY.

Shell
export ANTHROPIC_BASE_URL="https://router.requesty.ai/anthropic"
export ANTHROPIC_AUTH_TOKEN="your-gateway-key-here"

ANTHROPIC_MODEL and ANTHROPIC_SMALL_FAST_MODEL

Two more variables control which models Claude Code uses:

  • ANTHROPIC_MODEL sets the default model for the main agent.
  • ANTHROPIC_SMALL_FAST_MODEL sets the lightweight model used for background tasks like summarization.
Shell
export ANTHROPIC_MODEL="anthropic/claude-opus-4-8"
export ANTHROPIC_SMALL_FAST_MODEL="anthropic/claude-haiku-4-5"

When Claude Code points at Anthropic directly, these must be Anthropic model ids. When it points at a gateway, they can be any model id the gateway supports, which is how teams run GPT-5.5 or Gemini 3.5 Flash inside the Claude CLI.


Where to Set Them: Shell vs settings.json

You have two good options, and they serve different purposes.

Option 1: Your shell profile

Best for a quick, machine-wide default. Add the exports to ~/.zshrc (or ~/.bashrc) and reload:

Shell
echo 'export ANTHROPIC_BASE_URL="https://router.requesty.ai/anthropic"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="your-gateway-key-here"' >> ~/.zshrc
source ~/.zshrc

The most portable option is the env block in your Claude Code settings file. Global config lives at ~/.claude/settings.json; per project config lives at .claude/settings.json inside the repository.

JSON
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://router.requesty.ai/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "your-gateway-key-here",
    "ANTHROPIC_MODEL": "anthropic/claude-opus-4-8",
    "ANTHROPIC_SMALL_FAST_MODEL": "anthropic/claude-haiku-4-5"
  }
}

Values in settings.json travel with your config and override the defaults, which makes them easier to share across a team than shell exports that live only on one machine.


A Complete Working Example

Here is a full, copy and paste configuration that points Claude Code at a gateway, authenticates against it, and sets both models:

Shell
# ~/.zshrc or ~/.bashrc
export ANTHROPIC_BASE_URL="https://router.requesty.ai/anthropic"
export ANTHROPIC_AUTH_TOKEN="your-gateway-key-here"
export ANTHROPIC_MODEL="anthropic/claude-opus-4-8"
export ANTHROPIC_SMALL_FAST_MODEL="anthropic/claude-haiku-4-5"

Reload your shell, run claude, and every request now flows through the endpoint you set.


Why Route Claude Code Through a Gateway?

Setting ANTHROPIC_BASE_URL is the easy part. The reason most teams do it is what they get on the other side.

Claude Code runs continuous agentic loops over codebase-scale context, which means it burns tokens fast. Pointed directly at Anthropic, that leads to two predictable problems: 429 rate limit errors during long sessions, and bills that are hard to attribute across a team.

Requesty is an LLM gateway that you drop in front of Claude Code by setting exactly the variables above. Once traffic flows through it, you get:

  • No more hard rate limit walls. Requesty spreads load and fails over across providers, so a single provider's 429 does not stop your session. See our guide on bypassing Claude rate limits.
  • Any model inside the Claude CLI. Set ANTHROPIC_MODEL to GPT-5.5, Gemini 3.5 Flash, or any of 300+ models. Requesty handles the protocol translation.
  • Unified analytics and cost tracking. Every Claude Code request shows up with token counts, latency, and cost, attributable per key.
  • Spend controls and guardrails. Per key budget caps and built in guardrails apply automatically.

The full walkthrough is in Supercharging Claude Code with Requesty.


Quick Reference

VariablePurposeTypical value
ANTHROPIC_BASE_URLEndpoint for all requestshttps://router.requesty.ai/anthropic
ANTHROPIC_AUTH_TOKENBearer token for a custom endpointYour gateway key
ANTHROPIC_API_KEYKey for talking to Anthropic directlyYour Anthropic key
ANTHROPIC_MODELDefault main modelanthropic/claude-opus-4-8
ANTHROPIC_SMALL_FAST_MODELBackground modelanthropic/claude-haiku-4-5

Set them in your shell for a quick default, or in settings.json for a portable, shareable config. Either way, the moment you change ANTHROPIC_BASE_URL, Claude Code is yours to route.

Frequently asked questions

What is ANTHROPIC_BASE_URL in Claude Code?
ANTHROPIC_BASE_URL tells Claude Code which API endpoint to send requests to. By default Claude Code talks to Anthropic directly. Setting ANTHROPIC_BASE_URL to a different endpoint, such as an LLM gateway, routes all Claude Code traffic through that endpoint instead, without changing anything else in the CLI.
What is the difference between ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY?
ANTHROPIC_API_KEY is the standard Anthropic key Claude Code uses when talking to Anthropic directly. ANTHROPIC_AUTH_TOKEN sets the raw Bearer token sent in the Authorization header, which is what you use when pointing Claude Code at a custom endpoint or gateway that issues its own keys. When you set a custom ANTHROPIC_BASE_URL, you typically set ANTHROPIC_AUTH_TOKEN to the gateway key.
Where do I put Claude Code environment variables permanently?
You can export them in your shell profile (.zshrc or .bashrc) so they apply to every session, or add them to the env block of your settings.json (~/.claude/settings.json for global, or .claude/settings.json inside a project). The settings.json env block is the most portable option because it travels with your config rather than your shell.
How do I point Claude Code at a different model?
Set ANTHROPIC_MODEL to the model identifier you want as the default, and ANTHROPIC_SMALL_FAST_MODEL for the lightweight background model. When you route through a gateway these can be any supported model id, not only Anthropic ones.
Related reading