Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: add Windows compatibility for terminal width detection#132

Merged
sirmalloc merged 3 commits intosirmalloc:mainfrom
ItsDaRa:fix/windows-terminal-width
Mar 3, 2026
Merged

fix: add Windows compatibility for terminal width detection#132
sirmalloc merged 3 commits intosirmalloc:mainfrom
ItsDaRa:fix/windows-terminal-width

Conversation

@ItsDaRa
Copy link
Contributor

@ItsDaRa ItsDaRa commented Dec 25, 2025

Summary

  • Adds Windows platform check to getTerminalWidth() and canDetectTerminalWidth() in src/utils/terminal.ts
  • Uses process.stdout.columns on Windows instead of Unix-only shell commands

Problem

On Windows, the current terminal width detection causes issues:

  • tput command doesn't exist
  • ps, stty, awk are Unix-only utilities
  • Shell redirect 2>/dev/null creates a literal file named "null" in the working directory instead of suppressing stderr

This results in spurious "null" files being created wherever Claude Code is run.

Solution

Added a platform check at the start of both functions:

if (process.platform === 'win32') {
    const cols = process.stdout.columns;
    // return width or null/boolean as appropriate
}

process.stdout.columns is the Node.js cross-platform API for terminal width and works reliably on Windows.

Test plan

  • Tested on Windows 11 - no more "null" files created
  • Terminal width detection works correctly
  • Unix behavior unchanged (early return on Windows means Unix code path untouched)

Fixes #117

🤖 Generated with Claude Code

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() to use process.stdout.columns on
Windows, which is the cross-platform Node.js API for this purpose.

Fixes sirmalloc#117

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

Co-Authored-By: Claude <[email protected]>
@sirmalloc
Copy link
Owner

@ItsDaRa Have you tested this and seen the terminal width return appropriately on Windows? The main issue has always been that Claude Code calls the statusline as a subprocess without an actual connection to the terminal Claude Code is running in, so typical width detection always returns 80. If you can verify this by adding the "terminal width" widget to your statusline and resizing the terminal and verify it updates properly, then I'll merge this and push a new build out. I don't currently have a Windows machine easily accessible.

@ItsDaRa
Copy link
Contributor Author

ItsDaRa commented Jan 9, 2026

Apologizes, I didn't get any sort of notification. I'll try to test it in the next days and get back to you

zoonderkins added a commit to zoonderkins/ccstatusline that referenced this pull request Jan 21, 2026
Merged PRs:
- sirmalloc#138: fix: support bare repo worktrees in GitWorktree widget
- sirmalloc#135: feat: add git-indicators widget
- sirmalloc#132: fix: Windows terminal width detection
- sirmalloc#131: feat: Task Timer widget
- sirmalloc#123: feat: Add backups for settings.json
- sirmalloc#121: feat: Add configurable context warning alerts
- sirmalloc#120: feat: Add Mercurial support
- sirmalloc#119: feat: Add Git Root Dir widget
- sirmalloc#58: feat: Add support for local/project settings

Fixes Issues:
- sirmalloc#117: Windows tput cols creates null file
- sirmalloc#122: claude's settings.json deleted/lost
- sirmalloc#112: Add mercurial support

Additional fixes:
- Resolved circular dependency in renderer.ts/widgets.ts
- Fixed lint errors in multiple files
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.
@sirmalloc sirmalloc merged commit 4459379 into sirmalloc:main Mar 3, 2026
@sirmalloc
Copy link
Owner

I tweaked this and merged it. We can't rely on process.stdout.columns to tell us the actual columns on windows when we are invoked as a subprocess of claude code, so for now we disable terminal width detection entirely on windows. This avoids creating the empty file at c:\dev\null.

@ItsDaRa
Copy link
Contributor Author

ItsDaRa commented Mar 3, 2026

All right noted. Sorry I didn't get back to you but I just can't make sense out of it. It seems like it's random, making it harder to troubleshoot, it seem to happen more often when 2 sessions opened in the same repo, but that's all I could get. If I had to bet, I would say it's on Claude Code side, more than ccstatusline itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: tput cols creates "null" file and fails terminal width detection

2 participants