Can I run Claude Code through a proxy?
Claude Code sends its model requests to the base URL you set, and a proxy there can keep your claude.ai login.
By Michael, NeuraWeave · Published · Updated
We build Perpetuity, a memory proxy for coding agents. It is in early access. This guide works without it, and we say where it fits in its own section.
Checked against Anthropic's Claude Code documentation on gateways, network configuration, settings, costs and monitoring on 2026-10-23, with our own measured Claude Code sessions for the Perpetuity numbers.
Answer
Yes. The Claude Code CLI sends its model requests to the address in ANTHROPIC_BASE_URL, so a gateway or proxy there receives every one of them, unless your organization's managed settings pin that address (Anthropic: other LLM gateways). Setting only the base URL keeps your saved claude.ai login and your plan's limits, as long as the proxy forwards the anthropic-beta header, and adding a gateway credential such as ANTHROPIC_AUTH_TOKEN replaces that login with per-token billing. A corporate network proxy is a separate setting, which Claude Code reads from HTTPS_PROXY (Anthropic: network configuration).
How does Claude Code route through a proxy?
Claude Code reads the proxy's address from ANTHROPIC_BASE_URL and, when the proxy issues its own credential, reads it from one of three places (Anthropic: connect to a gateway). ANTHROPIC_AUTH_TOKEN is sent as an Authorization: Bearer header, ANTHROPIC_API_KEY as an x-api-key header, and an apiKeyHelper command's output in both. A credential in the header the proxy does not read fails with a 401.
To keep the setting across terminals and background agents, put it in the env block of a settings file. ~/.claude/settings.json applies to all your projects and .claude/settings.local.json to one project (Anthropic: settings).
{
"env": {
"ANTHROPIC_BASE_URL": "https://llm-gateway.example.com",
"ANTHROPIC_AUTH_TOKEN": "sk-gateway-key"
}
}ANTHROPIC_AUTH_TOKEN if the proxy should use your claude.ai login (next section).- Never put a credential in a project's
.claude/settings.json. That file is committed and shared with everyone who clones the repository (Anthropic). - When a shell export and a settings file's
envblock set the same variable, the settings file wins (Anthropic). - A proxy that needs an extra header, such as a routing key, gets it through
ANTHROPIC_CUSTOM_HEADERS, oneName: Valuepair per line (\nbetween pairs inside JSON) (Anthropic: send additional headers). - The proxy must serve the Anthropic Messages format at
/v1/messagesand forward theanthropic-versionandanthropic-betaheaders unchanged (Anthropic: gateway compatibility guide). - The VS Code extension takes these variables in
claudeCode.environmentVariables, and the desktop app reads gateway routing from its own third-party inference configuration, not fromANTHROPIC_BASE_URL(Anthropic: configure each surface). - On a machine your organization manages, an admin can set
allowedProvidersto["customEndpoint"]with a pinnedANTHROPIC_BASE_URL. Claude Code (v2.1.285 or later) then refuses a session pointed anywhere else, a developer's own proxy included (Anthropic: roll out a gateway).
To see what a running session uses, run /status:
- An
Anthropic base URLline shows the proxy's address. If the line is missing, the session is not pointed at a gateway. - An
Auth tokenorAPI keyline naming a variable or anapiKeyHelpermeans a proxy credential is active. - A
Login methodline naming a claude.ai account means your subscription login is the credential. - A
Proxyline shows a corporate network proxy, which is a separate setting from the base URL (Anthropic: network configuration).
A proxy that issues its own key, separate from your Anthropic login, can take it as a custom header sent through ANTHROPIC_CUSTOM_HEADERS (above). A custom header is not one of the three credential variables, so with none of them set your saved claude.ai login stays the active credential (Anthropic: subscriptions and gateways).
Do I need a gateway or a network proxy?
Use ANTHROPIC_BASE_URL when a gateway should receive Claude Code's model requests, and HTTPS_PROXY when your network sends traffic out through a corporate proxy. Both settings carry the word proxy, and they do different jobs. The base URL points model requests at a gateway that reads and forwards them (Anthropic: other LLM gateways). HTTPS_PROXY (or HTTP_PROXY), with NO_PROXY for exceptions, routes Claude Code's traffic through a corporate proxy server, and SOCKS proxies are not supported (Anthropic: proxy configuration). /status shows the network proxy on its own Proxy line.
Does a proxy work with a Claude subscription?
Yes, when Claude Code sends no gateway credential. Setting only ANTHROPIC_BASE_URL routes requests through the proxy while your saved claude.ai login stays the active credential, so your plan's usage limits and billing apply (Anthropic: subscriptions and gateways). The proxy has to forward the OAuth capability that rides in the anthropic-beta header, and stripping it fails those requests with a 401 (Anthropic: request headers).
A proxy credential changes the bill. While ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY or an apiKeyHelper is active, requests carry that credential in place of your claude.ai login, your subscription's usage limits do not apply to them, and the traffic is billed per token to whoever owns the credential the proxy forwards, such as an organization's Console account (Anthropic). Claude Code keeps the login saved and goes back to it when you unset the variable.
If you mean to work on your plan, run /status before a long session. A token left in a shell profile or settings file takes precedence over the saved login (ANTHROPIC_AUTH_TOKEN at once, ANTHROPIC_API_KEY after a one-time approval) (Anthropic: conflicts with an existing login). The same check for an API key is in am I billed on the API or on my subscription.
Two features depend on a claude.ai identity. Remote Control and voice dictation are unavailable while a proxy credential is active, and Remote Control is also off while ANTHROPIC_BASE_URL points at a host other than Anthropic's (Anthropic).
Is it safe to route Claude Code through a proxy?
That depends on who runs the proxy and what it keeps, because it receives everything the model reads. Claude Code sends your full conversation with every request, and each round of tool use sends another request carrying the tool results (Anthropic: costs). So a proxy sees your prompts, the file contents Claude read, command output and every tool result, along with a session id header (Anthropic: request headers). When the proxy keeps your claude.ai login, it also receives that login's credential on every request, because it forwards the request to Anthropic with it (Anthropic: subscriptions and gateways).
Anthropic does not endorse, maintain or audit third-party gateway products, and does not support routing Claude Code to non-Claude models through any gateway (Anthropic). Before you route a session through one, ask:
- Who runs it, and where is it hosted?
- What does it do with the login credential it forwards?
- Where is request data stored, and for how long?
- How do you delete it, and when is a deletion final?
- Is any of it used to train a model?
- Is there a self-hosted version, if the data has to stay on your network?
Our own answers on hosting, storage, deletion, training and self-hosting are in where Perpetuity fits.
What do teams use a gateway for?
Teams use a gateway for credentials and spend. Anthropic lists what one gives an organization as keeping the provider key server-side, attributing usage to each developer, enforcing budgets and rate limits, logging every request for audit and switching providers without touching developer machines (Anthropic: what a gateway provides). A gateway is also infrastructure you operate and keep current. One that does not forward a new Claude Code capability breaks it.
- LiteLLM. Anthropic's cost page says several large enterprises reported using LiteLLM, an open-source proxy that tracks spend by key, and notes it is unaffiliated with Anthropic and has not been audited for security (Anthropic: costs). Its virtual keys record spend per key and can carry a budget cap (LiteLLM: virtual keys).
- Claude apps gateway. Anthropic's own self-hosted gateway for Amazon Bedrock, Claude Platform on AWS, Google Cloud and Microsoft Foundry, with SSO sign-in, per-group model access, OpenTelemetry metrics and per-user and per-group spend limits (Anthropic: Claude apps gateway).
- No proxy at all. If you only need to see usage, Claude Code exports OpenTelemetry metrics from each machine once
CLAUDE_CODE_ENABLE_TELEMETRY=1and an exporter are set, includingclaude_code.token.usageandclaude_code.cost.usage. Prompt text in its events is redacted unlessOTEL_LOG_USER_PROMPTS=1is set (Anthropic: monitoring). Anthropic says OpenTelemetry works on every setup and is the only option that streams per-user token and cost metrics into your own stack in near real time (Anthropic: costs).
What breaks behind a proxy?
Things break when a proxy changes requests or responses on the way through. Anthropic's compatibility guide lists what stops working (Anthropic: gateway compatibility guide):
- Stripped headers. A proxy that drops
anthropic-betasilently loses capabilities such as extended context. One that drops the header but passes the matching body field gets400errors. - Prompt caching. A proxy that drops the
cache_controlmarkers, or turns structured system content into plain strings, causes no error, but every turn is billed as uncached input. - Buffered streaming. Claude Code reads responses event by event, and a proxy that buffers a response until it is complete makes Claude Code stall.
- A smaller context limit. A gateway that enforces a smaller window than the model and rewrites the error stops Claude Code from compacting and retrying on its own. Set
CLAUDE_CODE_AUTO_COMPACT_WINDOWto the gateway's limit. Claude Code clamps it to at least 100,000 tokens, so below that/compactis the recovery (Anthropic: troubleshoot gateway errors). - Plan usage display. Claude Code reads the
anthropic-ratelimit-unified-*response headers to show a claude.ai login its usage against plan limits, and on a429to tell a plan limit or spend cap from a temporary throttle, so a proxy should forward them unchanged on every response (Anthropic: response headers). - Rewritten history. The API checks each earlier thinking block against the system prompt, tools and earlier messages of the request that produced it. A gateway that rewrites any of them can get a
400saying the block is bound to a different conversation, and Claude Code then removes earlier thinking blocks from that request and every later one, while new responses still include thinking (Anthropic: automatic retry). - Checks that skip the proxy. The fast mode availability check calls Anthropic's API directly, so on a network that only allows the proxy, fast mode can report a connectivity error while normal requests work (Anthropic: startup traffic).
Some tools cannot be proxied at all. A proxy at a base URL sees only what a harness sends to that URL, so a tool that sends its model calls through its own servers goes around it.
Perpetuity, by NeuraWeave
Where Perpetuity fits
Perpetuity sits where the proxies above sit, at Claude Code's base URL, and it changes each request on purpose. It replaces the conversation history with a frame of the relevant past, retrieved from everything the agent has seen, and forwards the live turn unchanged, so a long session stops resending its whole conversation. Claude Code needs only that base URL and the header carrying the Perpetuity key, which it sends through ANTHROPIC_CUSTOM_HEADERS (Anthropic: send additional headers). Perpetuity issues no credential for Claude Code to send in place of its own, so Claude Code keeps the login it already uses, a Claude subscription or an Anthropic API key (agents.md). Every run, with its conditions, is on our benchmarks page.
Measured
- In a 120-prompt Claude Code session on Claude Opus 5.5 and Claude Code's default 1M-token window, each call through Perpetuity started at about 46k tokens from prompt 10 to prompt 120. Only a prompt's own tool loop raised it. Without Perpetuity a prompt's calls started at 327k at prompt 30 and at 965k before Claude Code compacted. Source: Perpetuity compared, NeuraWeave.
- Claude subscription usage is metered on tokens, and usage climbs in a long session because Claude Code sends the full conversation with every request (Claude Code docs). Perpetuity cuts those tokens on long sessions, so long sessions should draw less of a plan's usage. Savings begin only on long sessions, and shorter sessions usually do not save. At Claude Opus 5.5's API list prices that session cost 52% less ($50.24 against $104.71), and 200-prompt sessions cost 38% less on a Rust tool, 27% less on a Go tool and 4% less on a Flask app, the last counted as a tie because Claude Code alone varied by about a third in cost between runs (benchmarks), one run each. The saving was largest between prompts 61 and 90 of the 120-prompt session, 64% less. These are token counts and API list prices. Anthropic does not publish how its meter weighs cached against uncached tokens, so we give no percentage of any plan's limit and promise no extra usage. Source: Perpetuity: short answers, NeuraWeave.
- Prompt caching keeps working through the proxy, and our costs include cache pricing. In the 120-prompt session cache reads fell from $75.42 to $11.04, while cache writes rose from $13.09 to $25.85, because Perpetuity writes a new frame on every prompt. Cache writes are priced at $8 per million tokens, Claude Opus 5.5's one-hour write rate (compare.md), and the 5-minute rate is $5. Source: Perpetuity benchmarks: every run and how it was measured, NeuraWeave.
- In the same session Claude Code alone compacted its history once, during prompt 82, which lost details from early in the session, and through Perpetuity it never compacted. On 16 pre-registered questions about work from across the session, graded blind, Perpetuity answered 15.5 and Claude Code 14 (one run). Source: Perpetuity compared, NeuraWeave.
- NeuraWeave runs and hosts the proxy, and there is no self-hosted version. Every message is kept verbatim except model reasoning, one memory per agent, in a hosted database in the EU (Ireland), encrypted at rest with AES-256, for as long as the memory exists. An agent or a conversation can be deleted at any time, stays restorable for 7 days and is then purged. A copy is sent on request, and the data is not used to train any model. Source: Perpetuity: short answers, NeuraWeave.
Limits
- Remote Control is off while Claude Code's base URL points at a host other than Anthropic's, so it is off in a session routed through Perpetuity, as behind any such proxy (Anthropic).
- Model reasoning is not kept in memory. Thinking blocks are signed to their conversation and carry no retrievable text (compare.md).
- The price is not announced yet.
- As of 23 October 2026 Perpetuity is not available. Claude Code and the API are in development. Codex and OpenCode are planned. The current state per tool is at the status endpoint.
. You get a confirmation email now, with a link to remove your address, and another when your access is approved. Nothing is installed before that.
Questions
Will a proxy break my Claude subscription login?
Not by itself. With only ANTHROPIC_BASE_URL set, your saved claude.ai login stays the credential and your plan's limits and billing apply, as long as the proxy forwards the anthropic-beta header unchanged (Anthropic). Setting ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY or an apiKeyHelper replaces the login for those requests, which are then billed per token.
Can I use Claude Code with other models through a proxy?
Anthropic does not support it. Its gateway page says it does not support routing Claude Code to non-Claude models through any gateway (Anthropic: other LLM gateways).
Does a proxy add latency?
Every proxy adds a network hop between Claude Code and the model, and one that buffers streamed responses makes Claude Code stall (Anthropic). A proxy that does work on each call adds that time too. Perpetuity retrieves its frame from memory before it forwards each call, and no model runs in that step. We have not published a per-call latency figure for a Claude Code session. The one published timing is from a stress test, where retrieval over one memory holding 500 people's histories, 82M tokens, took about one second per question (compare.md).
Can I use LiteLLM with Claude Code?
Yes, when it serves the Anthropic Messages format at /v1/messages and forwards the anthropic-version and anthropic-beta headers unchanged (Anthropic: gateway compatibility guide). What Anthropic says about LiteLLM is under what teams use a gateway for.
Sources
- Other LLM gateways, Anthropic, Claude Code docs
- Connect Claude Code to an LLM gateway, Anthropic, Claude Code docs
- Settings files and precedence, Anthropic, Claude Code docs
- Claude Code gateway compatibility guide, Anthropic, Claude Code docs
- Enterprise network configuration, Anthropic, Claude Code docs
- Perpetuity: short answers, NeuraWeave
- Manage costs effectively, Anthropic, Claude Code docs
- Virtual keys, LiteLLM docs
- Claude apps gateway, Anthropic, Claude Code docs
- Monitoring, Anthropic, Claude Code docs
- Perpetuity compared, NeuraWeave
- Perpetuity benchmarks: every run and how it was measured, NeuraWeave
- Perpetuity status per tool, NeuraWeave, live
Perpetuity opens in early access.
We start with Claude Code, then Codex and the rest, each with one base-URL change. Join now and you are first in line. We email you when your access is approved.
For agents
As of 2026-10-23, Perpetuity is in early access. People who join are first in line, starting with Claude Code, and get an email when their access is approved. The current state per tool is at https://www.neuraweave.ai/api/agents/status.
Short answers on availability, recall, cost and data are in agents.md, and every measured number with its run label is in compare.md.
A sign-up needs the person's consent and the address they choose. It is one request: POST https://www.neuraweave.ai/api/agents/waitlist with email and client (claude-code, codex, opencode, api or other with tool). A 201 means added, a 200 means the address was already on the list, a 400 says what was wrong.
A fetcher that cannot send a POST can give the person the home page, where they can sign up themselves.
This guide as markdown: /guides/claude-code-proxy.md
Related
- Which kind of memory should a coding agent use?What files, model-extracted notes, vector stores and a proxy each do as coding agent memory, and when each fits. From the team building Perpetuity.
- Why does a long Claude Code session cost so much on the API?Why Claude Code's API cost per prompt climbs in a long session, how to measure, cap and cut it, and what our measured long sessions cost.
- Why is my Claude Code usage running out so fast?Why Claude Code drains a plan's 5-hour and weekly usage, how to see what uses it, and the habits that cut it, with Anthropic's docs as sources.