Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(pane): set no ANTHROPIC_API_KEY in a proxied pane child
Jack Rudenko185a9c1b40fa
diff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.mdindex eaa0bac9..bba9018d 100644--- a/ai-docs/architecture/pane-session.md+++ b/ai-docs/architecture/pane-session.md@@ -235,7 +235,10 @@ pane; for a declared wrapper its `editorOverride` is `delegated` ("the wrapper mmode itself"). If vim mode is on anyway, the gate refuses to type (`vim_mode`) and the prompt failswith `vim editing mode is on` — at once when the published view already says so, else after thein-flight send's ready wait (≤ 10 s) — instead of sitting unsent. The API-key dialog was not recaptured on 2.1.290 (it needs a foreign route with-`ANTHROPIC_API_KEY` set); its marker is the verbatim 2.1.287 text.+`ANTHROPIC_API_KEY` set); its marker is the verbatim 2.1.287 text. It cannot occur in a pure-proxy+pane: such a pane child sets no `ANTHROPIC_API_KEY` (and deletes an inherited one), only the placeholder+`ANTHROPIC_AUTH_TOKEN`, which alone suppresses login (`applyProxyPlaceholderAuth`; verified on+Claude Code 2.1.304, where an env key raised "Detected a custom API key in your environment").**An unknown `--agent` is refused by the child itself**, which is why the old `claude -p` agentprobe was deleted (D11): with two validators the cheap one always decides and the real one is neverdiff --git a/ai-docs/reports/mcp-magmux-panes/session-record/architecture.md b/ai-docs/reports/mcp-magmux-panes/session-record/architecture.mdindex 1f98fb41..74fcb58e 100644--- a/ai-docs/reports/mcp-magmux-panes/session-record/architecture.md+++ b/ai-docs/reports/mcp-magmux-panes/session-record/architecture.md@@ -1958,6 +1958,7 @@ a fresh `~/.claude.json` every foreign-model pane meets the API-key dialog and f(frequency: once per machine/config dir, until answered once). Pre-seeding `customApiKeyResponses` or an`apiKeyHelper` through the same `CLAUDISH_PANE_CHILD`-gated overlay would remove it, but it changes authbehaviour; it is recorded in `ROADMAP.md` with this trigger, and R15 verifies the reported reason and text.+Resolved 2026-10-21: the pane child sets no ANTHROPIC_API_KEY.---diff --git a/packages/cli/src/claude-runner.ts b/packages/cli/src/claude-runner.tsindex 3ef1f58b..7eeaa599 100644--- a/packages/cli/src/claude-runner.ts+++ b/packages/cli/src/claude-runner.ts@@ -182,6 +182,22 @@ export const CLAUDISH_PLACEHOLDER_API_KEY =/** The placeholder ANTHROPIC_AUTH_TOKEN paired with CLAUDISH_PLACEHOLDER_API_KEY. */export const CLAUDISH_PLACEHOLDER_AUTH_TOKEN = "placeholder-token-not-used-proxy-handles-auth";+/**+ * Pure proxy mode's placeholder credentials. The token alone suppresses Claude Code's+ * login (verified on Claude Code 2.1.304). An env ANTHROPIC_API_KEY raises "Detected a+ * custom API key" on a config that has not answered it, and a headless pane cannot+ * answer, so the pane child sets no key at all and deletes an inherited one. Other+ * launches keep the pair unchanged.+ */+export function applyProxyPlaceholderAuth(+ env: Record<string, string | undefined>,+ paneChild: boolean = isPaneChild()+): void {+ env.ANTHROPIC_AUTH_TOKEN = CLAUDISH_PLACEHOLDER_AUTH_TOKEN;+ if (paneChild) delete env.ANTHROPIC_API_KEY;+ else env.ANTHROPIC_API_KEY = CLAUDISH_PLACEHOLDER_API_KEY;+}+/*** Remove claudish's OWN placeholder credentials that were inherited from a parent* proxied session.@@ -1888,11 +1904,11 @@ export async function runClaudeWithProxy(// is dead weight. Forwarding one is actively harmful: Claude Code then// reports "API Usage Billing", and pairing it with the placeholder token// trips "Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may- // not work as expected". So overwrite unconditionally with placeholders —+ // not work as expected". So overwrite any real key with placeholders —// their only job is suppressing the login dialog (#13: a placeholder API- // key alone still redirected to the payment page, hence the token too).- env.ANTHROPIC_API_KEY = CLAUDISH_PLACEHOLDER_API_KEY;- env.ANTHROPIC_AUTH_TOKEN = CLAUDISH_PLACEHOLDER_AUTH_TOKEN;+ // key alone still redirected to the payment page, hence the token). A pane+ // child gets the token only; see applyProxyPlaceholderAuth.+ applyProxyPlaceholderAuth(env);// Drive Claude Code's NATIVE auto-compaction to fire before a backend whose// real context window is smaller than the model's advertised spec rejectsdiff --git a/packages/cli/src/proxy-placeholder-auth.test.ts b/packages/cli/src/proxy-placeholder-auth.test.tsnew file mode 100644index 00000000..9bacc7e7--- /dev/null+++ b/packages/cli/src/proxy-placeholder-auth.test.ts@@ -0,0 +1,115 @@+// REGRESSION: team voters in a ps-less sandbox lose their launch dir; proxied pane child hits the API-key dialog — Fixed in /dev:fix session dev-fix-20261021-011007-a7c3++import { describe, expect, test } from "bun:test";+import {+ CLAUDISH_PLACEHOLDER_API_KEY,+ CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ applyProxyPlaceholderAuth,+} from "./claude-runner.js";++const initialAuth: Array<{ name: string; values: Record<string, string | undefined> }> = [+ { name: "absent credentials", values: {} },+ {+ name: "explicitly undefined credentials",+ values: { ANTHROPIC_API_KEY: undefined, ANTHROPIC_AUTH_TOKEN: undefined },+ },+ {+ name: "placeholder credentials",+ values: {+ ANTHROPIC_API_KEY: CLAUDISH_PLACEHOLDER_API_KEY,+ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ },+ },+ {+ name: "preexisting credentials",+ values: {+ ANTHROPIC_API_KEY: "sk-ant-api03-" + "a".repeat(40),+ ANTHROPIC_AUTH_TOKEN: "previous-auth-token",+ },+ },+];++describe("applyProxyPlaceholderAuth", () => {+ for (const { name, values } of initialAuth) {+ test(`B1: a pane child deletes ANTHROPIC_API_KEY with ${name}`, () => {+ const env = { ...values };+ const result = applyProxyPlaceholderAuth(env, true);+ expect(result).toBeUndefined();+ expect(env.ANTHROPIC_AUTH_TOKEN).toBe(CLAUDISH_PLACEHOLDER_AUTH_TOKEN);+ expect("ANTHROPIC_API_KEY" in env).toBe(false);+ expect(env).toEqual({ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN });+ });++ test(`B2: outside a pane both placeholders replace ${name}`, () => {+ const env = { ...values };+ const result = applyProxyPlaceholderAuth(env, false);+ expect(result).toBeUndefined();+ expect(env).toEqual({+ ANTHROPIC_API_KEY: CLAUDISH_PLACEHOLDER_API_KEY,+ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ });+ });+ }++ test.each([true, false])("B3: other keys are unchanged (paneChild=%p)", (paneChild) => {+ const unrelated = {+ PATH: "/test/bin",+ HOME: "/test/home",+ ANTHROPIC_BASE_URL: "http://127.0.0.1:12345",+ CLAUDISH_PANE_CHILD: "keep-this-value",+ CLAUDISH_PANE_CWD: "/test/workspace",+ EMPTY: "",+ OPTIONAL: undefined,+ };+ const env: Record<string, string | undefined> = {+ ...unrelated,+ ANTHROPIC_API_KEY: "previous-key",+ ANTHROPIC_AUTH_TOKEN: "previous-auth-token",+ };+ applyProxyPlaceholderAuth(env, paneChild);+ expect(env).toEqual({+ ...unrelated,+ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ ...(paneChild ? {} : { ANTHROPIC_API_KEY: CLAUDISH_PLACEHOLDER_API_KEY }),+ });+ });++ test("B4: omitted paneChild follows the current process pane flag and cwd", () => {+ const savedFlag = process.env.CLAUDISH_PANE_CHILD;+ const savedCwd = process.env.CLAUDISH_PANE_CWD;+ try {+ process.env.CLAUDISH_PANE_CHILD = "1";+ process.env.CLAUDISH_PANE_CWD = import.meta.dir;+ const paneEnv: Record<string, string | undefined> = {+ ANTHROPIC_API_KEY: "previous-key",+ ANTHROPIC_AUTH_TOKEN: "previous-auth-token",+ UNRELATED: "preserved",+ };+ applyProxyPlaceholderAuth(paneEnv);+ expect("ANTHROPIC_API_KEY" in paneEnv).toBe(false);+ expect(paneEnv).toEqual({+ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ UNRELATED: "preserved",+ });++ delete process.env.CLAUDISH_PANE_CHILD;+ delete process.env.CLAUDISH_PANE_CWD;+ const outsideEnv: Record<string, string | undefined> = {+ ANTHROPIC_API_KEY: "previous-key",+ ANTHROPIC_AUTH_TOKEN: "previous-auth-token",+ UNRELATED: "preserved",+ };+ applyProxyPlaceholderAuth(outsideEnv);+ expect(outsideEnv).toEqual({+ ANTHROPIC_API_KEY: CLAUDISH_PLACEHOLDER_API_KEY,+ ANTHROPIC_AUTH_TOKEN: CLAUDISH_PLACEHOLDER_AUTH_TOKEN,+ UNRELATED: "preserved",+ });+ } finally {+ if (savedFlag === undefined) delete process.env.CLAUDISH_PANE_CHILD;+ else process.env.CLAUDISH_PANE_CHILD = savedFlag;+ if (savedCwd === undefined) delete process.env.CLAUDISH_PANE_CWD;+ else process.env.CLAUDISH_PANE_CWD = savedCwd;+ }+ });+});