@rse/claudex 0.9.21 → 0.9.22

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
  ChangeLog
3
3
  =========
4
4
 
5
+ 0.9.22 (2026-05-09)
6
+ -------------------
7
+
8
+ - BUGFIX: fix building under Windows
9
+ - BUGFIX: workaround shell argument escaping and tmux argument parsing problems under Windows
10
+ - BUGFIX: fix internal script invocation
11
+ - CLEANUP: record CHANGELOG entry for previous change
12
+
5
13
  0.9.21 (2026-05-09)
6
14
  -------------------
7
15
 
package/claudex.js CHANGED
@@ -12,6 +12,7 @@ import which from "which";
12
12
  import chalk from "chalk";
13
13
  import deepmerge from "deepmerge";
14
14
  import { Command } from "commander";
15
+ import * as shQ from "shell-quote";
15
16
  /* determine our base directory (handle absolute, relative, PATH, symlinks) */
16
17
  const findBaseDir = () => {
17
18
  const argv1 = process.argv[1] ?? "";
@@ -150,10 +151,6 @@ const ensureTool = (tool, options = {}) => {
150
151
  fatal(`required tool "${tool}" not found in $PATH`);
151
152
  }
152
153
  };
153
- /* helper to POSIX-single-quote-escape a string for safe interpolation
154
- into a "bash -c" command line (defense against shell injection of
155
- user-supplied or env-derived values) */
156
- const shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
157
154
  /* re-invoke this same script (mirrors "$0 ..." in Bash) */
158
155
  const self = async (...args) => {
159
156
  const r = await execa(process.execPath, [selfPathJS, ...args], {
@@ -457,7 +454,7 @@ const actionInternalTmux = (args) => {
457
454
  ensureTool("tmux");
458
455
  const claudexFlags = process.env.CLAUDEX_FLAGS_PASSTHROUGH ?? "";
459
456
  const conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
460
- .replace(/@CLAUDEX@/g, `${shq(process.execPath)} ${shq(selfPathJS)}`)
457
+ .replace(/@CLAUDEX@/g, `${shQ.quote([process.execPath, selfPathJS])}`)
461
458
  .replace(/@CLAUDEX_FLAGS_PASSTHROUGH@/g, claudexFlags);
462
459
  const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`);
463
460
  fs.writeFileSync(confFile, conf, { mode: 0o600 });
@@ -609,7 +606,32 @@ const actionInternalCapsula = (args) => {
609
606
  ...args
610
607
  ]);
611
608
  };
612
- /* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula) */
609
+ /* action: internal "exec" -- execute a command supplied via the
610
+ $CLAUDEX_INTERNAL_EXEC environment variable. The variable value is split
611
+ into argv via shell-quote (honoring '..' and ".." quoting, no shell
612
+ expansion of operators), and then the resulting command is run with stdio
613
+ inherited. This indirection exists to work around platforms (notably
614
+ Windows tmux) that mishandle quoting when a command is passed via "tmux
615
+ new-session" as multiple trailing argv items: we instead pass the whole
616
+ command as a single env-var value. */
617
+ const actionInternalExec = () => {
618
+ const cmdline = process.env.CLAUDEX_INTERNAL_EXEC ?? "";
619
+ if (cmdline === "")
620
+ fatal("CLAUDEX_INTERNAL_EXEC environment variable is empty or unset");
621
+ const parsed = shQ.parse(cmdline);
622
+ const argv = [];
623
+ for (const tok of parsed) {
624
+ if (typeof tok === "string")
625
+ argv.push(tok);
626
+ else
627
+ fatal("CLAUDEX_INTERNAL_EXEC contains unsupported shell construct (operators, globs, or env-var expansion are not allowed)");
628
+ }
629
+ if (argv.length === 0)
630
+ fatal("CLAUDEX_INTERNAL_EXEC contains no command to execute");
631
+ const [file, ...rest] = argv;
632
+ return execInherit(file, rest);
633
+ };
634
+ /* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula, exec) */
613
635
  const actionInternal = async (opts, args) => {
614
636
  const util = args[0];
615
637
  const rest = args.slice(1);
@@ -619,6 +641,7 @@ const actionInternal = async (opts, args) => {
619
641
  case "ase-task-edit": return actionInternalAseTaskEdit();
620
642
  case "lazygit": return actionInternalLazygit(opts.recolor === true, rest);
621
643
  case "capsula": return actionInternalCapsula(rest);
644
+ case "exec": return actionInternalExec();
622
645
  default:
623
646
  fatal(`invalid internal command "${util ?? ""}"`);
624
647
  }
@@ -644,17 +667,10 @@ const actionDefault = (opts, args) => {
644
667
  else
645
668
  session = detectSessionName();
646
669
  const rest = args;
647
- /* build the in-pane self-invocation shell string */
648
- const inPane = [
649
- shq(process.execPath),
650
- shq(selfPathJS),
651
- ...innerFlags.map(shq),
652
- ...rest.map(shq)
653
- ].join(" ");
654
- /* propagate the chosen pass-through flags to "internal tmux" so its
655
- tmux.conf bind-keys spawn new claude panes with the same flags */
670
+ /* build the in-pane self-invocation */
671
+ const inPane = shQ.quote([process.execPath, selfPathJS, ...innerFlags, ...rest]);
672
+ /* propagate the chosen pass-through flags to "internal tmux" */
656
673
  const claudexFlags = innerFlags.join(" ");
657
- process.env.CLAUDEX_FLAGS_PASSTHROUGH = claudexFlags;
658
674
  /* dispatch according to global options */
659
675
  if (opts.capsula) {
660
676
  /* enter/start container, then run tmux inside it */
@@ -669,7 +685,12 @@ const actionDefault = (opts, args) => {
669
685
  return execInherit("docker", [
670
686
  "exec", "-i", "-t", container,
671
687
  "bash", "-c",
672
- `TERM=${shq(TERM)} HOME=${shq(HOME)} CLAUDEX_FLAGS_PASSTHROUGH=${shq(claudexFlags)} sudo -E -u ${shq(USER)} ${shq(process.execPath)} ${shq(selfPathJS)} internal tmux new-session -A -s ${shq(session)}`
688
+ `TERM=${shQ.quote([TERM])} ` +
689
+ `HOME=${shQ.quote([HOME])} ` +
690
+ `CLAUDEX_FLAGS_PASSTHROUGH=${shQ.quote([claudexFlags])} ` +
691
+ `sudo -E -u ${shQ.quote([USER])} ` +
692
+ `${shQ.quote([process.execPath, selfPathJS])} ` +
693
+ `internal tmux new-session -A -s ${shQ.quote([session])}`
673
694
  ]);
674
695
  }
675
696
  else {
@@ -677,16 +698,26 @@ const actionDefault = (opts, args) => {
677
698
  return execInherit(process.execPath, [
678
699
  selfPathJS, "internal", "capsula",
679
700
  "-e", `CLAUDEX_FLAGS_PASSTHROUGH=${claudexFlags}`,
701
+ "-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
680
702
  "-C", container, process.execPath, selfPathJS, "internal", "tmux",
681
- "new-session", "-A", "-s", session, "-n", "claude", inPane
703
+ "new-session", "-A", "-s", session, "-n", "claude",
704
+ "claudex", "internal", "exec"
682
705
  ]);
683
706
  }
684
707
  }
685
708
  else {
686
709
  /* enter/start plain tmux */
687
710
  return execInherit(process.execPath, [
688
- selfPathJS, "internal", "tmux", "new-session", "-A", "-s", session, "-n", "claude", inPane
689
- ]);
711
+ selfPathJS,
712
+ "internal", "tmux",
713
+ "new-session", "-A", "-s", session, "-n", "claude",
714
+ "claudex", "internal", "exec"
715
+ ], {
716
+ env: {
717
+ CLAUDEX_FLAGS_PASSTHROUGH: claudexFlags,
718
+ CLAUDEX_INTERNAL_EXEC: inPane
719
+ }
720
+ });
690
721
  }
691
722
  }
692
723
  /* branch: capsula-only mode */
@@ -697,22 +728,29 @@ const actionDefault = (opts, args) => {
697
728
  const session = detectSessionName();
698
729
  const container = `capsula-${USER}-debian-claude-${session}`;
699
730
  const inspect = execaSync("docker", ["inspect", "-f", "{{.State.Running}}", container], { reject: false });
731
+ const passthru = [...innerFlags, ...args];
700
732
  if (inspect.exitCode === 0) {
701
733
  /* start the container if it exists but is not running */
702
734
  if (inspect.stdout.trim() !== "true")
703
735
  execaSync("docker", ["start", container], { reject: false, stdio: "ignore" });
704
736
  /* enter already running container and run claude (single-quote shell-escape) */
705
- const passthru = [...innerFlags, ...args].map(shq).join(" ");
706
737
  return execInherit("docker", [
707
738
  "exec", "-i", "-t", container,
708
739
  "bash", "-c",
709
- `TERM=${shq(TERM)} HOME=${shq(HOME)} sudo -E -u ${shq(USER)} ${shq(process.execPath)} ${shq(selfPathJS)} ${passthru}`
740
+ `TERM=${shQ.quote([TERM])} ` +
741
+ `HOME=${shQ.quote([HOME])} ` +
742
+ `sudo -E -u ${shQ.quote([USER])} ` +
743
+ `${shQ.quote([process.execPath, selfPathJS])} ` +
744
+ `${shQ.quote(passthru)}`
710
745
  ]);
711
746
  }
712
747
  else {
713
748
  /* start a new container and run claude */
714
749
  return execInherit(process.execPath, [
715
- selfPathJS, "internal", "capsula", "-C", container, process.execPath, selfPathJS, ...innerFlags, ...args
750
+ selfPathJS,
751
+ "internal", "capsula", "-C", container,
752
+ process.execPath, selfPathJS,
753
+ ...passthru
716
754
  ]);
717
755
  }
718
756
  }
package/claudex.ts CHANGED
@@ -13,6 +13,7 @@ import which from "which"
13
13
  import chalk from "chalk"
14
14
  import deepmerge from "deepmerge"
15
15
  import { Command } from "commander"
16
+ import * as shQ from "shell-quote"
16
17
 
17
18
  /* type for environment variable map */
18
19
  type Env = Record<string, string | undefined>
@@ -170,12 +171,6 @@ const ensureTool = (tool: string | string[], options: {
170
171
  }
171
172
  }
172
173
 
173
- /* helper to POSIX-single-quote-escape a string for safe interpolation
174
- into a "bash -c" command line (defense against shell injection of
175
- user-supplied or env-derived values) */
176
- const shq = (s: string): string =>
177
- `'${s.replace(/'/g, "'\\''")}'`
178
-
179
174
  /* re-invoke this same script (mirrors "$0 ..." in Bash) */
180
175
  const self = async (...args: string[]): Promise<number> => {
181
176
  const r = await execa(process.execPath, [ selfPathJS, ...args ], {
@@ -529,7 +524,7 @@ const actionInternalTmux = (args: string[]): never => {
529
524
  ensureTool("tmux")
530
525
  const claudexFlags = process.env.CLAUDEX_FLAGS_PASSTHROUGH ?? ""
531
526
  const conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
532
- .replace(/@CLAUDEX@/g, `${shq(process.execPath)} ${shq(selfPathJS)}`)
527
+ .replace(/@CLAUDEX@/g, `${shQ.quote([ process.execPath, selfPathJS ])}`)
533
528
  .replace(/@CLAUDEX_FLAGS_PASSTHROUGH@/g, claudexFlags)
534
529
  const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`)
535
530
  fs.writeFileSync(confFile, conf, { mode: 0o600 })
@@ -688,7 +683,33 @@ const actionInternalCapsula = (args: string[]): never => {
688
683
  ])
689
684
  }
690
685
 
691
- /* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula) */
686
+ /* action: internal "exec" -- execute a command supplied via the
687
+ $CLAUDEX_INTERNAL_EXEC environment variable. The variable value is split
688
+ into argv via shell-quote (honoring '..' and ".." quoting, no shell
689
+ expansion of operators), and then the resulting command is run with stdio
690
+ inherited. This indirection exists to work around platforms (notably
691
+ Windows tmux) that mishandle quoting when a command is passed via "tmux
692
+ new-session" as multiple trailing argv items: we instead pass the whole
693
+ command as a single env-var value. */
694
+ const actionInternalExec = (): never => {
695
+ const cmdline = process.env.CLAUDEX_INTERNAL_EXEC ?? ""
696
+ if (cmdline === "")
697
+ fatal("CLAUDEX_INTERNAL_EXEC environment variable is empty or unset")
698
+ const parsed = shQ.parse(cmdline)
699
+ const argv: string[] = []
700
+ for (const tok of parsed) {
701
+ if (typeof tok === "string")
702
+ argv.push(tok)
703
+ else
704
+ fatal("CLAUDEX_INTERNAL_EXEC contains unsupported shell construct (operators, globs, or env-var expansion are not allowed)")
705
+ }
706
+ if (argv.length === 0)
707
+ fatal("CLAUDEX_INTERNAL_EXEC contains no command to execute")
708
+ const [ file, ...rest ] = argv
709
+ return execInherit(file, rest)
710
+ }
711
+
712
+ /* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula, exec) */
692
713
  const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
693
714
  const util = args[0]
694
715
  const rest = args.slice(1)
@@ -698,6 +719,7 @@ const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
698
719
  case "ase-task-edit": return actionInternalAseTaskEdit()
699
720
  case "lazygit": return actionInternalLazygit(opts.recolor === true, rest)
700
721
  case "capsula": return actionInternalCapsula(rest)
722
+ case "exec": return actionInternalExec()
701
723
  default:
702
724
  fatal(`invalid internal command "${util ?? ""}"`)
703
725
  }
@@ -727,18 +749,11 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
727
749
  session = detectSessionName()
728
750
  const rest = args
729
751
 
730
- /* build the in-pane self-invocation shell string */
731
- const inPane = [
732
- shq(process.execPath),
733
- shq(selfPathJS),
734
- ...innerFlags.map(shq),
735
- ...rest.map(shq)
736
- ].join(" ")
752
+ /* build the in-pane self-invocation */
753
+ const inPane = shQ.quote([ process.execPath, selfPathJS, ...innerFlags, ...rest ])
737
754
 
738
- /* propagate the chosen pass-through flags to "internal tmux" so its
739
- tmux.conf bind-keys spawn new claude panes with the same flags */
755
+ /* propagate the chosen pass-through flags to "internal tmux" */
740
756
  const claudexFlags = innerFlags.join(" ")
741
- process.env.CLAUDEX_FLAGS_PASSTHROUGH = claudexFlags
742
757
 
743
758
  /* dispatch according to global options */
744
759
  if (opts.capsula) {
@@ -755,7 +770,12 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
755
770
  return execInherit("docker", [
756
771
  "exec", "-i", "-t", container,
757
772
  "bash", "-c",
758
- `TERM=${shq(TERM)} HOME=${shq(HOME)} CLAUDEX_FLAGS_PASSTHROUGH=${shq(claudexFlags)} sudo -E -u ${shq(USER)} ${shq(process.execPath)} ${shq(selfPathJS)} internal tmux new-session -A -s ${shq(session)}`
773
+ `TERM=${shQ.quote([ TERM ])} ` +
774
+ `HOME=${shQ.quote([ HOME ])} ` +
775
+ `CLAUDEX_FLAGS_PASSTHROUGH=${shQ.quote([ claudexFlags ])} ` +
776
+ `sudo -E -u ${shQ.quote([ USER ])} ` +
777
+ `${shQ.quote([ process.execPath, selfPathJS ])} ` +
778
+ `internal tmux new-session -A -s ${shQ.quote([ session ])}`
759
779
  ])
760
780
  }
761
781
  else {
@@ -763,16 +783,26 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
763
783
  return execInherit(process.execPath, [
764
784
  selfPathJS, "internal", "capsula",
765
785
  "-e", `CLAUDEX_FLAGS_PASSTHROUGH=${claudexFlags}`,
786
+ "-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
766
787
  "-C", container, process.execPath, selfPathJS, "internal", "tmux",
767
- "new-session", "-A", "-s", session, "-n", "claude", inPane
788
+ "new-session", "-A", "-s", session, "-n", "claude",
789
+ "claudex", "internal", "exec"
768
790
  ])
769
791
  }
770
792
  }
771
793
  else {
772
794
  /* enter/start plain tmux */
773
795
  return execInherit(process.execPath, [
774
- selfPathJS, "internal", "tmux", "new-session", "-A", "-s", session, "-n", "claude", inPane
775
- ])
796
+ selfPathJS,
797
+ "internal", "tmux",
798
+ "new-session", "-A", "-s", session, "-n", "claude",
799
+ "claudex", "internal", "exec"
800
+ ], {
801
+ env: {
802
+ CLAUDEX_FLAGS_PASSTHROUGH: claudexFlags,
803
+ CLAUDEX_INTERNAL_EXEC: inPane
804
+ }
805
+ })
776
806
  }
777
807
  }
778
808
 
@@ -784,23 +814,30 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
784
814
  const session = detectSessionName()
785
815
  const container = `capsula-${USER}-debian-claude-${session}`
786
816
  const inspect = execaSync("docker", [ "inspect", "-f", "{{.State.Running}}", container ], { reject: false })
817
+ const passthru = [ ...innerFlags, ...args ]
787
818
  if (inspect.exitCode === 0) {
788
819
  /* start the container if it exists but is not running */
789
820
  if (inspect.stdout.trim() !== "true")
790
821
  execaSync("docker", [ "start", container ], { reject: false, stdio: "ignore" })
791
822
 
792
823
  /* enter already running container and run claude (single-quote shell-escape) */
793
- const passthru = [ ...innerFlags, ...args ].map(shq).join(" ")
794
824
  return execInherit("docker", [
795
825
  "exec", "-i", "-t", container,
796
826
  "bash", "-c",
797
- `TERM=${shq(TERM)} HOME=${shq(HOME)} sudo -E -u ${shq(USER)} ${shq(process.execPath)} ${shq(selfPathJS)} ${passthru}`
827
+ `TERM=${shQ.quote([ TERM ])} ` +
828
+ `HOME=${shQ.quote([ HOME ])} ` +
829
+ `sudo -E -u ${shQ.quote([ USER ])} ` +
830
+ `${shQ.quote([ process.execPath, selfPathJS ])} ` +
831
+ `${shQ.quote(passthru)}`
798
832
  ])
799
833
  }
800
834
  else {
801
835
  /* start a new container and run claude */
802
836
  return execInherit(process.execPath, [
803
- selfPathJS, "internal", "capsula", "-C", container, process.execPath, selfPathJS, ...innerFlags, ...args
837
+ selfPathJS,
838
+ "internal", "capsula", "-C", container,
839
+ process.execPath, selfPathJS,
840
+ ...passthru
804
841
  ])
805
842
  }
806
843
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rse/claudex",
3
3
  "publishConfig": { "access": "public" },
4
- "version": "0.9.21",
4
+ "version": "0.9.22",
5
5
  "description": "Claude Code eXtended",
6
6
  "type": "module",
7
7
  "keywords": [ "claude", "code", "extension", "wrapper" ],
@@ -20,12 +20,15 @@
20
20
  "execa": "9.6.1",
21
21
  "chalk": "5.6.2",
22
22
  "commander": "14.0.3",
23
- "deepmerge": "4.3.1"
23
+ "deepmerge": "4.3.1",
24
+ "shescape": "2.1.12",
25
+ "shell-quote": "1.8.3"
24
26
  },
25
27
  "devDependencies": {
26
28
  "typescript": "6.0.3",
27
29
  "@types/node": "25.6.2",
28
30
  "@types/which": "3.0.4",
31
+ "@types/shell-quote": "1.7.5",
29
32
 
30
33
  "@rse/stx": "1.1.5",
31
34
  "eslint": "9.39.4",
package/stx.conf CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  # build entire project
8
8
  build
9
- eslint --config eslint.mjs claudex.ts
10
- tsc
9
+ eslint --config eslint.mjs claudex.ts && \
10
+ tsc --project tsconfig.json
11
11
 
12
12
  # remove regularly built files
13
13
  clean