MCPcopy Index your code
hub / github.com/codeaashu/claude-code / patchStderr

Method patchStderr

src/ink/ink.tsx:1604–1639  ·  view source on GitHub ↗

* Intercept process.stderr.write so stray writes (config.ts, hooks.ts, * third-party deps) don't corrupt the alt-screen buffer. patchConsole only * hooks console.* methods — direct stderr writes bypass it, land at the * parked cursor, scroll the alt-screen, and desync frontFrame from the

()

Source from the content-addressed store, hash-verified

1602 * process.stdout — Ink itself writes there.
1603 */
1604 private patchStderr(): () => void {
1605 const stderr = process.stderr;
1606 const originalWrite = stderr.write;
1607 let reentered = false;
1608 const intercept = (chunk: Uint8Array | string, encodingOrCb?: BufferEncoding | ((err?: Error) => void), cb?: (err?: Error) => void): boolean => {
1609 const callback = typeof encodingOrCb === 'function' ? encodingOrCb : cb;
1610 // Reentrancy guard: logForDebugging → writeToStderr → here. Pass
1611 // through to the original so --debug-to-stderr still works and we
1612 // don't stack-overflow.
1613 if (reentered) {
1614 const encoding = typeof encodingOrCb === 'string' ? encodingOrCb : undefined;
1615 return originalWrite.call(stderr, chunk, encoding, callback);
1616 }
1617 reentered = true;
1618 try {
1619 const text = typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf8');
1620 logForDebugging(`[stderr] ${text}`, {
1621 level: 'warn'
1622 });
1623 if (this.altScreenActive && !this.isUnmounted && !this.isPaused) {
1624 this.prevFrameContaminated = true;
1625 this.scheduleRender();
1626 }
1627 } finally {
1628 reentered = false;
1629 callback?.();
1630 }
1631 return true;
1632 };
1633 stderr.write = intercept;
1634 return () => {
1635 if (stderr.write === intercept) {
1636 stderr.write = originalWrite;
1637 }
1638 };
1639 }
1640}
1641
1642/**

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected