claude-use 12.0.0 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -32078,6 +32078,9 @@ async function realRunningAmong(pids, psTimeoutMs = PS_TIMEOUT_MS) {
32078
32078
  const states = await readProcessStates(existing, psTimeoutMs);
32079
32079
  return new Set(existing.filter((pid) => states.get(pid)?.startsWith("Z") !== true));
32080
32080
  }
32081
+ function definedEntries(env) {
32082
+ return Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== void 0));
32083
+ }
32081
32084
  function realRunAsyncWithin(timeoutMs) {
32082
32085
  return async (command, args) => await new Promise((resolve3) => {
32083
32086
  (0, import_node_child_process3.execFile)(command, [...args], { encoding: "utf8", timeout: timeoutMs }, (error63, stdout2, stderr) => {
@@ -32543,8 +32546,14 @@ var init_realPorts = __esm({
32543
32546
  BYTES_PER_MIB2 = 1048576;
32544
32547
  RUN_OUTPUT_LIMIT_BYTES = RUN_OUTPUT_LIMIT_MIB * BYTES_PER_MIB2;
32545
32548
  realRunPort = {
32546
- run(command, args, input2) {
32547
- const result = spawnSyncBlocking("an external command", command, args, { encoding: "utf8", maxBuffer: RUN_OUTPUT_LIMIT_BYTES, ...input2 === void 0 ? {} : { input: input2 } });
32549
+ run(command, args, input2, options) {
32550
+ const result = spawnSyncBlocking("an external command", command, args, {
32551
+ encoding: "utf8",
32552
+ maxBuffer: RUN_OUTPUT_LIMIT_BYTES,
32553
+ ...input2 === void 0 ? {} : { input: input2 },
32554
+ ...options?.env === void 0 ? {} : { env: definedEntries(options.env) },
32555
+ ...options?.timeoutMs === void 0 ? {} : { timeout: options.timeoutMs }
32556
+ });
32548
32557
  return { status: result.status, stdout: result.stdout, stderr: result.stderr };
32549
32558
  }
32550
32559
  };
@@ -35040,9 +35049,224 @@ var init_identityToken = __esm({
35040
35049
  }
35041
35050
  });
35042
35051
 
35052
+ // src/headroom/headers.ts
35053
+ function mergeAnthropicCustomHeaders(existing, additions) {
35054
+ const merged = /* @__PURE__ */ new Map();
35055
+ for (const block2 of existing) {
35056
+ if (block2 === void 0) {
35057
+ continue;
35058
+ }
35059
+ for (const line of block2.split("\n")) {
35060
+ const entry = parseCustomHeaderLine(line);
35061
+ if (entry === void 0) {
35062
+ continue;
35063
+ }
35064
+ merged.set(entry.name, entry.value);
35065
+ }
35066
+ }
35067
+ for (const entry of additions) {
35068
+ merged.set(entry.name, entry.value);
35069
+ }
35070
+ return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
35071
+ }
35072
+ function parseAnthropicCustomHeaders(block2) {
35073
+ return block2.split("\n").flatMap((line) => {
35074
+ const entry = parseCustomHeaderLine(line);
35075
+ return entry === void 0 ? [] : [entry];
35076
+ });
35077
+ }
35078
+ function withoutAnthropicCustomHeaders(block2, remove) {
35079
+ const lines = block2.split("\n");
35080
+ const kept = lines.filter((line) => {
35081
+ const entry = parseCustomHeaderLine(line);
35082
+ return entry === void 0 || !remove(entry);
35083
+ });
35084
+ return kept.length === lines.length ? block2 : kept.join("\n");
35085
+ }
35086
+ function parseCustomHeaderLine(line) {
35087
+ const trimmed = line.trim();
35088
+ if (trimmed === "") {
35089
+ return void 0;
35090
+ }
35091
+ const colon = trimmed.indexOf(":");
35092
+ if (colon <= 0) {
35093
+ return void 0;
35094
+ }
35095
+ return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
35096
+ }
35097
+ var init_headers = __esm({
35098
+ "src/headroom/headers.ts"() {
35099
+ "use strict";
35100
+ }
35101
+ });
35102
+
35103
+ // src/launcher/injected.ts
35104
+ function listKey(list2) {
35105
+ return `${list2},appended`;
35106
+ }
35107
+ function digest(value3) {
35108
+ return (0, import_node_crypto5.createHash)("sha256").update(value3).digest("hex");
35109
+ }
35110
+ function recordedDigests(env) {
35111
+ const raw = env[INJECTED_ENV];
35112
+ if (raw === void 0 || raw === "") {
35113
+ return {};
35114
+ }
35115
+ let parsed;
35116
+ try {
35117
+ parsed = JSON.parse(raw);
35118
+ } catch {
35119
+ return {};
35120
+ }
35121
+ const result = InjectedSchema.safeParse(parsed);
35122
+ return result.success ? result.data : {};
35123
+ }
35124
+ function recordInjections(base) {
35125
+ const env = { ...base };
35126
+ const digests = new Map(Object.entries(recordedDigests(env)));
35127
+ return {
35128
+ env,
35129
+ set: (name, value3) => {
35130
+ env[name] = value3;
35131
+ digests.set(name, digest(value3));
35132
+ },
35133
+ unset: (name) => {
35134
+ env[name] = void 0;
35135
+ digests.delete(name);
35136
+ },
35137
+ recordHeaders: (names) => {
35138
+ const block2 = env[CUSTOM_HEADERS_ENV];
35139
+ for (const entry of block2 === void 0 ? [] : parseAnthropicCustomHeaders(block2)) {
35140
+ if (names.includes(entry.name)) {
35141
+ digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest(entry.value));
35142
+ }
35143
+ }
35144
+ },
35145
+ recordBypassHosts: (list2, hosts) => {
35146
+ const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list2))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
35147
+ if (recordedHosts.length > 0) {
35148
+ digests.set(listKey(list2), recordedHosts.join(","));
35149
+ }
35150
+ },
35151
+ finish: () => {
35152
+ if (digests.size > 0) {
35153
+ env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
35154
+ }
35155
+ }
35156
+ };
35157
+ }
35158
+ function withoutRecordedHosts(list2, value3, digests) {
35159
+ const recordedHosts = new Set(digests[listKey(list2)]?.split(","));
35160
+ const entries = value3.split(",");
35161
+ const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
35162
+ return kept.length === entries.length ? value3 : kept.join(",");
35163
+ }
35164
+ function launchEnvironment(env, configDirEscapeHatch) {
35165
+ return configDirEscapeHatch ? env : withoutInjected(env);
35166
+ }
35167
+ function withoutInjected(env) {
35168
+ const digests = recordedDigests(env);
35169
+ const entries = Object.entries(env).flatMap(([name, value3]) => {
35170
+ if (name === INJECTED_ENV) {
35171
+ return [];
35172
+ }
35173
+ if (value3 === void 0) {
35174
+ return [[name, value3]];
35175
+ }
35176
+ if (name === CUSTOM_HEADERS_ENV) {
35177
+ const remaining = withoutAnthropicCustomHeaders(value3, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest(entry.value));
35178
+ return remaining !== value3 && remaining.trim() === "" ? [] : [[name, remaining]];
35179
+ }
35180
+ if (name === "NO_PROXY" || name === "no_proxy") {
35181
+ const remaining = withoutRecordedHosts(name, value3, digests);
35182
+ return remaining !== value3 && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
35183
+ }
35184
+ return digests[name] === digest(value3) ? [] : [[name, value3]];
35185
+ });
35186
+ return Object.fromEntries(entries);
35187
+ }
35188
+ var import_node_crypto5, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
35189
+ var init_injected = __esm({
35190
+ "src/launcher/injected.ts"() {
35191
+ "use strict";
35192
+ import_node_crypto5 = require("node:crypto");
35193
+ init_zod();
35194
+ init_headers();
35195
+ INJECTED_ENV = "AGENT_SHIM_INJECTED";
35196
+ CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
35197
+ HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
35198
+ InjectedSchema = external_exports.record(external_exports.string(), external_exports.string());
35199
+ }
35200
+ });
35201
+
35202
+ // src/launcher/guard.ts
35203
+ function detectAmbientCredential(env, injected) {
35204
+ for (const variable of AMBIENT_CREDENTIAL_VARS) {
35205
+ const value3 = env[variable];
35206
+ if (value3 === void 0 || value3 === "") {
35207
+ continue;
35208
+ }
35209
+ if (injected?.variable === variable && value3 === injected.token) {
35210
+ continue;
35211
+ }
35212
+ return { variable };
35213
+ }
35214
+ return void 0;
35215
+ }
35216
+ function formatAmbientCredentialGuardMessage(variable, identityName) {
35217
+ const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
35218
+ return [
35219
+ `error: ${variable} is set in the environment. This identity's isolated`,
35220
+ "credential would be bypassed \u2014 every identity authenticates as this same key",
35221
+ "while it's set. Unset it, or if this is deliberate, opt in per-launch with",
35222
+ "AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
35223
+ `\`${identitySetCommand}\`.`
35224
+ ].join("\n");
35225
+ }
35226
+ function evaluateAmbientCredentialGuard(params) {
35227
+ const detected = detectAmbientCredential(params.env, params.injectedCredential);
35228
+ if (detected === void 0) {
35229
+ return { ok: true };
35230
+ }
35231
+ if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
35232
+ return { ok: true };
35233
+ }
35234
+ return {
35235
+ ok: false,
35236
+ variable: detected.variable,
35237
+ message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
35238
+ };
35239
+ }
35240
+ function ambientCredentialFinding(env) {
35241
+ const named = detectAmbientCredential(launchEnvironment(env, false));
35242
+ if (named !== void 0) {
35243
+ return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
35244
+ }
35245
+ const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
35246
+ if (bare !== void 0) {
35247
+ return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
35248
+ }
35249
+ return { severity: "pass", message: "No ambient-credential environment variable is set." };
35250
+ }
35251
+ var AMBIENT_CREDENTIAL_VARS;
35252
+ var init_guard = __esm({
35253
+ "src/launcher/guard.ts"() {
35254
+ "use strict";
35255
+ init_injected();
35256
+ AMBIENT_CREDENTIAL_VARS = [
35257
+ "ANTHROPIC_API_KEY",
35258
+ "ANTHROPIC_AUTH_TOKEN",
35259
+ "CLAUDE_CODE_OAUTH_TOKEN",
35260
+ "CLAUDE_CODE_USE_BEDROCK",
35261
+ "CLAUDE_CODE_USE_VERTEX",
35262
+ "CLAUDE_CODE_USE_FOUNDRY"
35263
+ ];
35264
+ }
35265
+ });
35266
+
35043
35267
  // src/usage/signIn.ts
35044
35268
  function claudeCodeKeychainService(configDir) {
35045
- return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto5.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
35269
+ return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto6.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
35046
35270
  }
35047
35271
  function keychainHasItem(run, configDir) {
35048
35272
  return run.run("security", ["find-generic-password", "-s", claudeCodeKeychainService(configDir)]).status === 0;
@@ -35075,15 +35299,35 @@ function identitySignIn(fs37, probe, identity) {
35075
35299
  platform: probe.platform
35076
35300
  });
35077
35301
  }
35078
- var import_node_crypto5, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS;
35302
+ function storedLoginUsable(run, claudeBin, configDir, env) {
35303
+ const childEnv = { ...env, CLAUDE_CONFIG_DIR: configDir };
35304
+ for (const variable of AMBIENT_CREDENTIAL_VARS) {
35305
+ childEnv[variable] = void 0;
35306
+ }
35307
+ const result = run.run(claudeBin, ["auth", "status"], void 0, { env: childEnv, timeoutMs: AUTH_STATUS_TIMEOUT_MS });
35308
+ if (result.status === null) {
35309
+ return void 0;
35310
+ }
35311
+ try {
35312
+ const status = JSON.parse(result.stdout);
35313
+ if (typeof status === "object" && status !== null && "loggedIn" in status && typeof status.loggedIn === "boolean") {
35314
+ return status.loggedIn;
35315
+ }
35316
+ } catch {
35317
+ }
35318
+ return void 0;
35319
+ }
35320
+ var import_node_crypto6, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS, AUTH_STATUS_TIMEOUT_MS;
35079
35321
  var init_signIn = __esm({
35080
35322
  "src/usage/signIn.ts"() {
35081
35323
  "use strict";
35082
- import_node_crypto5 = require("node:crypto");
35324
+ import_node_crypto6 = require("node:crypto");
35083
35325
  import_node_path19 = __toESM(require("node:path"), 1);
35326
+ init_guard();
35084
35327
  CREDENTIALS_FILE = ".credentials.json";
35085
35328
  KEYCHAIN_SERVICE_PREFIX = "Claude Code-credentials";
35086
35329
  KEYCHAIN_SERVICE_HASH_DIGITS = 8;
35330
+ AUTH_STATUS_TIMEOUT_MS = 1e4;
35087
35331
  }
35088
35332
  });
35089
35333
 
@@ -35302,7 +35546,7 @@ function serialisedFor(entry, owner) {
35302
35546
  return JSON.stringify({ owner, ...withoutOwner(entry) });
35303
35547
  }
35304
35548
  function tempPathFor(target) {
35305
- return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto6.randomUUID)()}`);
35549
+ return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto7.randomUUID)()}`);
35306
35550
  }
