claudish 14.28.1 → 14.28.3

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/bin/claudish.cjs CHANGED
@@ -35,6 +35,7 @@
35
35
  // own descendants) directly; `team-orchestrator.ts` does exactly that.
36
36
 
37
37
  const { execFileSync, execSync, spawn } = require("node:child_process");
38
+ const { homedir } = require("node:os");
38
39
  const { resolve } = require("node:path");
39
40
  const { NO_ENV_FILE_FLAG, envFileKeys, probeFailedNotice } = require("./env-files.cjs");
40
41
 
@@ -44,6 +45,17 @@ const { NO_ENV_FILE_FLAG, envFileKeys, probeFailedNotice } = require("./env-file
44
45
  */
45
46
  const LAUNCHER_DROPPED_VAR = "CLAUDISH_LAUNCHER_DROPPED";
46
47
 
48
+ /**
49
+ * The commands that need no working directory. The whole argument list must be
50
+ * exactly one of these; any other argument may read or write relative to the
51
+ * working directory.
52
+ *
53
+ * A deleted working directory makes `process.cwd()` throw, and package managers such
54
+ * as npm cannot run there either, so these start the child in the home directory.
55
+ * `-v` is not here: it is `--verbose`, not a version flag.
56
+ */
57
+ const CWD_FREE_COMMANDS = ["update", "--version", "--help", "-h"];
58
+
47
59
  /**
48
60
  * The shell command that asks PATH where bun is.
49
61
  *
@@ -118,11 +130,15 @@ function bunArgv(entry, argv) {
118
130
  * those files set is left out (env-files.cjs asks Bun which). A real value sharing a
119
131
  * name with a file's is left out too, the safe direction; the child still reads the
120
132
  * provider API keys and model settings in `.env`. When Bun cannot answer, there is no child.
133
+ * A null `cwd` (the working directory no longer exists) means no file was loaded.
121
134
  */
122
135
  function childEnv({ isBun, execArgv, bunPath, cwd, env }) {
123
136
  const out = { ...env };
124
137
  delete out[LAUNCHER_DROPPED_VAR];
125
- if (!isBun || execArgv.includes(NO_ENV_FILE_FLAG)) return { env: out, dropped: [] };
138
+ // A null `cwd` means the working directory is gone, so Bun loaded no env file from it.
139
+ if (!isBun || execArgv.includes(NO_ENV_FILE_FLAG) || cwd === null) {
140
+ return { env: out, dropped: [] };
141
+ }
126
142
  const fileKeys = envFileKeys({ bunPath, execArgv, cwd, env });
127
143
  if (fileKeys === null) return null;
128
144
  const dropped = [];
@@ -136,6 +152,24 @@ function childEnv({ isBun, execArgv, bunPath, cwd, env }) {
136
152
  }
137
153
 
138
154
  function main() {
155
+ // `spawnCwd` stays undefined while the working directory exists, so the child
156
+ // inherits it. `cwd` is null when the directory is gone.
157
+ let cwd;
158
+ let spawnCwd;
159
+ try {
160
+ cwd = process.cwd();
161
+ } catch {
162
+ const args = process.argv.slice(2);
163
+ if (args.length !== 1 || !CWD_FREE_COMMANDS.includes(args[0])) {
164
+ console.error(
165
+ "[claudish] the current directory no longer exists (it was deleted or moved). cd to a folder that exists and run claudish again."
166
+ );
167
+ process.exit(1);
168
+ }
169
+ cwd = null;
170
+ spawnCwd = homedir();
171
+ }
172
+
139
173
  const bun = findBun();
140
174
  if (!bun) {
141
175
  console.error(`claudish requires the Bun runtime but it was not found.
@@ -156,7 +190,7 @@ Learn more: https://bun.sh`);
156
190
  isBun: process.versions.bun !== undefined,
157
191
  execArgv: process.execArgv,
158
192
  bunPath: process.execPath,
159
- cwd: process.cwd(),
193
+ cwd,
160
194
  env: process.env,
161
195
  });
162
196
  if (base === null) {
@@ -168,6 +202,7 @@ Learn more: https://bun.sh`);
168
202
  try {
169
203
  child = spawn(bun, bunArgv(entry, process.argv.slice(2)), {
170
204
  stdio: "inherit",
205
+ cwd: spawnCwd,
171
206
  // The pid pair tells the Bun child who launched it: this launcher, and the
172
207
  // launcher's own parent (Claude Code, for an MCP server). The child
173
208
  // believes the pair only when CLAUDISH_LAUNCHER_PID is its real parent