agent: stop the proxy hop capping chat sessions at 200k context
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 <noreply@anthropic.com>
This commit is contained in:
@@ -126,6 +126,18 @@ const ANTHROPIC_PROXY_PORT = process.env.ANTHROPIC_PROXY_PORT ?? '5051';
|
|||||||
|
|
||||||
function ensureAnthropicEnv(): void {
|
function ensureAnthropicEnv(): void {
|
||||||
process.env.ANTHROPIC_BASE_URL ??= `http://127.0.0.1:${ANTHROPIC_PROXY_PORT}`;
|
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;
|
if (process.env.ANTHROPIC_API_KEY) return;
|
||||||
|
|
||||||
const secret = readProxySecretFromDisk();
|
const secret = readProxySecretFromDisk();
|
||||||
|
|||||||
Reference in New Issue
Block a user