35307
35551
  function processRuns(pid) {
35308
35552
  try {
@@ -35505,12 +35749,12 @@ function createAsyncRealCredentialCache(root) {
35505
35749
  function realAsyncCredentialCacheEnv(paths) {
35506
35750
  return { port: createAsyncRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
35507
35751
  }
35508
- var import_node_child_process4, import_node_crypto6, import_node_fs9, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
35752
+ var import_node_child_process4, import_node_crypto7, import_node_fs9, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
35509
35753
  var init_realCredentialCache = __esm({
35510
35754
  "src/realCredentialCache.ts"() {
35511
35755
  "use strict";
35512
35756
  import_node_child_process4 = require("node:child_process");
35513
- import_node_crypto6 = require("node:crypto");
35757
+ import_node_crypto7 = require("node:crypto");
35514
35758
  import_node_fs9 = __toESM(require("node:fs"), 1);
35515
35759
  import_node_path20 = __toESM(require("node:path"), 1);
35516
35760
  init_blockingSpawn();
@@ -35557,7 +35801,7 @@ function acquireIdentityLock(params) {
35557
35801
  const staleAfterMs = params.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;
35558
35802
  const retryDelayMs = params.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
35559
35803
  const maxAttempts = params.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
35560
- const token = (0, import_node_crypto7.randomUUID)();
35804
+ const token = (0, import_node_crypto8.randomUUID)();
35561
35805
  if (params.fs.lstat(params.dir) === void 0) {
35562
35806
  params.fs.mkdirp(params.dir);
35563
35807
  }
@@ -35613,11 +35857,11 @@ function acquireIdentityLock(params) {
35613
35857
  }
35614
35858
  throw new IdentityLockBusyError(params.identity, lockPath, lastHolderPid);
35615
35859
  }
35616
- var import_node_crypto7, import_node_path21, DEFAULT_STALE_AFTER_MS, DEFAULT_RETRY_DELAY_MS, DEFAULT_MAX_ATTEMPTS, IdentityLockLostError, IdentityLockBusyError;
35860
+ var import_node_crypto8, import_node_path21, DEFAULT_STALE_AFTER_MS, DEFAULT_RETRY_DELAY_MS, DEFAULT_MAX_ATTEMPTS, IdentityLockLostError, IdentityLockBusyError;
35617
35861
  var init_lock = __esm({
35618
35862
  "src/launcher/lock.ts"() {
35619
35863
  "use strict";
35620
- import_node_crypto7 = require("node:crypto");
35864
+ import_node_crypto8 = require("node:crypto");
35621
35865
  import_node_path21 = __toESM(require("node:path"), 1);
35622
35866
  init_cliError();
35623
35867
  DEFAULT_STALE_AFTER_MS = 12e4;
@@ -37346,7 +37590,7 @@ function renameJournalFile(directory, from, to2) {
37346
37590
  return import_node_path24.default.join(directory, renamePairFileName(from, to2, JOURNAL_SUFFIX));
37347
37591
  }
37348
37592
  function renamePairFileName(from, to2, suffix) {
37349
- return `${(0, import_node_crypto8.createHash)("sha256").update(`${from}\0${to2}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
37593
+ return `${(0, import_node_crypto9.createHash)("sha256").update(`${from}\0${to2}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
37350
37594
  }
37351
37595
  function readRenameJournal(fs37, file2) {
37352
37596
  const raw = fs37.readFileUtf8(file2);
@@ -37442,11 +37686,11 @@ function requireNameFreeOfUnfinishedRename(fs37, directory, name, action, sameNa
37442
37686
  throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
37443
37687
  }
37444
37688
  }
37445
- var import_node_crypto8, import_node_path24, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
37689
+ var import_node_crypto9, import_node_path24, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
37446
37690
  var init_identityRenameJournal = __esm({
37447
37691
  "src/identityRenameJournal.ts"() {
37448
37692
  "use strict";
37449
- import_node_crypto8 = require("node:crypto");
37693
+ import_node_crypto9 = require("node:crypto");
37450
37694
  import_node_path24 = __toESM(require("node:path"), 1);
37451
37695
  init_zod();
37452
37696
  init_cliError();
@@ -37614,7 +37858,7 @@ var init_identityNameRenameRecord = __esm({
37614
37858
 
37615
37859
  // src/launcher/launchRecords.ts
37616
37860
  function recordFile2(directory, pid) {
37617
- return import_node_path26.default.join(directory, `${String(pid)}.${(0, import_node_crypto9.randomUUID)()}${RECORD_SUFFIX2}`);
37861
+ return import_node_path26.default.join(directory, `${String(pid)}.${(0, import_node_crypto10.randomUUID)()}${RECORD_SUFFIX2}`);
37618
37862
  }
37619
37863
  function readRecord(fs37, directory, name) {
37620
37864
  if (!name.endsWith(RECORD_SUFFIX2)) {
@@ -37655,12 +37899,12 @@ function liveLaunchesOn(fs37, directory, identity, isRunning) {
37655
37899
  return record3?.identity === identity && isRunning(record3.pid) ? [record3.pid] : [];
37656
37900
  }).sort((left, right) => left - right);
37657
37901
  }
37658
- var import_node_path26, import_node_crypto9, LaunchRecordSchema, RECORD_SUFFIX2;
37902
+ var import_node_path26, import_node_crypto10, LaunchRecordSchema, RECORD_SUFFIX2;
37659
37903
  var init_launchRecords = __esm({
37660
37904
  "src/launcher/launchRecords.ts"() {
37661
37905
  "use strict";
37662
37906
  import_node_path26 = __toESM(require("node:path"), 1);
37663
- import_node_crypto9 = require("node:crypto");
37907
+ import_node_crypto10 = require("node:crypto");
37664
37908
  init_zod();
37665
37909
  LaunchRecordSchema = external_exports.strictObject({
37666
37910
  /** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
@@ -40205,7 +40449,7 @@ function ipBytes(address) {
40205
40449
  return bytes;
40206
40450
  }
40207
40451
  function keyIdentifier(publicKey) {
40208
- return (0, import_node_crypto10.createHash)("sha1").update(publicKey.export({ type: "pkcs1", format: "der" })).digest();
40452
+ return (0, import_node_crypto11.createHash)("sha1").update(publicKey.export({ type: "pkcs1", format: "der" })).digest();
40209
40453
  }
40210
40454
  function readElement(buffer2, offset) {
40211
40455
  const tag = buffer2[offset];
@@ -40251,7 +40495,7 @@ ${body.join("\n")}
40251
40495
  `;
40252
40496
  }
40253
40497
  function randomSerial() {
40254
- const bytes = (0, import_node_crypto10.randomBytes)(SERIAL_NUMBER_BYTES);
40498
+ const bytes = (0, import_node_crypto11.randomBytes)(SERIAL_NUMBER_BYTES);
40255
40499
  bytes[0] = (bytes[0] ?? 0) & BASE_128_PAYLOAD_MASK | HIGH_BIT >> 1;
40256
40500
  return bytes;
40257
40501
  }
@@ -40266,7 +40510,7 @@ function assemble(spec) {
40266
40510
  spec.subjectPublicKey.export({ type: "spki", format: "der" }),
40267
40511
  tlv(TAG_EXTENSIONS, sequence(...spec.extensions))
40268
40512
  );
40269
- const signature = (0, import_node_crypto10.sign)("sha256", tbs, spec.signingKey);
40513
+ const signature = (0, import_node_crypto11.sign)("sha256", tbs, spec.signingKey);
40270
40514
  return sequence(tbs, SIGNATURE_ALGORITHM, wholeBitString(signature));
40271
40515
  }
40272
40516
  function subjectKeyIdentifierExtension(publicKey) {
@@ -40276,7 +40520,7 @@ function basicConstraintsExtension(isCa) {
40276
40520
  return extension(OID_BASIC_CONSTRAINTS, true, sequence(...isCa ? [boolean4(true)] : []));
40277
40521
  }
40278
40522
  function rsaKeyPair() {
40279
- return (0, import_node_crypto10.generateKeyPairSync)("rsa", { modulusLength: RSA_MODULUS_BITS });
40523
+ return (0, import_node_crypto11.generateKeyPairSync)("rsa", { modulusLength: RSA_MODULUS_BITS });
40280
40524
  }
40281
40525
  function keyPem(privateKey) {
40282
40526
  return privateKey.export({ type: "pkcs8", format: "pem" });
@@ -40300,8 +40544,8 @@ function issueLeafCertificate(ca2, names, notBefore, notAfter) {
40300
40544
  if (commonName === void 0) {
40301
40545
  throw new Error("a leaf certificate needs at least one name");
40302
40546
  }
40303
- const caCertificate = new import_node_crypto10.X509Certificate(ca2.certPem);
40304
- const caPrivateKey = (0, import_node_crypto10.createPrivateKey)(ca2.keyPem);
40547
+ const caCertificate = new import_node_crypto11.X509Certificate(ca2.certPem);
40548
+ const caPrivateKey = (0, import_node_crypto11.createPrivateKey)(ca2.keyPem);
40305
40549
  const { publicKey, privateKey } = rsaKeyPair();
40306
40550
  const generalNames = names.map((name) => import_node_net.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
40307
40551
  const der = assemble({
@@ -40322,11 +40566,11 @@ function issueLeafCertificate(ca2, names, notBefore, notAfter) {
40322
40566
  });
40323
40567
  return { certPem: toPem("CERTIFICATE", der), keyPem: keyPem(privateKey) };
40324
40568
  }
40325
- var import_node_crypto10, import_node_net, TAG_BOOLEAN, TAG_INTEGER, TAG_BIT_STRING, TAG_OCTET_STRING, TAG_NULL, TAG_OID, TAG_UTF8_STRING, TAG_UTC_TIME, TAG_GENERALIZED_TIME, TAG_SEQUENCE, TAG_SET, TAG_VERSION, TAG_EXTENSIONS, TAG_GENERAL_NAME_DNS, TAG_GENERAL_NAME_IP, TAG_KEY_IDENTIFIER, OID_COMMON_NAME, OID_SHA256_WITH_RSA, OID_SUBJECT_KEY_IDENTIFIER, OID_KEY_USAGE, OID_SUBJECT_ALT_NAME, OID_BASIC_CONSTRAINTS, OID_AUTHORITY_KEY_IDENTIFIER, OID_EXT_KEY_USAGE, OID_SERVER_AUTH, VERSION_3, SERIAL_NUMBER_BYTES, RSA_MODULUS_BITS, BITS_PER_BYTE, BYTE_MASK, HIGH_BIT, BASE_128_PAYLOAD_MASK, FIRST_ARC_WEIGHT, SHORT_FORM_MAX_LENGTH, MS_PER_SECOND6, UTC_TIME_LAST_YEAR, YEAR_DIGITS, TWO_DIGIT_YEAR_DIGITS, COMPACT_TIME_DIGITS, KEY_USAGE, SIGNATURE_ALGORITHM, IPV6_GROUPS, HEX_RADIX, BYTES_PER_IPV6_GROUP;
40569
+ var import_node_crypto11, import_node_net, TAG_BOOLEAN, TAG_INTEGER, TAG_BIT_STRING, TAG_OCTET_STRING, TAG_NULL, TAG_OID, TAG_UTF8_STRING, TAG_UTC_TIME, TAG_GENERALIZED_TIME, TAG_SEQUENCE, TAG_SET, TAG_VERSION, TAG_EXTENSIONS, TAG_GENERAL_NAME_DNS, TAG_GENERAL_NAME_IP, TAG_KEY_IDENTIFIER, OID_COMMON_NAME, OID_SHA256_WITH_RSA, OID_SUBJECT_KEY_IDENTIFIER, OID_KEY_USAGE, OID_SUBJECT_ALT_NAME, OID_BASIC_CONSTRAINTS, OID_AUTHORITY_KEY_IDENTIFIER, OID_EXT_KEY_USAGE, OID_SERVER_AUTH, VERSION_3, SERIAL_NUMBER_BYTES, RSA_MODULUS_BITS, BITS_PER_BYTE, BYTE_MASK, HIGH_BIT, BASE_128_PAYLOAD_MASK, FIRST_ARC_WEIGHT, SHORT_FORM_MAX_LENGTH, MS_PER_SECOND6, UTC_TIME_LAST_YEAR, YEAR_DIGITS, TWO_DIGIT_YEAR_DIGITS, COMPACT_TIME_DIGITS, KEY_USAGE, SIGNATURE_ALGORITHM, IPV6_GROUPS, HEX_RADIX, BYTES_PER_IPV6_GROUP;
40326
40570
  var init_x509 = __esm({
40327
40571
  "src/frontdoor/x509.ts"() {
40328
40572
  "use strict";
40329
- import_node_crypto10 = require("node:crypto");
40573
+ import_node_crypto11 = require("node:crypto");
40330
40574
  import_node_net = __toESM(require("node:net"), 1);
40331
40575
  TAG_BOOLEAN = 1;
40332
40576
  TAG_INTEGER = 2;
@@ -40449,23 +40693,23 @@ function capabilityFromProxyAuthorization(value3) {
40449
40693
  const password = userPass.slice(colon + 1);
40450
40694
  return password === "" ? void 0 : password;
40451
40695
  }
40452
- function digest(token) {
40453
- return (0, import_node_crypto11.createHash)("sha256").update(token, "utf8").digest();
40696
+ function digest2(token) {
40697
+ return (0, import_node_crypto12.createHash)("sha256").update(token, "utf8").digest();
40454
40698
  }
40455
40699
  function isLiveCapability(presented, live) {
40456
- const presentedDigest = digest(presented);
40700
+ const presentedDigest = digest2(presented);
40457
40701
  let matched = false;
40458
40702
  for (const token of live) {
40459
- const equal = (0, import_node_crypto11.timingSafeEqual)(presentedDigest, digest(token));
40703
+ const equal = (0, import_node_crypto12.timingSafeEqual)(presentedDigest, digest2(token));
40460
40704
  matched = equal || matched;
40461
40705
  }
40462
40706
  return matched;
40463
40707
  }
40464
- var import_node_crypto11, CONNECT_PROXY_USER, CONNECT_PROXY_REALM, BASIC_SCHEME;
40708
+ var import_node_crypto12, CONNECT_PROXY_USER, CONNECT_PROXY_REALM, BASIC_SCHEME;
40465
40709
  var init_capability = __esm({
40466
40710
  "src/frontdoor/capability.ts"() {
40467
40711
  "use strict";
40468
- import_node_crypto11 = require("node:crypto");
40712
+ import_node_crypto12 = require("node:crypto");
40469
40713
  CONNECT_PROXY_USER = "agent-shim";
40470
40714
  CONNECT_PROXY_REALM = "agent-shim front door";
40471
40715
  BASIC_SCHEME = "basic";
@@ -40815,8 +41059,8 @@ function ensureCa(store, generate) {
40815
41059
  }
40816
41060
  function caParses(ca2) {
40817
41061
  try {
40818
- new import_node_crypto12.X509Certificate(ca2.certPem);
40819
- (0, import_node_crypto12.createPrivateKey)(ca2.keyPem);
41062
+ new import_node_crypto13.X509Certificate(ca2.certPem);
41063
+ (0, import_node_crypto13.createPrivateKey)(ca2.keyPem);
40820
41064
  return true;
40821
41065
  } catch {
40822
41066
  return false;
@@ -41153,11 +41397,11 @@ function realConnectCertStore(paths) {
41153
41397
  }
41154
41398
  };
41155
41399
  }
41156
- var import_node_crypto12, fs14, CONNECT_INTERCEPT_HOST, CONNECT_INTERCEPT_HOSTS, CONNECT_TAP_HOSTS, ROUTED_PATH_PREFIX, HTTPS_PORT, HTTP_BAD_GATEWAY, CA_KEY_FILE_MODE, CONNECT_LINE_TOKENS, HEAD_TERMINATOR, MAX_CONNECT_HEAD_BYTES, CONNECT_ESTABLISHED, REFUSAL, CONNECT_LIMITS, CA_VALIDITY_DAYS, LEAF_VALIDITY_DAYS, CA_SUBJECT_COMMON_NAME, MS_PER_DAY2, HOP_BY_HOP_HEADERS, LOOPBACK_LEAF_NAMES, TAP_ALPN_PROTOCOLS;
41400
+ var import_node_crypto13, fs14, CONNECT_INTERCEPT_HOST, CONNECT_INTERCEPT_HOSTS, CONNECT_TAP_HOSTS, ROUTED_PATH_PREFIX, HTTPS_PORT, HTTP_BAD_GATEWAY, CA_KEY_FILE_MODE, CONNECT_LINE_TOKENS, HEAD_TERMINATOR, MAX_CONNECT_HEAD_BYTES, CONNECT_ESTABLISHED, REFUSAL, CONNECT_LIMITS, CA_VALIDITY_DAYS, LEAF_VALIDITY_DAYS, CA_SUBJECT_COMMON_NAME, MS_PER_DAY2, HOP_BY_HOP_HEADERS, LOOPBACK_LEAF_NAMES, TAP_ALPN_PROTOCOLS;
41157
41401
  var init_connect = __esm({
41158
41402
  "src/frontdoor/connect.ts"() {
41159
41403
  "use strict";
41160
- import_node_crypto12 = require("node:crypto");
41404
+ import_node_crypto13 = require("node:crypto");
41161
41405
  fs14 = __toESM(require("node:fs"), 1);
41162
41406
  init_x509();
41163
41407
  init_tap();
@@ -41989,7 +42233,7 @@ var init_package = __esm({
41989
42233
  "package.json"() {
41990
42234
  package_default = {
41991
42235
  name: "claude-use",
41992
- version: "12.0.0",
42236
+ version: "12.0.1",
41993
42237
  description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
41994
42238
  license: "MIT",
41995
42239
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -42162,221 +42406,6 @@ var init_claudeVersion = __esm({
42162
42406
  }
42163
42407
  });
42164
42408
 
42165
- // src/headroom/headers.ts
42166
- function mergeAnthropicCustomHeaders(existing, additions) {
42167
- const merged = /* @__PURE__ */ new Map();
42168
- for (const block2 of existing) {
42169
- if (block2 === void 0) {
42170
- continue;
42171
- }
42172
- for (const line of block2.split("\n")) {
42173
- const entry = parseCustomHeaderLine(line);
42174
- if (entry === void 0) {
42175
- continue;
42176
- }
42177
- merged.set(entry.name, entry.value);
42178
- }
42179
- }
42180
- for (const entry of additions) {
42181
- merged.set(entry.name, entry.value);
42182
- }
42183
- return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
42184
- }
42185
- function parseAnthropicCustomHeaders(block2) {
42186
- return block2.split("\n").flatMap((line) => {
42187
- const entry = parseCustomHeaderLine(line);
42188
- return entry === void 0 ? [] : [entry];
42189
- });
42190
- }
42191
- function withoutAnthropicCustomHeaders(block2, remove) {
42192
- const lines = block2.split("\n");
42193
- const kept = lines.filter((line) => {
42194
- const entry = parseCustomHeaderLine(line);
42195
- return entry === void 0 || !remove(entry);
42196
- });
42197
- return kept.length === lines.length ? block2 : kept.join("\n");
42198
- }
42199
- function parseCustomHeaderLine(line) {
42200
- const trimmed = line.trim();
42201
- if (trimmed === "") {
42202
- return void 0;
42203
- }
42204
- const colon = trimmed.indexOf(":");
42205
- if (colon <= 0) {
42206
- return void 0;
42207
- }
42208
- return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
42209
- }
42210
- var init_headers = __esm({
42211
- "src/headroom/headers.ts"() {
42212
- "use strict";
42213
- }
42214
- });
42215
-
42216
- // src/launcher/injected.ts
42217
- function listKey(list2) {
42218
- return `${list2},appended`;
42219
- }
42220
- function digest2(value3) {
42221
- return (0, import_node_crypto13.createHash)("sha256").update(value3).digest("hex");
42222
- }
42223
- function recordedDigests(env) {
42224
- const raw = env[INJECTED_ENV];
42225
- if (raw === void 0 || raw === "") {
42226
- return {};
42227
- }
42228
- let parsed;
42229
- try {
42230
- parsed = JSON.parse(raw);
42231
- } catch {
42232
- return {};
42233
- }
42234
- const result = InjectedSchema.safeParse(parsed);
42235
- return result.success ? result.data : {};
42236
- }
42237
- function recordInjections(base) {
42238
- const env = { ...base };
42239
- const digests = new Map(Object.entries(recordedDigests(env)));
42240
- return {
42241
- env,
42242
- set: (name, value3) => {
42243
- env[name] = value3;
42244
- digests.set(name, digest2(value3));
42245
- },
42246
- unset: (name) => {
42247
- env[name] = void 0;
42248
- digests.delete(name);
42249
- },
42250
- recordHeaders: (names) => {
42251
- const block2 = env[CUSTOM_HEADERS_ENV];
42252
- for (const entry of block2 === void 0 ? [] : parseAnthropicCustomHeaders(block2)) {
42253
- if (names.includes(entry.name)) {
42254
- digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
42255
- }
42256
- }
42257
- },
42258
- recordBypassHosts: (list2, hosts) => {
42259
- const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list2))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
42260
- if (recordedHosts.length > 0) {
42261
- digests.set(listKey(list2), recordedHosts.join(","));
42262
- }
42263
- },
42264
- finish: () => {
42265
- if (digests.size > 0) {
42266
- env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
42267
- }
42268
- }
42269
- };
42270
- }
42271
- function withoutRecordedHosts(list2, value3, digests) {
42272
- const recordedHosts = new Set(digests[listKey(list2)]?.split(","));
42273
- const entries = value3.split(",");
42274
- const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
42275
- return kept.length === entries.length ? value3 : kept.join(",");
42276
- }
42277
- function launchEnvironment(env, configDirEscapeHatch) {
42278
- return configDirEscapeHatch ? env : withoutInjected(env);
42279
- }
42280
- function withoutInjected(env) {
42281
- const digests = recordedDigests(env);
42282
- const entries = Object.entries(env).flatMap(([name, value3]) => {
42283
- if (name === INJECTED_ENV) {
42284
- return [];
42285
- }
42286
- if (value3 === void 0) {
42287
- return [[name, value3]];
42288
- }
42289
- if (name === CUSTOM_HEADERS_ENV) {
42290
- const remaining = withoutAnthropicCustomHeaders(value3, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
42291
- return remaining !== value3 && remaining.trim() === "" ? [] : [[name, remaining]];
42292
- }
42293
- if (name === "NO_PROXY" || name === "no_proxy") {
42294
- const remaining = withoutRecordedHosts(name, value3, digests);
42295
- return remaining !== value3 && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
42296
- }
42297
- return digests[name] === digest2(value3) ? [] : [[name, value3]];
42298
- });
42299
- return Object.fromEntries(entries);
42300
- }
42301
- var import_node_crypto13, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
42302
- var init_injected = __esm({
42303
- "src/launcher/injected.ts"() {
42304
- "use strict";
42305
- import_node_crypto13 = require("node:crypto");
42306
- init_zod();
42307
- init_headers();
42308
- INJECTED_ENV = "AGENT_SHIM_INJECTED";
42309
- CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
42310
- HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
42311
- InjectedSchema = external_exports.record(external_exports.string(), external_exports.string());
42312
- }
42313
- });
42314
-
42315
- // src/launcher/guard.ts
42316
- function detectAmbientCredential(env, injected) {
42317
- for (const variable of AMBIENT_CREDENTIAL_VARS) {
42318
- const value3 = env[variable];
42319
- if (value3 === void 0 || value3 === "") {
42320
- continue;
42321
- }
42322
- if (injected?.variable === variable && value3 === injected.token) {
42323
- continue;
42324
- }
42325
- return { variable };
42326
- }
42327
- return void 0;
42328
- }
42329
- function formatAmbientCredentialGuardMessage(variable, identityName) {
42330
- const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
42331
- return [
42332
- `error: ${variable} is set in the environment. This identity's isolated`,
42333
- "credential would be bypassed \u2014 every identity authenticates as this same key",
42334
- "while it's set. Unset it, or if this is deliberate, opt in per-launch with",
42335
- "AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
42336
- `\`${identitySetCommand}\`.`
42337
- ].join("\n");
42338
- }
42339
- function evaluateAmbientCredentialGuard(params) {
42340
- const detected = detectAmbientCredential(params.env, params.injectedCredential);
42341
- if (detected === void 0) {
42342
- return { ok: true };
42343
- }
42344
- if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
42345
- return { ok: true };
42346
- }
42347
- return {
42348
- ok: false,
42349
- variable: detected.variable,
42350
- message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
42351
- };
42352
- }
42353
- function ambientCredentialFinding(env) {
42354
- const named = detectAmbientCredential(launchEnvironment(env, false));
42355
- if (named !== void 0) {
42356
- return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
42357
- }
42358
- const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
42359
- if (bare !== void 0) {
42360
- return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
42361
- }
42362
- return { severity: "pass", message: "No ambient-credential environment variable is set." };
42363
- }
42364
- var AMBIENT_CREDENTIAL_VARS;
42365
- var init_guard = __esm({
42366
- "src/launcher/guard.ts"() {
42367
- "use strict";
42368
- init_injected();
42369
- AMBIENT_CREDENTIAL_VARS = [
42370
- "ANTHROPIC_API_KEY",
42371
- "ANTHROPIC_AUTH_TOKEN",
42372
- "CLAUDE_CODE_OAUTH_TOKEN",
42373
- "CLAUDE_CODE_USE_BEDROCK",
42374
- "CLAUDE_CODE_USE_VERTEX",
42375
- "CLAUDE_CODE_USE_FOUNDRY"
42376
- ];
42377
- }
42378
- });
42379
-
42380
42409
  // node_modules/.pnpm/undici@7.30.1/node_modules/undici/lib/core/symbols.js
42381
42410
  var require_symbols = __commonJS({
42382
42411
  "node_modules/.pnpm/undici@7.30.1/node_modules/undici/lib/core/symbols.js"(exports2, module2) {
@@ -73234,10 +73263,22 @@ function decideLaunch(params, readOnly, onRecorded) {
73234
73263
  ...parsedArgv.delay === void 0 ? {} : { delay: parsedArgv.delay }
73235
73264
  }
73236
73265
  });
73237
- const loginlessProvider = requestedFlags.remoteControl && selectedProvider !== void 0 && farmIdentity !== void 0 && identityDecision.name !== void 0 && params.hasStoredLogin?.(farmIdentity) === false ? { identity: identityDecision.name, provider: selectedProvider.name } : void 0;
73266
+ const loginlessProvider = (() => {
73267
+ if (!requestedFlags.remoteControl || selectedProvider === void 0 || farmIdentity === void 0 || identityDecision.name === void 0) {
73268
+ return void 0;
73269
+ }
73270
+ const stored2 = params.hasStoredLogin?.(farmIdentity);
73271
+ if (stored2 === false) {
73272
+ return { identity: identityDecision.name, provider: selectedProvider.name, why: "has no stored login" };
73273
+ }
73274
+ if (stored2 === true && params.hasUsableLogin?.(farmIdentity, discovered.path) === false) {
73275
+ return { identity: identityDecision.name, provider: selectedProvider.name, why: "has a stored login that is no longer usable" };
73276
+ }
73277
+ return void 0;
73278
+ })();
73238
73279
  const notes = [];
73239
73280
  if (loginlessProvider !== void 0) {
73240
- notes.push(`${loginlessProvider.identity} has no stored login, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
73281
+ notes.push(`${loginlessProvider.identity} ${loginlessProvider.why}, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
73241
73282
  }
73242
73283
  const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
73243
73284
  const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
@@ -73700,6 +73741,7 @@ function realPrepareLaunchParams(paths, options) {
73700
73741
  credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
73701
73742
  hold: realHoldPort,
73702
73743
  hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path59.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
73744
+ hasUsableLogin: (identity, claudeBin) => storedLoginUsable(options.run ?? realRunPort, claudeBin, import_node_path59.default.join(paths.identitiesDir, identity), options.proc.env),
73703
73745
  ...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
73704
73746
  ...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
73705
73747
  ...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },