fix: Avoid creating an empty c:\dev\null file on windows during terminal width detection. (#132)

On Windows, the Unix-specific commands (ps, stty, tput) and shell
redirects (2>/dev/null) don't work and cause issues:
- tput doesn't exist on Windows
- 2>/dev/null creates a literal file named "null" instead of
  redirecting stderr

This fix adds a platform check at the start of getTerminalWidth()
and canDetectTerminalWidth().  We cannot rely on process.stdout.columns when run as a subprocess of claude code to tell us the actual terminal width.  By simply returning that terminal width detection is unavailable on windows, we avoid the empty file being created, and disable explicit truncation behavior since we can't detect the width.


Fixes #117

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: preserve legacy terminal width behavior on Windows

Return null/false for win32 in terminal width helpers to keep width detection disabled on Windows and avoid Unix-style fallback paths that can create C:\dev\null.

---------

Co-authored-by: ItsDaRa <ItsDaRa@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-03-02 20:28:11 -05:00
1 parent 8b1ec580d9
commit 4459379038
1 file changed
+12 -1
+12 -1
View File
@@ -34,6 +34,12 @@ export function getPackageVersion(): string {
// Get terminal width
export function getTerminalWidth(): number | null {
// Preserve historical behavior on Windows: width detection is unavailable.
// This avoids Unix fallback command behavior (e.g. 2>/dev/null) on Windows.
if (process.platform === 'win32') {
return null;
}
try {
// First try to get the tty of the parent process
const tty = execSync('ps -o tty= -p $(ps -o ppid= -p $$)', {
@@ -83,6 +89,11 @@ export function getTerminalWidth(): number | null {
// Check if terminal width detection is available
export function canDetectTerminalWidth(): boolean {
// Preserve historical behavior on Windows: width detection is unavailable.
if (process.platform === 'win32') {
return false;
}
try {
// First try to get the tty of the parent process
const tty = execSync('ps -o tty= -p $(ps -o ppid= -p $$)', {
@@ -123,4 +134,4 @@ export function canDetectTerminalWidth(): boolean {
} catch {
return false;
}
}
}