diff --git a/scripts/claw.js b/scripts/claw.js index 04a4228c..121859a1 100644 --- a/scripts/claw.js +++ b/scripts/claw.js @@ -89,13 +89,17 @@ function askClaude(systemPrompt, history, userMessage, model) { if (model) { args.push('--model', model); } - args.push('-p', fullPrompt); + args.push('-p'); - // On Windows, the `claude` binary installed via npm is `claude.cmd`. - // Node's spawn() cannot resolve `.cmd` wrappers via PATH without shell: true, - // so this call fails with `spawn claude ENOENT` on Windows otherwise. + // On Windows the `claude` binary installed via npm is `claude.cmd`/`claude.ps1`, + // and Node's spawn() cannot resolve those wrappers via PATH without shell: true. + // But shell mode concatenates args *unescaped*, so a multi-line prompt passed as + // an arg gets mangled (newlines and the `===` section markers truncate it, and + // claude receives an empty prompt). Fix: send the prompt over stdin via `input` + // and keep only the short, safe flags (`--model`, `-p`) as args. // 'claude' is a hardcoded literal here (not user input), so shell mode is safe. const result = spawnSync('claude', args, { + input: fullPrompt, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, CLAUDECODE: '' },