Skip to content

Commit a20d784

Browse files
committed
Fix stdin raw mode error using temp file and shell redirection
Replace stdin piping with temp file and shell input redirection to avoid Ink raw mode errors when running Claude non-interactively. This allows Claude to use file editing tools without stdin TTY requirements.
1 parent fe8d257 commit a20d784

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

scripts/claude.mjs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,20 +3308,20 @@ Fix all CI failures now by making the necessary changes.`
33083308
}, 10_000)
33093309

33103310
try {
3311+
// Write prompt to temp file to avoid stdin raw mode issues
3312+
const tmpFile = path.join(rootPath, `.claude-fix-${Date.now()}.txt`)
3313+
await fs.writeFile(tmpFile, fixPrompt, 'utf8')
3314+
33113315
const fixArgs = prepareClaudeArgs([], opts)
3316+
// Use shell input redirection to pass prompt without stdin pipe
3317+
const shellCmd = `${claudeCmd} ${fixArgs.join(' ')} < "${tmpFile}"`
33123318
const exitCode = await new Promise((resolve, _reject) => {
3313-
const child = spawn(claudeCmd, fixArgs, {
3314-
stdio: ['pipe', 'inherit', 'inherit'],
3319+
const child = spawn(shellCmd, [], {
3320+
stdio: 'inherit',
33153321
cwd: rootPath,
3316-
...(WIN32 && { shell: true }),
3322+
shell: true,
33173323
})
33183324

3319-
// Write the fix prompt to stdin
3320-
if (fixPrompt) {
3321-
child.stdin.write(fixPrompt)
3322-
child.stdin.end()
3323-
}
3324-
33253325
child.on('exit', code => {
33263326
resolve(code || 0)
33273327
})
@@ -3330,6 +3330,12 @@ Fix all CI failures now by making the necessary changes.`
33303330
resolve(1)
33313331
})
33323332
})
3333+
3334+
// Clean up temp file
3335+
try {
3336+
await fs.unlink(tmpFile)
3337+
} catch {}
3338+
33333339
if (exitCode !== 0) {
33343340
log.warn(`Claude fix exited with code ${exitCode}`)
33353341
}
@@ -3513,20 +3519,20 @@ Fix the failure now by making the necessary changes.`
35133519
}, 10_000)
35143520

35153521
try {
3522+
// Write prompt to temp file to avoid stdin raw mode issues
3523+
const tmpFile = path.join(rootPath, `.claude-fix-${Date.now()}.txt`)
3524+
await fs.writeFile(tmpFile, fixPrompt, 'utf8')
3525+
35163526
const fixArgs = prepareClaudeArgs([], opts)
3527+
// Use shell input redirection to pass prompt without stdin pipe
3528+
const shellCmd = `${claudeCmd} ${fixArgs.join(' ')} < "${tmpFile}"`
35173529
const exitCode = await new Promise((resolve, _reject) => {
3518-
const child = spawn(claudeCmd, fixArgs, {
3519-
stdio: ['pipe', 'inherit', 'inherit'],
3530+
const child = spawn(shellCmd, [], {
3531+
stdio: 'inherit',
35203532
cwd: rootPath,
3521-
...(WIN32 && { shell: true }),
3533+
shell: true,
35223534
})
35233535

3524-
// Write the fix prompt to stdin
3525-
if (fixPrompt) {
3526-
child.stdin.write(fixPrompt)
3527-
child.stdin.end()
3528-
}
3529-
35303536
child.on('exit', code => {
35313537
resolve(code || 0)
35323538
})
@@ -3535,6 +3541,12 @@ Fix the failure now by making the necessary changes.`
35353541
resolve(1)
35363542
})
35373543
})
3544+
3545+
// Clean up temp file
3546+
try {
3547+
await fs.unlink(tmpFile)
3548+
} catch {}
3549+
35383550
if (exitCode !== 0) {
35393551
log.warn(`Claude fix exited with code ${exitCode}`)
35403552
}

0 commit comments

Comments
 (0)