[BUG] `nul` file created in project directory on Windows
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?
### Description
On Windows, Claude Code creates a nul file in the project root directory. This appears to happen when tools like Glob are executed. The file is repeatedly created during normal usage.
This issue does not occur on Linux, suggesting that somewhere in the code, a /dev/null redirect is being handled incorrectly on Windows - creating a literal nul file instead of using the Windows NUL device.
### Environment
- OS: Windows 11 (10.0.26200.7462)
- Claude Code version: (your version here)
### Steps to Reproduce
- Open Claude Code in a Windows project directory
- Use any tool that triggers file operations (e.g.,
Glob) - Check the project root - a
nulfile appears
### Expected Behavior
No nul file should be created. On Windows, output to null should go to the NUL device, not create a file.
### Actual Behavior
A nul file is created in the project directory. Since nul is a reserved name in Windows, it requires special handling to delete:
del ?\C:\path\to\project\nul
### Workaround
Added a PostToolUse hook to automatically delete the file:
```json
{
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "powershell -Command \"if (Test-Path 'D:\\path\\to\\project\\nul') { Remove-Item -Path '\\\\?\\D:\\path\\to\\project\\nul' -Force -ErrorAction SilentlyContinue }\""
}
]
}
]
}
}
What Should Happen?
On Windows, when Claude Code needs to redirect output to null, it should:
- Use the Windows
NULdevice (e.g.,command > NUL 2>&1) instead of creating a file - Or properly handle the
/dev/nullpath by translating it to the Windows equivalent - No physical
nulfile should ever be created in the user's project directory
The behavior should match Linux/macOS where no such file is created.
Error Messages/Logs
Steps to Reproduce
- Open Claude Code on Windows
- Navigate to any project directory
- Run any command that uses the
Globtool (e.g., ask Claude to "find all .cpp files") - Check the project root directory
- A
nulfile (0 bytes) will be created
Alternatively:
- Simply use Claude Code normally on Windows for a few minutes
- The
nulfile appears after various tool executions
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.1
Claude Code Version
2.1.1
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
### Additional Information
Observation:
- The
nulfile is created specifically when tools likeGlob,Grep, orReadare executed - The file is 0 bytes in size
- On Linux, the same operations do not create any file
- The issue appears to be related to how stderr/stdout redirection is handled on Windows
Workaround:
I created a PostToolUse hook in .claude/settings.local.json to automatically delete the file after each tool execution:
```json
{
"hooks": {
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "powershell -Command \"if (Test-Path 'D:\\path\\to\\project\\nul') { Remove-Item -Path '\\\\?\\D:\\path\\to\\project\\nul' -Force -ErrorAction SilentlyContinue }\""
}
]
}
]
}
}
Note:
Since nul is a reserved filename in Windows, standard delete commands don't work. The \\?\ prefix is required to delete the file:
del \\?\D:\path\to\project\nul
Possible Cause:
Somewhere in the codebase, there may be a shell command using 2>nul or >nul redirection that is being executed in a non-Windows-native shell (like Git Bash or WSL), causing it to create a literal file instead of redirecting to the Windows NUL device.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