Skip to content

Commit 02644e6

Browse files
author
jun
committed
fix(claude): keep a connected target's admission token out of subscription stripping
The carried subscription fix resolves auth mode before adding proxy-owned credentials, which is right for an ordinary launch. A connected launch is not one: the caller already named a hub and supplied the client admission token for it, so a machine whose own environment reads as a Claude subscription would strip the very credential the launch was constructed with. Gate the subscription strip on the absence of an explicit target, and add the regression.
1 parent 5b61770 commit 02644e6

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/cli/claude.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ export function buildClaudeEnv(
213213
env: () => env as NodeJS.ProcessEnv,
214214
ownTokens,
215215
}));
216-
if (resolved.markerMode === "subscription") {
216+
// An explicit connected target is not a subscription launch. The caller named a hub and
217+
// handed us the client admission token for it, so auth-mode detection - which reads the
218+
// local environment - has no bearing on whether that token belongs in the child env.
219+
// Without this, a machine whose environment reads as subscription strips the very
220+
// credential the connected launch was constructed with (#3148 carry).
221+
if (resolved.markerMode === "subscription" && !explicitTarget) {
217222
// A prior system-env snapshot may have left our admission key in the inherited
218223
// environment. It belongs to the proxy data plane, not Claude subscription OAuth.
219224
const token = env.ANTHROPIC_AUTH_TOKEN?.trim();

tests/claude-cli.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ describe("ocx claude env assembly", () => {
3737
expect(env.CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST).toBe("1");
3838
});
3939

40+
test("a connected target keeps its admission token even when the local env reads as subscription", () => {
41+
// #3148 resolves the auth mode before adding proxy-owned credentials, which is right for
42+
// an ordinary launch. A connected launch is different: the caller already named a hub and
43+
// supplied the client admission token for it, so a machine whose own environment looks
44+
// like a Claude subscription must not strip the credential the launch was built with.
45+
const env = buildClaudeEnv(cfg(), {
46+
baseUrl: "https://hub.example.test",
47+
admissionToken: "ocx_data_connected",
48+
}, {}, {}, { mode: "subscription", origin: "explicit" });
49+
expect(env.ANTHROPIC_BASE_URL).toBe("https://hub.example.test");
50+
expect(env.ANTHROPIC_AUTH_TOKEN).toBe("ocx_data_connected");
51+
});
52+
4053
test("user-owned connected destination wins and cannot receive the hub token", () => {
4154
const env = buildClaudeEnv(cfg(), {
4255
baseUrl: "https://hub.example.test",

0 commit comments

Comments
 (0)