[BUG] # Issue Report: NUL File Creation on Windows

Resolved 💬 3 comments Opened Oct 29, 2025 by cardaba Closed Nov 1, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Issue Report: NUL File Creation on Windows

Problem Description

When executing Windows BAT scripts that contain output redirection to NUL (e.g., >nul, 2>nul), Claude Code's Bash tool creates a literal file named "NUL" in the repository instead of properly redirecting to the Windows null device.

Environment

  • Platform: Windows 10/11
  • Tool: Claude Code Bash tool
  • Shell Context: Git Bash / Unix-like shell on Windows
  • Repository: Local Git repository

Steps to Reproduce

  1. Create a BAT script with null redirection:

``batch
@echo off
call some_command.bat 2>nul
``

  1. Execute the BAT script using Claude Code's Bash tool:

``bash
"path\to\script.bat"
``

  1. Observe that a file named NUL (0 bytes) is created in the working directory

Expected Behavior

Output should be redirected to the Windows null device (NUL) without creating a physical file. This is the standard behavior when executing BAT scripts from cmd.exe or PowerShell.

Actual Behavior

A literal file named NUL is created in the current working directory. This file:

  • Is 0 bytes
  • Appears as an untracked file in git
  • Gets recreated every time BAT scripts with >nul are executed
  • Pollutes the repository

Impact

  • Severity: Low to Medium
  • Creates spurious files in version control
  • Requires manual cleanup or .gitignore entries
  • Confusing for users unfamiliar with the issue
  • Happens frequently during normal workflow

Affected Scripts in Our Project

Multiple BAT scripts use >nul redirection:

  • PEQs_FORECAST/Script/peqs-consolidator.bat
  • PEQs_FORECAST/Script/shared/get_python.bat
  • PEQs_FORECAST/Script/order-validator.bat

Example from get_python.bat:

for /f "tokens=*" %%i in ('call shared\get_python.bat 2^>nul') do set "PYTHON_CMD=%%i"

Root Cause Analysis

This is a known issue with the interaction between:

  1. Windows-style null device redirection (NUL)
  2. Unix-like shells (Git Bash, WSL, etc.)
  3. How commands are executed through the shell

When Git Bash executes a Windows BAT file, it doesn't properly translate NUL to /dev/null or the Windows null device, causing it to be interpreted as a literal filename.

Workarounds Implemented

  1. Added to .gitignore:

``gitignore
# Windows NUL file issue
NUL
**/NUL
``

  1. Manual cleanup when noticed:

``bash
rm NUL
``

Suggested Solutions

Option 1: Translate NUL to proper null device

When executing BAT scripts, Claude Code's Bash tool could:

  • Detect Windows environment
  • Translate >nul to >$null (PowerShell) or handle it appropriately
  • Or execute BAT scripts through cmd.exe instead of bash

Option 2: Pre-execution warning

  • Detect BAT scripts containing >nul redirections
  • Warn user about potential NUL file creation
  • Suggest using cmd.exe execution mode

Option 3: Post-execution cleanup

  • Automatically detect and remove spurious NUL files after BAT execution
  • Only if NUL file is 0 bytes and recently created

Option 4: Execution mode flag

Add a flag to Bash tool for Windows BAT scripts:

{
  "command": "script.bat",
  "windows_native": true  // Execute through cmd.exe
}

Related Issues

This is a well-known issue in the Windows/Unix interoperability space:

  • Git for Windows issue tracker has similar reports
  • Common problem when running BAT scripts from WSL or Git Bash
  • Affects any Unix-like shell environment on Windows

Additional Context

  • Frequency: Happens every time affected BAT scripts are run
  • User awareness: Users may not notice until git status shows untracked files
  • Impact on workflow: Minor annoyance, but consistent

Recommendation

This issue should be addressed in the Bash tool's Windows execution logic. The most robust solution would be Option 1 (proper translation) or Option 4 (execution mode flag) to prevent the issue from occurring in the first place.

References

---

Reported by: Claude Code user on Windows environment
Date: 2025-10-29
Project: alexion-expansion-dashboard
Component: PEQs_FORECAST automation scripts

What Should Happen?

Expected Behavior

Output should be redirected to the Windows null device (NUL) without creating a physical file. This is the standard behavior when executing BAT scripts from cmd.exe or PowerShell.

Error Messages/Logs

## Actual Behavior

A literal file named `NUL` is created in the current working directory. This file:
- Is 0 bytes
- Appears as an untracked file in git
- Gets recreated every time BAT scripts with `>nul` are executed
- Pollutes the repository

Steps to Reproduce

  1. Create a BAT script with null redirection:

``batch
@echo off
call some_command.bat 2>nul
``

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.28

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