@rse/claudex 1.1.0 → 1.1.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.
Files changed (3) hide show
  1. package/claudex.js +38 -18
  2. package/claudex.ts +42 -18
  3. package/package.json +1 -1
package/claudex.js CHANGED
@@ -164,7 +164,7 @@ const execInherit = (file, args, opts = {}) => {
164
164
  process.exit(r.exitCode ?? 1);
165
165
  };
166
166
  /* helper to execute a platform-specific command */
167
- const executeCommand = (config, platformOverride) => {
167
+ const executeCommand = (config, platformOverride, fatalOnFailure = false) => {
168
168
  const platform = platformOverride ?? detectPlatform();
169
169
  const osName = platform.split(":")[0];
170
170
  const command = config[platform] ?? config[`${osName}:*`] ?? config["*"];
@@ -178,7 +178,10 @@ const executeCommand = (config, platformOverride) => {
178
178
  reject: false,
179
179
  windowsHide: false
180
180
  });
181
- return result.exitCode ?? 1;
181
+ const exitCode = result.exitCode ?? 1;
182
+ if (fatalOnFailure && exitCode !== 0)
183
+ fatal(`failed to execute "${cmd[0]}" (exit ${exitCode})`);
184
+ return exitCode;
182
185
  };
183
186
  /* helper to update an externally managed tool with exactly the package
184
187
  manager which actually provides it, instead of just the preferred one */
@@ -188,7 +191,7 @@ const updateTool = (tool, config) => {
188
191
  info(`skip update of "${tool}" (not provided by MacPorts or Homebrew)`);
189
192
  return 0;
190
193
  }
191
- return executeCommand(config, platform);
194
+ return executeCommand(config, platform, true);
192
195
  };
193
196
  /* helper to determine whether a global NPM installation requires sudo(8),
194
197
  i.e., whether the target directories of the NPM global prefix are not
@@ -355,7 +358,7 @@ const actionInstall = async (capsula) => {
355
358
  await self("internal", "capsula", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "nodejs");
356
359
  await self("internal", "capsula", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "binutils", "gcc", "g++", "make");
357
360
  info("install Claude Code");
358
- await self("internal", "capsula", "bash", "-o", "pipefail", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -fsSL https://claude.ai/install.sh | bash`);
361
+ await self("internal", "capsula", "bash", "-o", "pipefail", "-c", `PATH=${shQ.quote([path.join(HOME, ".local/bin")])}:"$PATH"; curl -fsSL https://claude.ai/install.sh | bash`);
359
362
  info("install ANSI-Recolor");
360
363
  await self("internal", "capsula", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "--allow-scripts=node-pty,tty-attr", "ansi-recolor");
361
364
  info("install TypeScript LS");
@@ -477,7 +480,7 @@ const actionInstall = async (capsula) => {
477
480
  /* run installation script */
478
481
  ensureTool("bash", { hint: "https://www.gnu.org/software/bash/" });
479
482
  ensureTool("curl", { hint: "https://curl.se/" });
