Claude Code
Claude Code reads its base URL and auth token from environment variables, which you point at Gateway’s Anthropic-compatible endpoint. Shared setup: Building with coding agents.
Configure Claude Code
Set these in the shell where you run claude. If you signed in with Anthropic credentials before, run /logout and relaunch.
ANTHROPIC_API_KEY must be empty: any value takes precedence over ANTHROPIC_AUTH_TOKEN and bypasses Gateway. Confirm both with /status, then ask for a small code change.
ANTHROPIC_DEFAULT_*_MODEL maps the opus, sonnet, and haiku tiers to Gateway models. Unset, Claude Code sends bare Anthropic IDs such as claude-sonnet-4-6, which Gateway also accepts.
Enable routing
Set a tier to a model alias so its policy picks the model per request:
Keep ANTHROPIC_DEFAULT_HAIKU_MODEL pinned: Claude Code sends background tasks to the haiku tier, and a fixed model keeps them cheap and predictable. default_routing also works here, using the key’s project policy or the organization default.
Gotchas
- The
/modelpicker lists the full Gateway catalog, your organization’s aliases, anddefault_routing. Gateway prefixes non-Anthropic IDs withclaude-code/so the picker keeps them, then strips it. Models with a 1M-token context window carry a[1m]suffix. - The Anthropic endpoint has no
project_idbody field. Scope an organization key withANTHROPIC_CUSTOM_HEADERS="X-Project-Id: <project-uuid>", or use a project API key. - Claude Code doesn’t read
.envfiles. Persist settings per project in theenvblock of.claude/settings.local.json, or in your shell profile. - Each session is one thread in Logs; to change grouping, see tracing from coding agents
The Claude Desktop app, including its built-in Claude Code surface, ignores these variables