MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / getStdinOverride

Function getStdinOverride

src/utils/renderOptions.ts:15–60  ·  view source on GitHub ↗

* Gets a ReadStream for /dev/tty when stdin is piped. * This allows interactive Ink rendering even when stdin is a pipe. * Result is cached for the lifetime of the process.

()

Source from the content-addressed store, hash-verified

13 * Result is cached for the lifetime of the process.
14 */
15function getStdinOverride(): ReadStream | undefined {
16 // Return cached result if already computed
17 if (cachedStdinOverride !== null) {
18 return cachedStdinOverride
19 }
20
21 // No override needed if stdin is already a TTY
22 if (process.stdin.isTTY) {
23 cachedStdinOverride = undefined
24 return undefined
25 }
26
27 // Skip in CI environments
28 if (isEnvTruthy(process.env.CI)) {
29 cachedStdinOverride = undefined
30 return undefined
31 }
32
33 // Skip if running MCP (input hijacking breaks MCP)
34 if (process.argv.includes('mcp')) {
35 cachedStdinOverride = undefined
36 return undefined
37 }
38
39 // No /dev/tty on Windows
40 if (process.platform === 'win32') {
41 cachedStdinOverride = undefined
42 return undefined
43 }
44
45 // Try to open /dev/tty as an alternative input source
46 try {
47 const ttyFd = openSync('/dev/tty', 'r')
48 const ttyStream = new ReadStream(ttyFd)
49 // Explicitly set isTTY to true since we know /dev/tty is a TTY.
50 // This is needed because some runtimes (like Bun's compiled binaries)
51 // may not correctly detect isTTY on ReadStream created from a file descriptor.
52 ttyStream.isTTY = true
53 cachedStdinOverride = ttyStream
54 return cachedStdinOverride
55 } catch (err) {
56 logError(err as Error)
57 cachedStdinOverride = undefined
58 return undefined
59 }
60}
61
62/**
63 * Returns base render options for Ink, including stdin override when needed.

Callers 1

getBaseRenderOptionsFunction · 0.85

Calls 2

isEnvTruthyFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected