MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getStdinOverride

Function getStdinOverride

source code/utils/renderOptions.ts:17–62  ·  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

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

Callers 1

getBaseRenderOptionsFunction · 0.85

Calls 2

isEnvTruthyFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected