MCPcopy Create free account
hub / github.com/codeaashu/claude-code / intercept

Method intercept

src/ink/ink.tsx:1608–1632  ·  view source on GitHub ↗
(chunk: Uint8Array | string, encodingOrCb?: BufferEncoding | ((err?: Error) => void), cb?: (err?: Error) => void)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 2

logForDebuggingFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected