@rse/claudex 0.9.20 → 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/AGENTS.md +81 -32
- package/CHANGELOG.md +21 -0
- package/README.md +1 -5
- package/claudex.js +129 -48
- package/claudex.ts +134 -53
- package/package.json +5 -2
- package/stx.conf +2 -2
- package/tmux.conf +9 -7
- package/doc/screenshot-3.png +0 -0
package/AGENTS.md
CHANGED
|
@@ -15,7 +15,7 @@ modal companion tools (LazyGit, Bash) into a single `claudex` command.
|
|
|
15
15
|
|
|
16
16
|
The project is written in TypeScript and built via the `stx` task runner (config in `stx.conf`).
|
|
17
17
|
|
|
18
|
-
- `npm start build` — runs the build
|
|
18
|
+
- `npm start build` — runs the build procedure: `eslint` + `tsc`.
|
|
19
19
|
- `npm start clean` — remove generated `claudex.js` and `tsc.tsbuildinfo`.
|
|
20
20
|
- `npm start clean-dist` — also remove `node_modules` and `package-lock.json`.
|
|
21
21
|
|
|
@@ -23,47 +23,96 @@ There are no tests in this repository.
|
|
|
23
23
|
|
|
24
24
|
The compiled `claudex.js` is the published entry point (`bin.claudex` in `package.json`); the
|
|
25
25
|
POSIX-sh `claudex` script next to it is a thin launcher that `exec node claudex.js "$@"`.
|
|
26
|
-
A second tiny shell script `claude`
|
|
27
|
-
|
|
26
|
+
A second tiny shell script `claude` simply `exec claudex "$@"` (prepending `$CLAUDEX_BASEDIR`
|
|
27
|
+
to `$PATH` if set), so users can transparently substitute `claudex` for `claude`.
|
|
28
28
|
|
|
29
29
|
## Architecture
|
|
30
30
|
|
|
31
|
-
The entire program is a single file, `claudex.ts
|
|
32
|
-
|
|
31
|
+
The entire program is a single file, `claudex.ts`. Dispatch is driven by `commander` in
|
|
32
|
+
`main()`, which defines a small command surface:
|
|
33
|
+
|
|
34
|
+
### Top-level invocation (default action: run Claude Code)
|
|
35
|
+
|
|
36
|
+
`claudex [-C] [-T [session]] [-R] [-A] [<claude-args>...]` — the default action runs
|
|
37
|
+
Claude Code, optionally wrapped by Capsula and/or tmux, optionally recolored, optionally
|
|
38
|
+
ASE-augmented. Top-level flags:
|
|
39
|
+
|
|
40
|
+
- `-C, --capsula` — run inside a per-user/per-session Capsula Docker container
|
|
41
|
+
(`capsula-${USER}-debian-claude-${session}`).
|
|
42
|
+
- `-T, --tmux [session]` — wrap in a tmux session (auto-detected name, or explicit
|
|
43
|
+
`[session]`). Session name is auto-detected by walking up to find `AGENTS.md` /
|
|
44
|
+
`CLAUDE.md`; otherwise the cwd basename is used.
|
|
45
|
+
- `-R, --recolor` — pipe Claude Code through `ansi-recolor` using `ansi-recolor.conf`.
|
|
46
|
+
- `-A, --ase` — enable ASE statusline and auto-derive `ASE_TERM_WIDTH` /
|
|
47
|
+
`ASE_TERM_COLORS` from the TTY for ASE diagram rendering.
|
|
48
|
+
|
|
49
|
+
Top-level `-h/--help` is intercepted before commander, passed through to `claude --help`,
|
|
50
|
+
and then the claudeX extension flags are appended to the help output.
|
|
51
|
+
|
|
52
|
+
In the default action the `claude` invocation:
|
|
53
|
+
|
|
54
|
+
- Prepends `$HOME/.local/bin` to `$PATH` (where `claude` is installed by the official installer).
|
|
55
|
+
- Injects a generated `--settings` JSON (telemetry/auto-update/bug/error-reporting disabled,
|
|
56
|
+
spinner verbs replaced; with `-A` adds an `ase statusline` command; with `-T` enables
|
|
57
|
+
experimental agent teams + `teammateMode: tmux` + `tmuxSplitPanes`).
|
|
58
|
+
- If `CLAUDE_MODEL=ollama:[//host[:port]]/<model>[?context=,capabilities=]` is set, rewrites
|
|
59
|
+
`ANTHROPIC_*` env vars (base URL, auth token "ollama", default Haiku/Opus/Sonnet model,
|
|
60
|
+
capabilities, auto-compact window) to point at a local Ollama server.
|
|
61
|
+
|
|
62
|
+
### Subcommands
|
|
33
63
|
|
|
34
|
-
- `version` — print version from `package.json`.
|
|
35
64
|
- `install` — install host-side deps (tmux, lazygit, git, node, ansi-recolor,
|
|
36
|
-
typescript-language-server, claude) via the platform's package manager
|
|
37
|
-
|
|
65
|
+
typescript-language-server, claude) via the platform's package manager (winget/choco on
|
|
66
|
+
Windows, MacPorts/Homebrew on macOS, apt/apk on Linux), OR the in-container deps when
|
|
67
|
+
`-C` is passed (Debian apt + Node.js + claude installer + the `claude` wrapper into
|
|
68
|
+
`/usr/bin/claude`).
|
|
38
69
|
- `update` — update those same components.
|
|
39
|
-
- `
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
- `
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
- `internal <util> [args...]` — internal sub-dispatch, used by re-entrant
|
|
71
|
+
self-invocation (tmux bind-keys, container `docker exec` strings, etc.). Utilities:
|
|
72
|
+
- `internal tmux <tmux-args>` — spawn `tmux -f <generated-conf>` using `tmux.conf`
|
|
73
|
+
with `@CLAUDEX@` substituted to `node /path/to/claudex.js` and `@CLAUDEX_FLAGS_PASSTHROUGH@`
|
|
74
|
+
substituted to the propagated pass-through flags. Bind-keys: `c`/`|`/`-` (new claude
|
|
75
|
+
pane), `g` (lazygit popup), `b` (bash/shell popup), `q` (ASE task-edit popup).
|
|
76
|
+
- `internal shell [args...]` — spawn an interactive login shell
|
|
77
|
+
(`$SHELL -l ...` on POSIX; PowerShell or `$ComSpec` on Windows).
|
|
78
|
+
- `internal ase-task-edit` — read `#{@ase_task_id}` from the current tmux pane and
|
|
79
|
+
run `ase task edit <tid>`.
|
|
80
|
+
- `internal lazygit [args...]` — spawn `lazygit -ucf lazygit.yaml`, optionally
|
|
81
|
+
wrapped by `ansi-recolor` when `-R` is in effect.
|
|
82
|
+
- `internal capsula [args...]` — spawn `capsula -c claude -t debian -P linux/arm64`
|
|
83
|
+
with the curated env-var allowlist (`TERM`, `HOME`, `CLAUDE_MODEL`, `CLAUDEX`),
|
|
84
|
+
dotfile mount list (`.bashrc`, `.gitconfig`, `.ssh/*`, `.vimrc`, `.tmux.conf`,
|
|
85
|
+
`.claude*`, `.dotfiles/*`, etc.), `.env`-file null-mounts (walked up from cwd), and
|
|
86
|
+
`-b basedir`.
|
|
54
87
|
|
|
55
88
|
### Self-invocation
|
|
56
89
|
|
|
57
|
-
`claudex` re-invokes itself extensively (
|
|
58
|
-
strings).
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
90
|
+
`claudex` re-invokes itself extensively (tmux `bind-key` strings, container `docker exec`
|
|
91
|
+
strings, sub-action chaining). Self-invocation uses `node claudex.js` directly via
|
|
92
|
+
`selfPathJS = <basedir>/claudex.js` plus `process.execPath`, not the POSIX-sh `claudex`
|
|
93
|
+
launcher — this avoids a shell layer and keeps argv handling consistent across
|
|
94
|
+
platforms. Inside tmux bind-key strings the same `node /path/to/claudex.js` form is
|
|
95
|
+
substituted into `tmux.conf` via the `@CLAUDEX@` placeholder.
|
|
96
|
+
|
|
97
|
+
### Flag propagation
|
|
98
|
+
|
|
99
|
+
The pass-through flags `-R` and `-A` are propagated to spawned tmux panes via the
|
|
100
|
+
`CLAUDEX_FLAGS_PASSTHROUGH` env var so new claude panes inherit the user's choice.
|
|
101
|
+
`-C` and `-T` are deliberately NOT propagated (they are consumed at the outer layer to
|
|
102
|
+
avoid recursive container/tmux nesting).
|
|
103
|
+
|
|
104
|
+
The `CLAUDEX_FLAGS` env var lets users set default top-level flags (`-R`/`-C`/`-T`/`-A`);
|
|
105
|
+
they are merged with command-line flags (env first, command-line second; already-present
|
|
106
|
+
flags are not duplicated). This merge is skipped for the `internal` sub-dispatch.
|
|
62
107
|
|
|
63
108
|
### Sandbox detection
|
|
64
109
|
|
|
65
|
-
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
|
|
110
|
+
Inside the Capsula container, `ENVIRONMENT=capsula` is set; commands that must not run
|
|
111
|
+
in-container (`install`/`update` non-capsula path, the default action with `-C` or `-T`,
|
|
112
|
+
and `internal capsula`) check this and `fatal()` early.
|
|
113
|
+
|
|
114
|
+
### Claude Code version pruning
|
|
69
115
|
|
|
116
|
+
After a successful install/update, `pruneClaudeVersions()` removes all but the currently
|
|
117
|
+
active version under `~/.local/share/claude/versions` (active version is detected by
|
|
118
|
+
running the installed `claude --version`).
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
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
|
+
|
|
13
|
+
0.9.21 (2026-05-09)
|
|
14
|
+
-------------------
|
|
15
|
+
|
|
16
|
+
- IMPROVEMENT: support CLAUDEX\_FLAGS env variable for passing default options
|
|
17
|
+
- IMPROVEMENT: provide convenience keystrokes including CTRL+t for task switching
|
|
18
|
+
- IMPROVEMENT: improve temp file cleanup approach for tmux config
|
|
19
|
+
- BUGFIX: ensure docker container is really running
|
|
20
|
+
- BUGFIX: fix typo in code
|
|
21
|
+
- UPDATE: align AGENTS.md with current code state
|
|
22
|
+
- CLEANUP: internally, use CLAUDEX\_FLAGS\_PASSTHROUGH for the option passing
|
|
23
|
+
- CLEANUP: always use "node claudex.js" internally for self-execution
|
|
24
|
+
- REFACTOR: move pruning of obsolete Claude versions to later in flow
|
|
25
|
+
|
|
5
26
|
0.9.20 (2026-05-09)
|
|
6
27
|
-------------------
|
|
7
28
|
|
package/README.md
CHANGED
|
@@ -52,14 +52,10 @@ panes of the screen.
|
|
|
52
52
|
|
|
53
53
|

|
|
54
54
|
|
|
55
|
-
This is with LazyGit opened in a modal window:
|
|
55
|
+
This is with LazyGit opened on top of Claude Code in a modal window:
|
|
56
56
|
|
|
57
57
|

|
|
58
58
|
|
|
59
|
-
This is with Bash opened in a modal window:
|
|
60
|
-
|
|
61
|
-

|
|
62
|
-
|
|
63
59
|
Installation
|
|
64
60
|
------------
|
|
65
61
|
|
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] ?? "";
|
|
@@ -25,10 +26,7 @@ const findBaseDir = () => {
|
|
|
25
26
|
return path.dirname(resolved);
|
|
26
27
|
};
|
|
27
28
|
const basedir = findBaseDir();
|
|
28
|
-
/* the path used for self-invocation
|
|
29
|
-
next to the compiled JS, since the JS itself is not executable
|
|
30
|
-
and embedded shell strings (docker/tmux) need a runnable command */
|
|
31
|
-
const selfPath = path.join(basedir, "claudex");
|
|
29
|
+
/* the path used for self-invocation */
|
|
32
30
|
const selfPathJS = path.join(basedir, "claudex.js");
|
|
33
31
|
/* helper for displaying info messages */
|
|
34
32
|
const info = (msg) => {
|
|
@@ -153,10 +151,6 @@ const ensureTool = (tool, options = {}) => {
|
|
|
153
151
|
fatal(`required tool "${tool}" not found in $PATH`);
|
|
154
152
|
}
|
|
155
153
|
};
|
|
156
|
-
/* helper to POSIX-single-quote-escape a string for safe interpolation
|
|
157
|
-
into a "bash -c" command line (defense against shell injection of
|
|
158
|
-
user-supplied or env-derived values) */
|
|
159
|
-
const shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
|
|
160
154
|
/* re-invoke this same script (mirrors "$0 ..." in Bash) */
|
|
161
155
|
const self = async (...args) => {
|
|
162
156
|
const r = await execa(process.execPath, [selfPathJS, ...args], {
|
|
@@ -245,18 +239,18 @@ const actionInstall = async (capsula) => {
|
|
|
245
239
|
await self("internal", "capsula", "sudo", "-E", "apt", "install", "-qq", "-y", "binutils", "gcc", "g++", "make");
|
|
246
240
|
info("install Claude Code");
|
|
247
241
|
await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`);
|
|
248
|
-
/* prune obsolete versions only after successful install */
|
|
249
|
-
await self("internal", "capsula", "bash", "-c", "VERSIONS=\"$HOME/.local/share/claude/versions\"; " +
|
|
250
|
-
"[ -d \"$VERSIONS\" ] || exit 0; " +
|
|
251
|
-
"ACTIVE=$(\"$HOME/.local/bin/claude\" --version 2>/dev/null | awk '{print $1; exit}'); " +
|
|
252
|
-
"[ -n \"$ACTIVE\" ] || exit 0; " +
|
|
253
|
-
"find \"$VERSIONS\" -mindepth 1 -maxdepth 1 ! -name \"$ACTIVE\" -exec rm -rf {} +");
|
|
254
242
|
info("install ANSI-Recolor");
|
|
255
243
|
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "ansi-recolor");
|
|
256
244
|
info("install TypeScript LS");
|
|
257
245
|
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "typescript-language-server");
|
|
258
246
|
info("install Claude wrapper");
|
|
259
247
|
await self("internal", "capsula", "sudo", "install", "-c", "-m", "755", `${basedir}/claude`, "/usr/bin/claude");
|
|
248
|
+
/* prune obsolete versions only after successful install */
|
|
249
|
+
await self("internal", "capsula", "bash", "-c", "VERSIONS=\"$HOME/.local/share/claude/versions\"; " +
|
|
250
|
+
"[ -d \"$VERSIONS\" ] || exit 0; " +
|
|
251
|
+
"ACTIVE=$(\"$HOME/.local/bin/claude\" --version 2>/dev/null | awk '{print $1; exit}'); " +
|
|
252
|
+
"[ -n \"$ACTIVE\" ] || exit 0; " +
|
|
253
|
+
"find \"$VERSIONS\" -mindepth 1 -maxdepth 1 ! -name \"$ACTIVE\" -exec rm -rf {} +");
|
|
260
254
|
}
|
|
261
255
|
else {
|
|
262
256
|
const platform = detectPlatform();
|
|
@@ -454,16 +448,29 @@ const actionUpdate = async (capsula) => {
|
|
|
454
448
|
/* action: internal "tmux" -- spawn tmux with our generated configuration.
|
|
455
449
|
The tmux.conf bind-keys for new claude panes embed the parent invocation's
|
|
456
450
|
pass-through flags (e.g. "-R") so panes inherit the user's choice; flags
|
|
457
|
-
are transported via the
|
|
458
|
-
entering tmux mode). */
|
|
451
|
+
are transported via the CLAUDEX_FLAGS_PASSTHROUGH env var (set by
|
|
452
|
+
actionDefault when entering tmux mode). */
|
|
459
453
|
const actionInternalTmux = (args) => {
|
|
460
454
|
ensureTool("tmux");
|
|
461
|
-
const claudexFlags = process.env.
|
|
455
|
+
const claudexFlags = process.env.CLAUDEX_FLAGS_PASSTHROUGH ?? "";
|
|
462
456
|
const conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
|
|
463
|
-
.replace(/@
|
|
464
|
-
.replace(/@
|
|
457
|
+
.replace(/@CLAUDEX@/g, `${shQ.quote([process.execPath, selfPathJS])}`)
|
|
458
|
+
.replace(/@CLAUDEX_FLAGS_PASSTHROUGH@/g, claudexFlags);
|
|
465
459
|
const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`);
|
|
466
460
|
fs.writeFileSync(confFile, conf, { mode: 0o600 });
|
|
461
|
+
/* ensure the temp config is removed on normal exit AND on signal-driven
|
|
462
|
+
termination (SIGINT/SIGTERM); SIGKILL and process panics remain
|
|
463
|
+
uncoverable. tmux.conf is read once at startup and not re-read via
|
|
464
|
+
source-file, so early removal is safe. */
|
|
465
|
+
const cleanup = () => {
|
|
466
|
+
try {
|
|
467
|
+
fs.unlinkSync(confFile);
|
|
468
|
+
}
|
|
469
|
+
catch (_e) { /* ignore */ }
|
|
470
|
+
};
|
|
471
|
+
process.on("exit", cleanup);
|
|
472
|
+
process.on("SIGINT", () => { cleanup(); process.exit(130); });
|
|
473
|
+
process.on("SIGTERM", () => { cleanup(); process.exit(143); });
|
|
467
474
|
const r = execaSync("tmux", [
|
|
468
475
|
"-f", confFile,
|
|
469
476
|
...args
|
|
@@ -472,12 +479,7 @@ const actionInternalTmux = (args) => {
|
|
|
472
479
|
reject: false,
|
|
473
480
|
windowsHide: false
|
|
474
481
|
});
|
|
475
|
-
|
|
476
|
-
fs.unlinkSync(confFile);
|
|
477
|
-
}
|
|
478
|
-
catch (_e) {
|
|
479
|
-
/* ignore */
|
|
480
|
-
}
|
|
482
|
+
cleanup();
|
|
481
483
|
return process.exit(r.exitCode ?? 0);
|
|
482
484
|
};
|
|
483
485
|
/* action: internal "shell" -- spawn an interactive login shell */
|
|
@@ -604,7 +606,32 @@ const actionInternalCapsula = (args) => {
|
|
|
604
606
|
...args
|
|
605
607
|
]);
|
|
606
608
|
};
|
|
607
|
-
/* action: internal
|
|
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) */
|
|
608
635
|
const actionInternal = async (opts, args) => {
|
|
609
636
|
const util = args[0];
|
|
610
637
|
const rest = args.slice(1);
|
|
@@ -614,6 +641,7 @@ const actionInternal = async (opts, args) => {
|
|
|
614
641
|
case "ase-task-edit": return actionInternalAseTaskEdit();
|
|
615
642
|
case "lazygit": return actionInternalLazygit(opts.recolor === true, rest);
|
|
616
643
|
case "capsula": return actionInternalCapsula(rest);
|
|
644
|
+
case "exec": return actionInternalExec();
|
|
617
645
|
default:
|
|
618
646
|
fatal(`invalid internal command "${util ?? ""}"`);
|
|
619
647
|
}
|
|
@@ -639,46 +667,57 @@ const actionDefault = (opts, args) => {
|
|
|
639
667
|
else
|
|
640
668
|
session = detectSessionName();
|
|
641
669
|
const rest = args;
|
|
642
|
-
/* build the in-pane self-invocation
|
|
643
|
-
const inPane = [
|
|
644
|
-
|
|
645
|
-
shq(selfPathJS),
|
|
646
|
-
...innerFlags.map(shq),
|
|
647
|
-
...rest.map(shq)
|
|
648
|
-
].join(" ");
|
|
649
|
-
/* propagate the chosen pass-through flags to "internal tmux" so its
|
|
650
|
-
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" */
|
|
651
673
|
const claudexFlags = innerFlags.join(" ");
|
|
652
|
-
process.env.CLAUDEX_FLAGS = claudexFlags;
|
|
653
674
|
/* dispatch according to global options */
|
|
654
675
|
if (opts.capsula) {
|
|
655
676
|
/* enter/start container, then run tmux inside it */
|
|
656
677
|
ensureTool("docker");
|
|
657
678
|
const container = `capsula-${USER}-debian-claude-${session}`;
|
|
658
|
-
const inspect = execaSync("docker", ["inspect", container], { reject: false
|
|
679
|
+
const inspect = execaSync("docker", ["inspect", "-f", "{{.State.Running}}", container], { reject: false });
|
|
659
680
|
if (inspect.exitCode === 0) {
|
|
681
|
+
/* start the container if it exists but is not running */
|
|
682
|
+
if (inspect.stdout.trim() !== "true")
|
|
683
|
+
execaSync("docker", ["start", container], { reject: false, stdio: "ignore" });
|
|
660
684
|
/* enter already running container and run tmux */
|
|
661
685
|
return execInherit("docker", [
|
|
662
686
|
"exec", "-i", "-t", container,
|
|
663
687
|
"bash", "-c",
|
|
664
|
-
`TERM=${
|
|
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])}`
|
|
665
694
|
]);
|
|
666
695
|
}
|
|
667
696
|
else {
|
|
668
697
|
/* start a new container and run tmux */
|
|
669
698
|
return execInherit(process.execPath, [
|
|
670
699
|
selfPathJS, "internal", "capsula",
|
|
671
|
-
"-e", `
|
|
672
|
-
"-
|
|
673
|
-
"
|
|
700
|
+
"-e", `CLAUDEX_FLAGS_PASSTHROUGH=${claudexFlags}`,
|
|
701
|
+
"-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
|
|
702
|
+
"-C", container, process.execPath, selfPathJS, "internal", "tmux",
|
|
703
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
704
|
+
"claudex", "internal", "exec"
|
|
674
705
|
]);
|
|
675
706
|
}
|
|
676
707
|
}
|
|
677
708
|
else {
|
|
678
709
|
/* enter/start plain tmux */
|
|
679
710
|
return execInherit(process.execPath, [
|
|
680
|
-
selfPathJS,
|
|
681
|
-
|
|
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
|
+
});
|
|
682
721
|
}
|
|
683
722
|
}
|
|
684
723
|
/* branch: capsula-only mode */
|
|
@@ -688,20 +727,30 @@ const actionDefault = (opts, args) => {
|
|
|
688
727
|
ensureTool("docker");
|
|
689
728
|
const session = detectSessionName();
|
|
690
729
|
const container = `capsula-${USER}-debian-claude-${session}`;
|
|
691
|
-
const inspect = execaSync("docker", ["inspect", container], { reject: false
|
|
730
|
+
const inspect = execaSync("docker", ["inspect", "-f", "{{.State.Running}}", container], { reject: false });
|
|
731
|
+
const passthru = [...innerFlags, ...args];
|
|
692
732
|
if (inspect.exitCode === 0) {
|
|
733
|
+
/* start the container if it exists but is not running */
|
|
734
|
+
if (inspect.stdout.trim() !== "true")
|
|
735
|
+
execaSync("docker", ["start", container], { reject: false, stdio: "ignore" });
|
|
693
736
|
/* enter already running container and run claude (single-quote shell-escape) */
|
|
694
|
-
const passthru = [...innerFlags, ...args].map(shq).join(" ");
|
|
695
737
|
return execInherit("docker", [
|
|
696
738
|
"exec", "-i", "-t", container,
|
|
697
739
|
"bash", "-c",
|
|
698
|
-
`TERM=${
|
|
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)}`
|
|
699
745
|
]);
|
|
700
746
|
}
|
|
701
747
|
else {
|
|
702
748
|
/* start a new container and run claude */
|
|
703
749
|
return execInherit(process.execPath, [
|
|
704
|
-
selfPathJS,
|
|
750
|
+
selfPathJS,
|
|
751
|
+
"internal", "capsula", "-C", container,
|
|
752
|
+
process.execPath, selfPathJS,
|
|
753
|
+
...passthru
|
|
705
754
|
]);
|
|
706
755
|
}
|
|
707
756
|
}
|
|
@@ -867,6 +916,38 @@ const actionHelp = () => {
|
|
|
867
916
|
};
|
|
868
917
|
/* the main procedure -- builds and dispatches according to options and commands */
|
|
869
918
|
const main = async () => {
|
|
919
|
+
/* honor the external CLAUDEX_FLAGS environment variable as a way to set
|
|
920
|
+
the top-level "-R"/"-C"/"-T"/"-A" flags by default. Merge env-derived
|
|
921
|
+
flags with the command-line flags (env first, command-line second, so
|
|
922
|
+
the user can extend or override on the command line). Skip for the
|
|
923
|
+
"internal" sub-dispatch (which uses CLAUDEX_FLAGS_PASSTHROUGH for
|
|
924
|
+
tmux.conf bind-key flag propagation), and skip flags that are already
|
|
925
|
+
present on argv to avoid duplicating boolean options. */
|
|
926
|
+
{
|
|
927
|
+
const topArgs = process.argv.slice(2);
|
|
928
|
+
const subcmd = topArgs.find((a) => !a.startsWith("-")) ?? "";
|
|
929
|
+
const envFlags = (process.env.CLAUDEX_FLAGS ?? "").trim();
|
|
930
|
+
if (envFlags !== "" && subcmd !== "internal") {
|
|
931
|
+
const aliases = {
|
|
932
|
+
"-R": "--recolor", "--recolor": "-R",
|
|
933
|
+
"-C": "--capsula", "--capsula": "-C",
|
|
934
|
+
"-T": "--tmux", "--tmux": "-T",
|
|
935
|
+
"-A": "--ase", "--ase": "-A"
|
|
936
|
+
};
|
|
937
|
+
const present = (tok) => {
|
|
938
|
+
if (topArgs.includes(tok))
|
|
939
|
+
return true;
|
|
940
|
+
const alt = aliases[tok];
|
|
941
|
+
if (alt !== undefined && topArgs.includes(alt))
|
|
942
|
+
return true;
|
|
943
|
+
return false;
|
|
944
|
+
};
|
|
945
|
+
const tokens = envFlags.split(/\s+/).filter((t) => t !== "");
|
|
946
|
+
const toInsert = tokens.filter((t) => !present(t));
|
|
947
|
+
if (toInsert.length > 0)
|
|
948
|
+
process.argv.splice(2, 0, ...toInsert);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
870
951
|
/* intercept top-level "-h/--help" before commander grabs it, so we can
|
|
871
952
|
pass-through to "claude --help" and append our extension info */
|
|
872
953
|
const topArgs = process.argv.slice(2);
|
|
@@ -888,7 +969,7 @@ const main = async () => {
|
|
|
888
969
|
.helpOption(false)
|
|
889
970
|
.option("-C, --capsula", "execute Claude Code inside a Capsula sandbox container")
|
|
890
971
|
.option("-T, --tmux [session]", "wrap Claude Code in a Tmux terminal multiplexing session (optional session name)")
|
|
891
|
-
.option("-R, --recolor", "wrap Claude Code with ANSI
|
|
972
|
+
.option("-R, --recolor", "wrap Claude Code with ANSI recoloring for improved theming")
|
|
892
973
|
.option("-A, --ase", "enable ASE-specific Claude Code statusline and ASE_* environment variables")
|
|
893
974
|
.argument("[args...]", "arguments passed unparsed to Claude Code")
|
|
894
975
|
.action((args, opts) => {
|
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>
|
|
@@ -31,10 +32,7 @@ const findBaseDir = (): string => {
|
|
|
31
32
|
}
|
|
32
33
|
const basedir = findBaseDir()
|
|
33
34
|
|
|
34
|
-
/* the path used for self-invocation
|
|
35
|
-
next to the compiled JS, since the JS itself is not executable
|
|
36
|
-
and embedded shell strings (docker/tmux) need a runnable command */
|
|
37
|
-
const selfPath = path.join(basedir, "claudex")
|
|
35
|
+
/* the path used for self-invocation */
|
|
38
36
|
const selfPathJS = path.join(basedir, "claudex.js")
|
|
39
37
|
|
|
40
38
|
/* helper for displaying info messages */
|
|
@@ -173,12 +171,6 @@ const ensureTool = (tool: string | string[], options: {
|
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
173
|
|
|
176
|
-
/* helper to POSIX-single-quote-escape a string for safe interpolation
|
|
177
|
-
into a "bash -c" command line (defense against shell injection of
|
|
178
|
-
user-supplied or env-derived values) */
|
|
179
|
-
const shq = (s: string): string =>
|
|
180
|
-
`'${s.replace(/'/g, "'\\''")}'`
|
|
181
|
-
|
|
182
174
|
/* re-invoke this same script (mirrors "$0 ..." in Bash) */
|
|
183
175
|
const self = async (...args: string[]): Promise<number> => {
|
|
184
176
|
const r = await execa(process.execPath, [ selfPathJS, ...args ], {
|
|
@@ -286,15 +278,6 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
|
|
|
286
278
|
info("install Claude Code")
|
|
287
279
|
await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`)
|
|
288
280
|
|
|
289
|
-
/* prune obsolete versions only after successful install */
|
|
290
|
-
await self("internal", "capsula", "bash", "-c",
|
|
291
|
-
"VERSIONS=\"$HOME/.local/share/claude/versions\"; " +
|
|
292
|
-
"[ -d \"$VERSIONS\" ] || exit 0; " +
|
|
293
|
-
"ACTIVE=$(\"$HOME/.local/bin/claude\" --version 2>/dev/null | awk '{print $1; exit}'); " +
|
|
294
|
-
"[ -n \"$ACTIVE\" ] || exit 0; " +
|
|
295
|
-
"find \"$VERSIONS\" -mindepth 1 -maxdepth 1 ! -name \"$ACTIVE\" -exec rm -rf {} +"
|
|
296
|
-
)
|
|
297
|
-
|
|
298
281
|
info("install ANSI-Recolor")
|
|
299
282
|
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "ansi-recolor")
|
|
300
283
|
|
|
@@ -303,6 +286,15 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
|
|
|
303
286
|
|
|
304
287
|
info("install Claude wrapper")
|
|
305
288
|
await self("internal", "capsula", "sudo", "install", "-c", "-m", "755", `${basedir}/claude`, "/usr/bin/claude")
|
|
289
|
+
|
|
290
|
+
/* prune obsolete versions only after successful install */
|
|
291
|
+
await self("internal", "capsula", "bash", "-c",
|
|
292
|
+
"VERSIONS=\"$HOME/.local/share/claude/versions\"; " +
|
|
293
|
+
"[ -d \"$VERSIONS\" ] || exit 0; " +
|
|
294
|
+
"ACTIVE=$(\"$HOME/.local/bin/claude\" --version 2>/dev/null | awk '{print $1; exit}'); " +
|
|
295
|
+
"[ -n \"$ACTIVE\" ] || exit 0; " +
|
|
296
|
+
"find \"$VERSIONS\" -mindepth 1 -maxdepth 1 ! -name \"$ACTIVE\" -exec rm -rf {} +"
|
|
297
|
+
)
|
|
306
298
|
}
|
|
307
299
|
else {
|
|
308
300
|
const platform = detectPlatform()
|
|
@@ -526,16 +518,27 @@ const actionUpdate = async (capsula: boolean): Promise<void> => {
|
|
|
526
518
|
/* action: internal "tmux" -- spawn tmux with our generated configuration.
|
|
527
519
|
The tmux.conf bind-keys for new claude panes embed the parent invocation's
|
|
528
520
|
pass-through flags (e.g. "-R") so panes inherit the user's choice; flags
|
|
529
|
-
are transported via the
|
|
530
|
-
entering tmux mode). */
|
|
521
|
+
are transported via the CLAUDEX_FLAGS_PASSTHROUGH env var (set by
|
|
522
|
+
actionDefault when entering tmux mode). */
|
|
531
523
|
const actionInternalTmux = (args: string[]): never => {
|
|
532
524
|
ensureTool("tmux")
|
|
533
|
-
const claudexFlags = process.env.
|
|
525
|
+
const claudexFlags = process.env.CLAUDEX_FLAGS_PASSTHROUGH ?? ""
|
|
534
526
|
const conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
|
|
535
|
-
.replace(/@
|
|
536
|
-
.replace(/@
|
|
527
|
+
.replace(/@CLAUDEX@/g, `${shQ.quote([ process.execPath, selfPathJS ])}`)
|
|
528
|
+
.replace(/@CLAUDEX_FLAGS_PASSTHROUGH@/g, claudexFlags)
|
|
537
529
|
const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`)
|
|
538
530
|
fs.writeFileSync(confFile, conf, { mode: 0o600 })
|
|
531
|
+
/* ensure the temp config is removed on normal exit AND on signal-driven
|
|
532
|
+
termination (SIGINT/SIGTERM); SIGKILL and process panics remain
|
|
533
|
+
uncoverable. tmux.conf is read once at startup and not re-read via
|
|
534
|
+
source-file, so early removal is safe. */
|
|
535
|
+
const cleanup = (): void => {
|
|
536
|
+
try { fs.unlinkSync(confFile) }
|
|
537
|
+
catch (_e) { /* ignore */ }
|
|
538
|
+
}
|
|
539
|
+
process.on("exit", cleanup)
|
|
540
|
+
process.on("SIGINT", () => { cleanup(); process.exit(130) })
|
|
541
|
+
process.on("SIGTERM", () => { cleanup(); process.exit(143) })
|
|
539
542
|
const r = execaSync("tmux", [
|
|
540
543
|
"-f", confFile,
|
|
541
544
|
...args
|
|
@@ -544,12 +547,7 @@ const actionInternalTmux = (args: string[]): never => {
|
|
|
544
547
|
reject: false,
|
|
545
548
|
windowsHide: false
|
|
546
549
|
})
|
|
547
|
-
|
|
548
|
-
fs.unlinkSync(confFile)
|
|
549
|
-
}
|
|
550
|
-
catch (_e) {
|
|
551
|
-
/* ignore */
|
|
552
|
-
}
|
|
550
|
+
cleanup()
|
|
553
551
|
return process.exit(r.exitCode ?? 0)
|
|
554
552
|
}
|
|
555
553
|
|
|
@@ -685,7 +683,33 @@ const actionInternalCapsula = (args: string[]): never => {
|
|
|
685
683
|
])
|
|
686
684
|
}
|
|
687
685
|
|
|
688
|
-
/* action: internal
|
|
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) */
|
|
689
713
|
const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
|
|
690
714
|
const util = args[0]
|
|
691
715
|
const rest = args.slice(1)
|
|
@@ -695,6 +719,7 @@ const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
|
|
|
695
719
|
case "ase-task-edit": return actionInternalAseTaskEdit()
|
|
696
720
|
case "lazygit": return actionInternalLazygit(opts.recolor === true, rest)
|
|
697
721
|
case "capsula": return actionInternalCapsula(rest)
|
|
722
|
+
case "exec": return actionInternalExec()
|
|
698
723
|
default:
|
|
699
724
|
fatal(`invalid internal command "${util ?? ""}"`)
|
|
700
725
|
}
|
|
@@ -724,48 +749,60 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
|
|
|
724
749
|
session = detectSessionName()
|
|
725
750
|
const rest = args
|
|
726
751
|
|
|
727
|
-
/* build the in-pane self-invocation
|
|
728
|
-
const inPane = [
|
|
729
|
-
shq(process.execPath),
|
|
730
|
-
shq(selfPathJS),
|
|
731
|
-
...innerFlags.map(shq),
|
|
732
|
-
...rest.map(shq)
|
|
733
|
-
].join(" ")
|
|
752
|
+
/* build the in-pane self-invocation */
|
|
753
|
+
const inPane = shQ.quote([ process.execPath, selfPathJS, ...innerFlags, ...rest ])
|
|
734
754
|
|
|
735
|
-
/* propagate the chosen pass-through flags to "internal tmux"
|
|
736
|
-
tmux.conf bind-keys spawn new claude panes with the same flags */
|
|
755
|
+
/* propagate the chosen pass-through flags to "internal tmux" */
|
|
737
756
|
const claudexFlags = innerFlags.join(" ")
|
|
738
|
-
process.env.CLAUDEX_FLAGS = claudexFlags
|
|
739
757
|
|
|
740
758
|
/* dispatch according to global options */
|
|
741
759
|
if (opts.capsula) {
|
|
742
760
|
/* enter/start container, then run tmux inside it */
|
|
743
761
|
ensureTool("docker")
|
|
744
762
|
const container = `capsula-${USER}-debian-claude-${session}`
|
|
745
|
-
const inspect = execaSync("docker", [ "inspect", container ], { reject: false
|
|
763
|
+
const inspect = execaSync("docker", [ "inspect", "-f", "{{.State.Running}}", container ], { reject: false })
|
|
746
764
|
if (inspect.exitCode === 0) {
|
|
765
|
+
/* start the container if it exists but is not running */
|
|
766
|
+
if (inspect.stdout.trim() !== "true")
|
|
767
|
+
execaSync("docker", [ "start", container ], { reject: false, stdio: "ignore" })
|
|
768
|
+
|
|
747
769
|
/* enter already running container and run tmux */
|
|
748
770
|
return execInherit("docker", [
|
|
749
771
|
"exec", "-i", "-t", container,
|
|
750
772
|
"bash", "-c",
|
|
751
|
-
`TERM=${
|
|
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 ])}`
|
|
752
779
|
])
|
|
753
780
|
}
|
|
754
781
|
else {
|
|
755
782
|
/* start a new container and run tmux */
|
|
756
783
|
return execInherit(process.execPath, [
|
|
757
784
|
selfPathJS, "internal", "capsula",
|
|
758
|
-
"-e", `
|
|
759
|
-
"-
|
|
760
|
-
"
|
|
785
|
+
"-e", `CLAUDEX_FLAGS_PASSTHROUGH=${claudexFlags}`,
|
|
786
|
+
"-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
|
|
787
|
+
"-C", container, process.execPath, selfPathJS, "internal", "tmux",
|
|
788
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
789
|
+
"claudex", "internal", "exec"
|
|
761
790
|
])
|
|
762
791
|
}
|
|
763
792
|
}
|
|
764
793
|
else {
|
|
765
794
|
/* enter/start plain tmux */
|
|
766
795
|
return execInherit(process.execPath, [
|
|
767
|
-
selfPathJS,
|
|
768
|
-
|
|
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
|
+
})
|
|
769
806
|
}
|
|
770
807
|
}
|
|
771
808
|
|
|
@@ -776,20 +813,31 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
|
|
|
776
813
|
ensureTool("docker")
|
|
777
814
|
const session = detectSessionName()
|
|
778
815
|
const container = `capsula-${USER}-debian-claude-${session}`
|
|
779
|
-
const inspect = execaSync("docker", [ "inspect", container ], { reject: false
|
|
816
|
+
const inspect = execaSync("docker", [ "inspect", "-f", "{{.State.Running}}", container ], { reject: false })
|
|
817
|
+
const passthru = [ ...innerFlags, ...args ]
|
|
780
818
|
if (inspect.exitCode === 0) {
|
|
819
|
+
/* start the container if it exists but is not running */
|
|
820
|
+
if (inspect.stdout.trim() !== "true")
|
|
821
|
+
execaSync("docker", [ "start", container ], { reject: false, stdio: "ignore" })
|
|
822
|
+
|
|
781
823
|
/* enter already running container and run claude (single-quote shell-escape) */
|
|
782
|
-
const passthru = [ ...innerFlags, ...args ].map(shq).join(" ")
|
|
783
824
|
return execInherit("docker", [
|
|
784
825
|
"exec", "-i", "-t", container,
|
|
785
826
|
"bash", "-c",
|
|
786
|
-
`TERM=${
|
|
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)}`
|
|
787
832
|
])
|
|
788
833
|
}
|
|
789
834
|
else {
|
|
790
835
|
/* start a new container and run claude */
|
|
791
836
|
return execInherit(process.execPath, [
|
|
792
|
-
selfPathJS,
|
|
837
|
+
selfPathJS,
|
|
838
|
+
"internal", "capsula", "-C", container,
|
|
839
|
+
process.execPath, selfPathJS,
|
|
840
|
+
...passthru
|
|
793
841
|
])
|
|
794
842
|
}
|
|
795
843
|
}
|
|
@@ -963,6 +1011,39 @@ const actionHelp = (): never => {
|
|
|
963
1011
|
|
|
964
1012
|
/* the main procedure -- builds and dispatches according to options and commands */
|
|
965
1013
|
const main = async (): Promise<void> => {
|
|
1014
|
+
/* honor the external CLAUDEX_FLAGS environment variable as a way to set
|
|
1015
|
+
the top-level "-R"/"-C"/"-T"/"-A" flags by default. Merge env-derived
|
|
1016
|
+
flags with the command-line flags (env first, command-line second, so
|
|
1017
|
+
the user can extend or override on the command line). Skip for the
|
|
1018
|
+
"internal" sub-dispatch (which uses CLAUDEX_FLAGS_PASSTHROUGH for
|
|
1019
|
+
tmux.conf bind-key flag propagation), and skip flags that are already
|
|
1020
|
+
present on argv to avoid duplicating boolean options. */
|
|
1021
|
+
{
|
|
1022
|
+
const topArgs = process.argv.slice(2)
|
|
1023
|
+
const subcmd = topArgs.find((a) => !a.startsWith("-")) ?? ""
|
|
1024
|
+
const envFlags = (process.env.CLAUDEX_FLAGS ?? "").trim()
|
|
1025
|
+
if (envFlags !== "" && subcmd !== "internal") {
|
|
1026
|
+
const aliases: Record<string, string> = {
|
|
1027
|
+
"-R": "--recolor", "--recolor": "-R",
|
|
1028
|
+
"-C": "--capsula", "--capsula": "-C",
|
|
1029
|
+
"-T": "--tmux", "--tmux": "-T",
|
|
1030
|
+
"-A": "--ase", "--ase": "-A"
|
|
1031
|
+
}
|
|
1032
|
+
const present = (tok: string): boolean => {
|
|
1033
|
+
if (topArgs.includes(tok))
|
|
1034
|
+
return true
|
|
1035
|
+
const alt = aliases[tok]
|
|
1036
|
+
if (alt !== undefined && topArgs.includes(alt))
|
|
1037
|
+
return true
|
|
1038
|
+
return false
|
|
1039
|
+
}
|
|
1040
|
+
const tokens = envFlags.split(/\s+/).filter((t) => t !== "")
|
|
1041
|
+
const toInsert = tokens.filter((t) => !present(t))
|
|
1042
|
+
if (toInsert.length > 0)
|
|
1043
|
+
process.argv.splice(2, 0, ...toInsert)
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
966
1047
|
/* intercept top-level "-h/--help" before commander grabs it, so we can
|
|
967
1048
|
pass-through to "claude --help" and append our extension info */
|
|
968
1049
|
const topArgs = process.argv.slice(2)
|
|
@@ -985,7 +1066,7 @@ const main = async (): Promise<void> => {
|
|
|
985
1066
|
.helpOption(false)
|
|
986
1067
|
.option("-C, --capsula", "execute Claude Code inside a Capsula sandbox container")
|
|
987
1068
|
.option("-T, --tmux [session]", "wrap Claude Code in a Tmux terminal multiplexing session (optional session name)")
|
|
988
|
-
.option("-R, --recolor", "wrap Claude Code with ANSI
|
|
1069
|
+
.option("-R, --recolor", "wrap Claude Code with ANSI recoloring for improved theming")
|
|
989
1070
|
.option("-A, --ase", "enable ASE-specific Claude Code statusline and ASE_* environment variables")
|
|
990
1071
|
.argument("[args...]", "arguments passed unparsed to Claude Code")
|
|
991
1072
|
.action((args: string[], opts: TopOpts) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rse/claudex",
|
|
3
3
|
"publishConfig": { "access": "public" },
|
|
4
|
-
"version": "0.9.
|
|
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
package/tmux.conf
CHANGED
|
@@ -195,11 +195,13 @@ set-option -ga terminal-features ",*:hyperlinks"
|
|
|
195
195
|
set-option -as terminal-overrides ",*:RGB"
|
|
196
196
|
set-option -as terminal-overrides ',*:Tc:sitm=\E[3m:ritm=\E[23m'
|
|
197
197
|
|
|
198
|
-
# claudeX
|
|
199
|
-
bind-key c new-window -c "#{pane_current_path}" -n claude "@
|
|
200
|
-
bind-key | split-window -c "#{pane_current_path}" -h "@
|
|
201
|
-
bind-key - split-window -c "#{pane_current_path}" -v "@
|
|
202
|
-
bind-key g display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Version Control (lazygit) #[noreverse]▶" "@
|
|
203
|
-
bind-key s display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Shell #[noreverse]▶" "@
|
|
204
|
-
bind-key q display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Task Edit (ase task edit) #[noreverse]▶" "@
|
|
198
|
+
# claudeX specifics
|
|
199
|
+
bind-key c new-window -c "#{pane_current_path}" -n claude "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@"
|
|
200
|
+
bind-key | split-window -c "#{pane_current_path}" -h "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@"
|
|
201
|
+
bind-key - split-window -c "#{pane_current_path}" -v "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@"
|
|
202
|
+
bind-key g display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Version Control (lazygit) #[noreverse]▶" "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@ internal lazygit"
|
|
203
|
+
bind-key s display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Shell #[noreverse]▶" "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@ internal shell"
|
|
204
|
+
bind-key q display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Task Edit (ase task edit) #[noreverse]▶" "@CLAUDEX@ @CLAUDEX_FLAGS_PASSTHROUGH@ internal ase-task-edit"
|
|
205
|
+
bind-key t send-keys "/ase:ase-meta-task "
|
|
206
|
+
bind-key p send-keys "/ase:ase-meta-persona "
|
|
205
207
|
|
package/doc/screenshot-3.png
DELETED
|
Binary file
|