480
- await execa("bash", ["-o", "pipefail", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -fsSL https://claude.ai/install.sh | bash`], {
483
+ await execa("bash", ["-o", "pipefail", "-c", `PATH=${shQ.quote([path.join(HOME, ".local/bin")])}:"$PATH"; curl -fsSL https://claude.ai/install.sh | bash`], {
481
484
  stdio: "inherit"
482
485
  });
483
486
  /* prune obsolete versions only after successful install */
@@ -515,7 +518,7 @@ const actionUpdate = async (capsula) => {
515
518
  await self("internal", "capsula", "-s", "sudo", "apt", "update", "-qq");
516
519
  await self("internal", "capsula", "-s", "sudo", "apt", "upgrade", "-qq", "-y");
517
520
  info("update Claude Code");
518
- await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`);
521
+ await self("internal", "capsula", "bash", "-c", `PATH=${shQ.quote([path.join(HOME, ".local/bin")])}:"$PATH"; ${shQ.quote([path.join(HOME, ".local/bin/claude")])} update`);
519
522
  info("update ANSI-Recolor");
520
523
  await self("internal", "capsula", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "--allow-scripts=node-pty,tty-attr", "ansi-recolor");
521
524
  info("update TypeScript LS");
@@ -583,23 +586,23 @@ const actionUpdate = async (capsula) => {
583
586
  info("update ANSI-Recolor");
584
587
  executeCommand({
585
588
  "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
586
- });
589
+ }, undefined, true);
587
590
  info("update TypeScript-Language-Server");
588
591
  executeCommand({
589
592
  "*": npmInstallGlobal("typescript-language-server")
590
- });
593
+ }, undefined, true);
591
594
  info("update CodeBurn");
592
595
  executeCommand({
593
596
  "*": npmInstallGlobal("codeburn")
594
- });
597
+ }, undefined, true);
595
598
  info("update ASE");
596
599
  executeCommand({
597
600
  "*": npmInstallGlobal("@rse/ase")
598
- });
601
+ }, undefined, true);
599
602
  info("update Claude Code");
600
603
  if (process.platform !== "win32") {
601
604
  ensureTool("bash");
602
- await execa("bash", ["-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`], {
605
+ await execa("bash", ["-c", `PATH=${shQ.quote([path.join(HOME, ".local/bin")])}:"$PATH"; ${shQ.quote([path.join(HOME, ".local/bin/claude")])} update`], {
603
606
  stdio: "inherit"
604
607
  });
605
608
  /* prune obsolete versions only after successful update */
@@ -676,6 +679,10 @@ const actionInternalTmux = (opts, args) => {
676
679
  process.on("exit", cleanup);
677
680
  process.on("SIGINT", () => { cleanup(); process.exit(130); });
678
681
  process.on("SIGTERM", () => { cleanup(); process.exit(143); });
682
+ /* pass each new Unix session its own invocation environment */
683
+ if (!isPsmux() && args[0] === "new-session")
684
+ for (const name of ["CLAUDEX_FLAGS", "CLAUDEX_INTERNAL_EXEC", "CLAUDE_MODEL", "OPENROUTER_API_KEY"])
685
+ args.splice(1, 0, "-e", `${name}=${process.env[name] ?? ""}`);
679
686
  const r = execaSync("tmux", [
680
687
  "-f", confFile,
681
688
  ...args
@@ -1178,7 +1185,7 @@ const actionDefault = async (opts, args) => {
1178
1185
  ]
1179
1186
  }
1180
1187
  };
1181
- if (opts.tmux) {
1188
+ if (process.env.TMUX) {
1182
1189
  claudeSettings = deepmerge(claudeSettings, {
1183
1190
  "env": {
1184
1191
  "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
@@ -1249,12 +1256,12 @@ const main = async () => {
1249
1256
  the top-level "-R"/"-C"/"-T"/"-A" flags by default. Merge env-derived
1250
1257
  flags with the command-line flags (env first, command-line second, so
1251
1258
  the user can extend or override on the command line). Skip for the
1252
- "internal" sub-dispatch (which uses CLAUDEX_FLAGS_PASSTHROUGH for
1253
- tmux.conf bind-key flag propagation), and skip flags that are already
1254
- present on argv to avoid duplicating boolean options. */
1259
+ "internal" sub-dispatch; tmux.conf bind-keys invoke plain "claudex",
1260
+ whose defaults come from CLAUDEX_FLAGS. Skip flags already present
1261
+ on argv to avoid duplicating boolean options. */
1255
1262
  {
1256
1263
  const topArgs = process.argv.slice(2);
1257
- const subcmd = topArgs.find((a) => !a.startsWith("-")) ?? "";
1264
+ const subcmd = topArgs.find((a, i) => !a.startsWith("-") && (i === 0 || (topArgs[i - 1] !== "-T" && topArgs[i - 1] !== "--tmux"))) ?? "";
1258
1265
  const envFlags = (process.env.CLAUDEX_FLAGS ?? "").trim();
1259
1266
  const claudeNativeSubcmds = [
1260
1267
  "agents", "auth", "auto-mode", "doctor", "mcp",
@@ -1295,7 +1302,19 @@ const main = async () => {
1295
1302
  filtered.push(t);
1296
1303
  }
1297
1304
  /* insert in front of the other arguments */
1298
- const toInsert = filtered.filter((t) => !present(t));
1305
+ const toInsert = [];
1306
+ for (let i = 0; i < filtered.length; i++) {
1307
+ const t = filtered[i];
1308
+ const hasSession = (t === "-T" || t === "--tmux")
1309
+ && i + 1 < filtered.length && !filtered[i + 1].startsWith("-");
1310
+ if (!present(t)) {
1311
+ toInsert.push(t);
1312
+ if (hasSession)
1313
+ toInsert.push(filtered[i + 1]);
1314
+ }
1315
+ if (hasSession)
1316
+ i++;
1317
+ }
1299
1318
  if (toInsert.length > 0)
1300
1319
  process.argv.splice(2, 0, ...toInsert);
1301
1320
  }
@@ -1303,7 +1322,7 @@ const main = async () => {
1303
1322
  /* intercept top-level "-h/--help" and "-v/-V/--version" before commander
1304
1323
  grabs them, so we can pass-through to "claude" and append our extension info */
1305
1324
  const topArgs = process.argv.slice(2);
1306
- const firstNonFlag = topArgs.findIndex((a) => !a.startsWith("-"));
1325
+ const firstNonFlag = topArgs.findIndex((a, i) => !a.startsWith("-") && (i === 0 || (topArgs[i - 1] !== "-T" && topArgs[i - 1] !== "--tmux")));
1307
1326
  const headFlags = firstNonFlag < 0 ? topArgs : topArgs.slice(0, firstNonFlag);
1308
1327
  const subcmd = firstNonFlag < 0 ? "" : topArgs[firstNonFlag];
1309
1328
  if ((headFlags.includes("-h") || headFlags.includes("--help"))
@@ -1362,6 +1381,7 @@ const main = async () => {
1362
1381
  .command("internal")
1363
1382
  .description("internal command dispatcher (tmux, shell, lazygit, ase-task-edit, capsula)")
1364
1383
  .helpOption("-h, --help", "display help for command")
1384
+ .passThroughOptions()
1365
1385
  .allowUnknownOption()
1366
1386
  .argument("[args...]", "internal command name and its arguments")
1367
1387
  .action(async (args, _opts, cmd) => {
package/claudex.ts CHANGED
@@ -184,7 +184,7 @@ const execInherit = (file: string, args: string[], opts: { env?: Env } = {}): ne
184
184
  }
185
185
 
186
186
  /* helper to execute a platform-specific command */
187
- const executeCommand = (config: { [ platform: string ]: string[] | string }, platformOverride?: string) => {
187
+ const executeCommand = (config: { [ platform: string ]: string[] | string }, platformOverride?: string, fatalOnFailure = false) => {
188
188
  const platform = platformOverride ?? detectPlatform()
189
189
  const osName = platform.split(":")[0]
190
190
  const command = config[platform] ?? config[`${osName}:*`] ?? config["*"]
@@ -198,7 +198,10 @@ const executeCommand = (config: { [ platform: string ]: string[] | string }, pla
198
198
  reject: false,
199
199
  windowsHide: false
200
200
  })
201
- return result.exitCode ?? 1
201
+ const exitCode = result.exitCode ?? 1
202
+ if (fatalOnFailure && exitCode !== 0)
203
+ fatal(`failed to execute "${cmd[0]}" (exit ${exitCode})`)
204
+ return exitCode
202
205
  }
203
206
 
204
207
  /* helper to update an externally managed tool with exactly the package
@@ -209,7 +212,7 @@ const updateTool = (tool: string, config: { [ platform: string ]: string[] | str
209
212
  info(`skip update of "${tool}" (not provided by MacPorts or Homebrew)`)
210
213
  return 0
211
214
  }
212
- return executeCommand(config, platform)
215
+ return executeCommand(config, platform, true)
213
216
  }
214
217
 
215
218
  /* helper to determine whether a global NPM installation requires sudo(8),
@@ -403,7 +406,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
403
406
  await self("internal", "capsula", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "binutils", "gcc", "g++", "make")
404
407
 
405
408
  info("install Claude Code")
406
- await self("internal", "capsula", "bash", "-o", "pipefail", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -fsSL https://claude.ai/install.sh | bash`)
409
+ await self("internal", "capsula", "bash", "-o", "pipefail", "-c", `PATH=${shQ.quote([ path.join(HOME, ".local/bin") ])}:"$PATH"; curl -fsSL https://claude.ai/install.sh | bash`)
407
410
 
408
411
  info("install ANSI-Recolor")
409
412
  await self("internal", "capsula", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "--allow-scripts=node-pty,tty-attr", "ansi-recolor")
@@ -542,7 +545,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
542
545
  /* run installation script */
543
546
  ensureTool("bash", { hint: "https://www.gnu.org/software/bash/" })
544
547
  ensureTool("curl", { hint: "https://curl.se/" })
545
- await execa("bash", [ "-o", "pipefail", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -fsSL https://claude.ai/install.sh | bash` ], {
548
+ await execa("bash", [ "-o", "pipefail", "-c", `PATH=${shQ.quote([ path.join(HOME, ".local/bin") ])}:"$PATH"; curl -fsSL https://claude.ai/install.sh | bash` ], {
546
549
  stdio: "inherit"
547
550
  })
548
551
 
@@ -587,7 +590,7 @@ const actionUpdate = async (capsula: boolean): Promise<void> => {
587
590
  await self("internal", "capsula", "-s", "sudo", "apt", "upgrade", "-qq", "-y")
588
591
 
589
592
  info("update Claude Code")
590
- await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`)
593
+ await self("internal", "capsula", "bash", "-c", `PATH=${shQ.quote([ path.join(HOME, ".local/bin") ])}:"$PATH"; ${shQ.quote([ path.join(HOME, ".local/bin/claude") ])} update`)
591
594
 
592
595
  info("update ANSI-Recolor")
593
596
  await self("internal", "capsula", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "--allow-scripts=node-pty,tty-attr", "ansi-recolor")
@@ -664,27 +667,27 @@ const actionUpdate = async (capsula: boolean): Promise<void> => {
664
667
  info("update ANSI-Recolor")
665
668
  executeCommand({
666
669
  "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
667
- })
670
+ }, undefined, true)
668
671
 
669
672
  info("update TypeScript-Language-Server")
670
673
  executeCommand({
671
674
  "*": npmInstallGlobal("typescript-language-server")
672
- })
675
+ }, undefined, true)
673
676
 
674
677
  info("update CodeBurn")
675
678
  executeCommand({
676
679
  "*": npmInstallGlobal("codeburn")
677
- })
680
+ }, undefined, true)
678
681
 
679
682
  info("update ASE")
680
683
  executeCommand({
681
684
  "*": npmInstallGlobal("@rse/ase")
682
- })
685
+ }, undefined, true)
683
686
 
684
687
  info("update Claude Code")
685
688
  if (process.platform !== "win32") {
686
689
  ensureTool("bash")
687
- await execa("bash", [ "-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update` ], {
690
+ await execa("bash", [ "-c", `PATH=${shQ.quote([ path.join(HOME, ".local/bin") ])}:"$PATH"; ${shQ.quote([ path.join(HOME, ".local/bin/claude") ])} update` ], {
688
691
  stdio: "inherit"
689
692
  })
690
693
 
@@ -762,6 +765,12 @@ const actionInternalTmux = (opts: TopOpts, args: string[]): never => {
762
765
  process.on("exit", cleanup)
763
766
  process.on("SIGINT", () => { cleanup(); process.exit(130) })
764
767
  process.on("SIGTERM", () => { cleanup(); process.exit(143) })
768
+
769
+ /* pass each new Unix session its own invocation environment */
770
+ if (!isPsmux() && args[0] === "new-session")
771
+ for (const name of [ "CLAUDEX_FLAGS", "CLAUDEX_INTERNAL_EXEC", "CLAUDE_MODEL", "OPENROUTER_API_KEY" ])
772
+ args.splice(1, 0, "-e", `${name}=${process.env[name] ?? ""}`)
773
+
765
774
  const r = execaSync("tmux", [
766
775
  "-f", confFile,
767
776
  ...args
@@ -1286,7 +1295,7 @@ const actionDefault = async (opts: TopOpts, args: string[]): Promise<never> => {
1286
1295
  ]
1287
1296
  }
1288
1297
  } as Record<string, unknown>
1289
- if (opts.tmux) {
1298
+ if (process.env.TMUX) {
1290
1299
  claudeSettings = deepmerge(claudeSettings, {
1291
1300
  "env": {
1292
1301
  "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
@@ -1365,12 +1374,13 @@ const main = async (): Promise<void> => {
1365
1374
  the top-level "-R"/"-C"/"-T"/"-A" flags by default. Merge env-derived
1366
1375
  flags with the command-line flags (env first, command-line second, so
1367
1376
  the user can extend or override on the command line). Skip for the
1368
- "internal" sub-dispatch (which uses CLAUDEX_FLAGS_PASSTHROUGH for
1369
- tmux.conf bind-key flag propagation), and skip flags that are already
1370
- present on argv to avoid duplicating boolean options. */
1377
+ "internal" sub-dispatch; tmux.conf bind-keys invoke plain "claudex",
1378
+ whose defaults come from CLAUDEX_FLAGS. Skip flags already present
1379
+ on argv to avoid duplicating boolean options. */
1371
1380
  {
1372
1381
  const topArgs = process.argv.slice(2)
1373
- const subcmd = topArgs.find((a) => !a.startsWith("-")) ?? ""
1382
+ const subcmd = topArgs.find((a, i) =>
1383
+ !a.startsWith("-") && (i === 0 || (topArgs[i - 1] !== "-T" && topArgs[i - 1] !== "--tmux"))) ?? ""
1374
1384
  const envFlags = (process.env.CLAUDEX_FLAGS ?? "").trim()
1375
1385
  const claudeNativeSubcmds = [
1376
1386
  "agents", "auth", "auto-mode", "doctor", "mcp",
@@ -1414,7 +1424,19 @@ const main = async (): Promise<void> => {
1414
1424
  }
1415
1425
 
1416
1426
  /* insert in front of the other arguments */
1417
- const toInsert = filtered.filter((t) => !present(t))
1427
+ const toInsert: string[] = []
1428
+ for (let i = 0; i < filtered.length; i++) {
1429
+ const t = filtered[i]
1430
+ const hasSession = (t === "-T" || t === "--tmux")
1431
+ && i + 1 < filtered.length && !filtered[i + 1].startsWith("-")
1432
+ if (!present(t)) {
1433
+ toInsert.push(t)
1434
+ if (hasSession)
1435
+ toInsert.push(filtered[i + 1])
1436
+ }
1437
+ if (hasSession)
1438
+ i++
1439
+ }
1418
1440
  if (toInsert.length > 0)
1419
1441
  process.argv.splice(2, 0, ...toInsert)
1420
1442
  }
@@ -1423,7 +1445,8 @@ const main = async (): Promise<void> => {
1423
1445
  /* intercept top-level "-h/--help" and "-v/-V/--version" before commander
1424
1446
  grabs them, so we can pass-through to "claude" and append our extension info */
1425
1447
  const topArgs = process.argv.slice(2)
1426
- const firstNonFlag = topArgs.findIndex((a) => !a.startsWith("-"))
1448
+ const firstNonFlag = topArgs.findIndex((a, i) =>
1449
+ !a.startsWith("-") && (i === 0 || (topArgs[i - 1] !== "-T" && topArgs[i - 1] !== "--tmux")))
1427
1450
  const headFlags = firstNonFlag < 0 ? topArgs : topArgs.slice(0, firstNonFlag)
1428
1451
  const subcmd = firstNonFlag < 0 ? "" : topArgs[firstNonFlag]
1429
1452
  if ((headFlags.includes("-h") || headFlags.includes("--help"))
@@ -1487,6 +1510,7 @@ const main = async (): Promise<void> => {
1487
1510
  .command("internal")
1488
1511
  .description("internal command dispatcher (tmux, shell, lazygit, ase-task-edit, capsula)")
1489
1512
  .helpOption("-h, --help", "display help for command")
1513
+ .passThroughOptions()
1490
1514
  .allowUnknownOption()
1491
1515
  .argument("[args...]", "internal command name and its arguments")
1492
1516
  .action(async (args: string[], _opts: object, cmd: Command) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rse/claudex",
3
3
  "publishConfig": { "access": "public" },
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "Claude Code eXtended",
6
6
  "type": "module",
7
7
  "keywords": [ "claude", "code", "extension", "wrapper" ],