From b953a6ba8cc45007b72c8d977319e1941b86477a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Sat, 8 Aug 2026 16:24:04 +0000 Subject: [PATCH] agent: stop the proxy hop capping chat sessions at 200k context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Platform chat ran at 200K while the same `claude` in a terminal got Opus 5's full 1M. Nothing to do with the model, the account or compaction tuning — the CLI gates 1M on `provider === 'firstParty' && Fp()`, and `Fp()` is satisfied only when ANTHROPIC_BASE_URL is unset or its host is api.anthropic.com. We point it at 127.0.0.1:5051 so the agent's traffic goes through the OAuth proxy, which fails that host check and silently drops the window to 200K. _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL is the CLI's own escape hatch for a first-party passthrough, and the assertion holds: the proxy forwards verbatim to api.anthropic.com and already preserves anthropic-beta. Read from the CLI binary (2.1.223), not inferred: claude-opus-5 carries context:{window:1e6, native_1m:true}, so the model half of the gate always passed. Only the hostname was wrong. Co-Authored-By: Claude Opus 5 --- src/servers/sidecar/claude/user-instance.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/servers/sidecar/claude/user-instance.ts b/src/servers/sidecar/claude/user-instance.ts index 5f90ea67..603bf69f 100644 --- a/src/servers/sidecar/claude/user-instance.ts +++ b/src/servers/sidecar/claude/user-instance.ts @@ -126,6 +126,18 @@ const ANTHROPIC_PROXY_PORT = process.env.ANTHROPIC_PROXY_PORT ?? '5051'; function ensureAnthropicEnv(): void { process.env.ANTHROPIC_BASE_URL ??= `http://127.0.0.1:${ANTHROPIC_PROXY_PORT}`; + // Without this, every platform chat session is capped at 200K context while the same `claude` in a + // terminal gets Opus 5's full 1M — for no reason other than the proxy hop above. + // + // The CLI decides 1M eligibility with `provider === 'firstParty' && Fp()`, where `Fp()` is + // `!ANTHROPIC_BASE_URL || new URL(ANTHROPIC_BASE_URL).host === 'api.anthropic.com'`. Pointing the + // base URL at 127.0.0.1 fails that host check, so the client silently drops to 200K — the model is + // fine (`claude-opus-5` is `native_1m: true`) and so is the account; only the hostname is wrong. + // + // The assertion this flag makes is true here: the proxy forwards verbatim to api.anthropic.com and + // preserves `anthropic-beta` (see proxy.ts), so first-party is exactly what is on the other end. Do + // not set it on a base URL that points anywhere else. + process.env._CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL ??= '1'; if (process.env.ANTHROPIC_API_KEY) return; const secret = readProxySecretFromDisk();