Skip to content

Commit 96fa709

Browse files
committed
fix: prevent process hang on Windows when stdin EOF does not propagate through Volta shim
On Windows with a Volta-managed ccstatusline, spawning ccstatusline as a child subprocess causes it to hang indefinitely. The process chain is: parent node -> cmd.exe (shell:true) -> bash (Volta shim) -> volta -> node The for-await stdin loop never receives EOF because stdin EOF from the parent does not propagate through cmd.exe -> bash -> volta on Windows. Each Claude Code statusline refresh spawns a new hung process; in one real session this accumulated to 961 leaked node.exe processes, 2.1 GB RAM, 90.5% kernel-mode CPU. Fix 1 (readStdin): replace for-await with event-based reading + 3s bail timeout. When EOF never arrives, the timeout destroys stdin and resolves the promise. Data already accumulated in chunks[] is returned normally (no data loss). Fix 2 (main): add explicit process.exit(0) after renderMultipleLines. Claude Code abandons (does not kill) statusline processes that run long; an explicit exit prevents any residual async handles from keeping the event loop alive. Related: nodejs/node#32291, volta-cli/volta#1199, ccusage/ccusage#459
1 parent bed8501 commit 96fa709

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎src/ccstatusline.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,21 @@ async function readStdin(): Promise<string | null> {
6565
chunks.push(decoder.decode(chunk));
6666
}
6767
} else {
68-
// Node.js environment
68+
// Node.js environment.
69+
// Use event-based reading instead of for-await so we can add a bail
70+
// timeout: on Windows, stdin EOF never propagates through the Volta shim
71+
// chain (cmd.exe -> bash -> volta -> node), causing for-await to hang
72+
// indefinitely. The timeout destroys stdin after 3s of silence; data
73+
// already in chunks[] is preserved and returned normally.
74+
// See: nodejs/node#32291, volta-cli/volta#1199, ryoppippi/ccusage#459
6975
process.stdin.setEncoding('utf8');
70-
for await (const chunk of process.stdin) {
71-
chunks.push(chunk as string);
72-
}
76+
await new Promise<void>((resolve) => {
77+
const bail = setTimeout(() => { process.stdin.destroy(); resolve(); }, 3000);
78+
if (typeof (bail as NodeJS.Timeout).unref === 'function') (bail as NodeJS.Timeout).unref();
79+
process.stdin.on('data', (chunk: string) => chunks.push(chunk));
80+
process.stdin.on('end', () => { clearTimeout(bail); resolve(); });
81+
process.stdin.on('error', () => { clearTimeout(bail); resolve(); });
82+
});
7383
}
7484
return chunks.join('');
7585
} catch {
@@ -327,6 +337,10 @@ async function main() {
327337
}
328338

329339
await renderMultipleLines(result.data);
340+
// Explicitly exit so the event loop does not linger. Without this,
341+
// any residual async handles from rendering keep the process alive,
342+
// which accumulates under Claude Code's "abandon not kill" lifecycle.
343+
process.exit(0);
330344
} catch (error) {
331345
console.error('Error parsing JSON:', error);
332346
process.exit(1);

0 commit comments

Comments
 (0)