Skip to main content

Claude Code gateway setup

Claude Code reaches the Anyray gateway through ANTHROPIC_BASE_URL in the env block of ~/.claude/settings.json. Anyray Connect writes that block for you, keeps the client key fresh, and restores the long context window Claude Code drops behind a custom base URL.

Connect Claude Code​

1
Enroll, then connect
npx anyray-connect@latest --gateway http://<gateway>:8787 --tools claude-code

Enroll first (--enroll <link> or --sso) to get a personal ark_… client key. --dry-run previews. Drop --tools to configure every detected tool.

2
Start a new Claude Code session

It loads the anyray MCP server at startup. Sessions already open route through the gateway from their next request.

3
Check it
anyray-connect doctor

Send one prompt. Your turn shows in console Sessions.

A Claude Pro, Max, Team, or Enterprise sign-in stays yours: see subscription login.

What Connect writes to settings.json​

Key in ~/.claude/settings.jsonWhat it holds
env.ANTHROPIC_BASE_URLThe gateway origin, with no /v1.
env.ANTHROPIC_CUSTOM_HEADERSx-anyray-metadata for attribution. On a Claude subscription it also carries x-anyray-provider: anthropic, x-anyray-auth-mode: passthrough, and your key as x-anyray-api-key.
apiKeyHelperAPI-key lane only. Runs anyray-connect print-key to renew the ark_… key on demand. A subscription seat gets a SessionStart hook instead, so your Claude sign-in is not replaced.
env._CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL, env.ENABLE_TOOL_SEARCH, [1m] on modelThe context window fix below.

Connect also installs hooks, the anyray MCP server, and MCP tool approvals in the same file: Seams inside your tools. To keep all of it in another file, see Claude Code settings file.

Set ANTHROPIC_BASE_URL by hand​

This is the API-key lane: the gateway holds the Anthropic key and your ark_… key identifies you.

~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "http://<gateway>:8787",
"ANTHROPIC_AUTH_TOKEN": "ark_synthetic-123456"
}
}

Leave /v1 off the URL. Open sessions use it from their next request. A hand-set key is not renewed for you (Key renewal), and the context window stays at 200k until you add the settings in the next section. If you later run Connect, --revert does not put this route or key back.

The 200k context window behind a custom ANTHROPIC_BASE_URL​

Claude Code only looks a model's real context window up when it talks to api.anthropic.com directly. Behind any custom base URL it budgets a flat 200,000 tokens and auto-compacts at roughly 95% of that, so a seat on a 1M-context model would silently lose 800k of window. Connect restores it with the settings below. None changes how you sign in or where requests route, and anyray-connect --revert removes them.

_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL​

Connect sets env._CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL to 1. It lets Claude Code use its own per-model windows again.

The flag also makes Claude Code mark its system prompt with a prompt-cache scope value only a subscription sign-in is entitled to. Anyray strips that mark on every other lane, or an org-API-key seat would get system.2.cache_control.ephemeral.scope: Extra inputs are not permitted as a 400 on every request.

CLAUDE_CODE_AUTO_MODE_SERVER​

Connect sets env.CLAUDE_CODE_AUTO_MODE_SERVER to 1, in your settings and in the fleet managed file. A leftover 0 makes Claude Code run Auto mode's safety check itself, as an extra model request per checked action that you pay for. --revert removes it.

Connect sets env.ENABLE_TOOL_SEARCH to auto:4 on a 1M-token model, including Claude Code's default when you pin none, and auto:20 otherwise. The flag above would turn tool search on for every session, so Connect turns it on only when your tool schemas are large for the model's window.

A value you, an admin (managed settings file) or a teammate (.claude/settings.json) set is kept, and --revert removes only a value Connect wrote. If your admin opts a Bedrock-routed org into claude-code-unpinned-tool-search-v1, Connect removes its own value and writes none.

The [1m] model suffix​

Connect appends [1m] to settings.model. That covers models that reach 1M through Claude Code's long-context option rather than natively.

If the context meter looks stuck at 100%

That is the un-restored behavior: a 1M model clamped against a 200k budget. Re-run Connect, then fully restart Claude Code.

WebSearch and DesignSync deny rules on Bedrock-only routes

The first-party flag also makes Claude Code offer tools that only Anthropic's own API can run. On an org route that reaches only Bedrock, an admin can have Connect add WebSearch and DesignSync to permissions.deny so new sessions stop sending their schemas. Open sessions keep them until they restart. Off by default. The gateway already removes WebSearch from every Bedrock request, since Bedrock cannot run it. A deny rule you already had stays, and --revert removes only the rules Connect added.

Revert​

anyray-connect --tools claude-code --revert

anyray-connect --revert undoes every tool and clears the enrollment (Reverting). A terminal that was open before the revert still exports the gateway. Open a new one, or clear it:

unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ENABLE_TOOL_SEARCH _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL