claude-bridge-cli 1.1.6 → 1.2.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 (2) hide show
  1. package/lib/bridge.js +30 -14
  2. package/package.json +1 -1
package/lib/bridge.js CHANGED
@@ -340,29 +340,41 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
340
340
  }
341
341
 
342
342
  const isWin = process.platform === "win32";
343
- const args = ["-p", finalPrompt, "--output-format", "json"];
343
+ const isCmdShim = isWin && config.claudeBin.endsWith(".cmd");
344
+
345
+ // Write prompt to temp file — avoids Windows 8K arg limit and stdin
346
+ // piping issues through cmd.exe. Works on all platforms.
347
+ const tmpFile = path.join(os.tmpdir(), `claude-prompt-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`);
348
+ fs.writeFileSync(tmpFile, finalPrompt, "utf8");
349
+
350
+ const args = ["-p", `@${tmpFile}`, "--output-format", "json",
351
+ "--permission-mode", "acceptEdits"];
344
352
  if (session_id) {
345
353
  const sessionExists = scanSessionFiles().some(s => s.id === session_id);
346
354
  args.push(sessionExists ? "--resume" : "--session-id", session_id);
347
355
  }
348
356
  if (plan_mode) args.push("--plan");
349
357
 
350
- const bin = isWin && config.claudeBin.endsWith(".cmd") ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
351
- const fullArgs = isWin && config.claudeBin.endsWith(".cmd") ? ["/c", config.claudeBin, ...args] : args;
358
+ const bin = isCmdShim ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
359
+ const fullArgs = isCmdShim ? ["/c", config.claudeBin, ...args] : args;
352
360
 
353
- const { execFile } = require("node:child_process");
354
- const proc = execFile(bin, fullArgs, {
361
+ const proc = spawn(bin, fullArgs, {
355
362
  cwd: cwd || config.cwd,
356
363
  timeout: config.timeout,
357
- maxBuffer: 50 * 1024 * 1024,
358
364
  env: { ...process.env },
365
+ stdio: ["ignore", "pipe", "pipe"],
359
366
  windowsHide: true,
360
- }, (err, stdout, stderr) => {
367
+ });
368
+
369
+ let stdout = "", stderr = "";
370
+ proc.stdout.on("data", (d) => { stdout += d; });
371
+ proc.stderr.on("data", (d) => { stderr += d; });
372
+
373
+ if (session_id) running.set(session_id, proc);
374
+
375
+ proc.on("close", (code) => {
376
+ try { fs.unlinkSync(tmpFile); } catch {}
361
377
  if (session_id) running.delete(session_id);
362
- if (err && !stdout) {
363
- resolve({ error: stderr || err.message });
364
- return;
365
- }
366
378
  try {
367
379
  const result = JSON.parse(stdout);
368
380
  const sid = result.session_id || session_id || crypto.randomUUID();
@@ -379,15 +391,19 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
379
391
  context: result.context || null,
380
392
  });
381
393
  } catch {
382
- if (stdout && stdout.trim()) {
394
+ if (stdout.trim()) {
383
395
  resolve({ response: stdout.trim(), session_id: session_id || crypto.randomUUID() });
384
396
  } else {
385
- resolve({ error: stderr || "unknown error" });
397
+ resolve({ error: stderr.trim() || `claude exited with code ${code}` });
386
398
  }
387
399
  }
388
400
  });
389
401
 
390
- if (session_id) running.set(session_id, proc);
402
+ proc.on("error", (err) => {
403
+ try { fs.unlinkSync(tmpFile); } catch {}
404
+ if (session_id) running.delete(session_id);
405
+ resolve({ error: err.message });
406
+ });
391
407
  });
392
408
  }
393
409
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-bridge-cli",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
4
4
  "description": "Use Claude Code from your browser. Runs a local server that connects your browser tools to the Claude CLI.",
5
5
  "main": "lib/bridge.js",
6
6
  "bin": {