How it works
This uses proxy mode. Claude Code keeps authenticating to Anthropic with its own credentials — those flow through Relay untouched in theAuthorization header. Relay identifies the traffic by your relay
key, sent in X-WR-API-Key, and forwards the request verbatim to Anthropic.
Claude Code keeps its own Anthropic credential; Relay observes and forwards.
ANTHROPIC_API_KEY) is unchanged — Relay only adds observability.
Prerequisites
-
Proxy mode enabled on your relay:
-
A relay key whose policy grants the Claude models Claude Code uses
(Sonnet, Opus, Haiku). In authenticated proxy mode without an explicit
host header, Relay reads the
modelfrom the request and resolves the upstream host from this key’s policy — so the models must be granted. - (Optional) Payload logging turned on, if you want to capture the full request/response bodies — see Usage & Logging.
Setup
Set three things via environment variables: the relay’s Anthropic base URL, and two custom headers (X-WR-API-Key and X-WR-Proxy-Mode). Claude Code’s
own login stays as-is and flows through as the upstream credential.
Option A — a wrapper command
Drop a small script on yourPATH (e.g. wcc) so you opt in per-invocation:
wcc instead of claude when you want the session tracked; plain claude
stays direct.
Option B — Claude Code settings
To route every session, set the same values underenv in
~/.claude/settings.json (or a project-level .claude/settings.json):
ANTHROPIC_BASE_URL is host + the /anthropic prefix; Claude Code appends
/v1/messages itself. ANTHROPIC_CUSTOM_HEADERS is newline-separated
Name: Value pairs.What you get
Once a session runs through Relay:- Usage — every Claude Code request appears in
GET /logsand the/usage/*endpoints, attributed to your relay key, with token counts and timing. Great for seeing what Claude Code actually costs. - Payloads — with payload logging enabled, the full prompts and
completions are captured and readable at
GET /logs/{request_id}— exactly what Claude Code sent and what the model returned.
Notes
- Setting
ANTHROPIC_BASE_URLdisables Claude Code’s MCP tool search by default; re-enable it withENABLE_TOOL_SEARCH=trueif you use it. - Proxy mode does no translation — Claude Code’s native Anthropic requests are forwarded byte-for-byte.