fix: escape newlines in shell arguments on Windows

close #70
This commit is contained in:
weishu
2026-01-17 19:59:59 +08:00
parent c44eae0b17
commit 3f465cd47d
3 changed files with 16 additions and 4 deletions
+4 -3
View File
@@ -25,6 +25,7 @@ import {
import { getDefaultClaudeCodePath, logDebug, streamToStdin } from './utils'
import { withBunRuntimeEnv } from '@/utils/bunRuntime'
import { killProcessByChildProcess } from '@/utils/process'
import { stripNewlinesForWindowsShellArg } from '@/utils/shellEscape'
import type { Writable } from 'node:stream'
import { logger } from '@/ui/logger'
import { appendMcpConfigArg } from '../utils/mcpConfig'
@@ -289,8 +290,8 @@ export function query(config: {
const args = ['--output-format', 'stream-json', '--verbose']
let cleanupMcpConfig: (() => void) | null = null
if (customSystemPrompt) args.push('--system-prompt', customSystemPrompt)
if (appendSystemPrompt) args.push('--append-system-prompt', appendSystemPrompt)
if (customSystemPrompt) args.push('--system-prompt', stripNewlinesForWindowsShellArg(customSystemPrompt))
if (appendSystemPrompt) args.push('--append-system-prompt', stripNewlinesForWindowsShellArg(appendSystemPrompt))
if (maxTurns) args.push('--max-turns', maxTurns.toString())
if (model) args.push('--model', model)
if (canCallTool) {
@@ -317,7 +318,7 @@ export function query(config: {
// Handle prompt input
if (typeof prompt === 'string') {
args.push('--print', prompt.trim())
args.push('--print', stripNewlinesForWindowsShellArg(prompt.trim()))
} else {
args.push('--input-format', 'stream-json')
}