Skip to content

Conversation

@kp222x
Copy link

@kp222x kp222x commented Dec 14, 2025

Summary

Adds a new plugin that automatically removes the problematic nul files created by Claude Code on Windows.

This is a workaround for the long-standing issue where Claude Code uses 2>nul (Windows CMD syntax) when running in Git Bash or other Unix-like shells on Windows, creating a literal file named nul instead of redirecting to the null device.

The Problem

Impact: 60+ users affected over 4+ months (see issue comments)

When Claude runs bash commands on Windows:

  • Uses 2>nul for stderr redirection (CMD syntax)
  • Git Bash treats nul as a regular filename
  • Creates a literal file that:
    • Cannot be deleted via Windows Explorer or PowerShell
    • Breaks git add and git commit operations
    • Can corrupt source control history
    • Reappears after each bash command

The Solution

This plugin adds a PostToolUse hook that:

  1. Only activates on Windows (os.platform() === "win32")
  2. Runs after every Bash tool execution
  3. Silently removes any nul file in the current working directory
  4. Does not interrupt workflow on errors

Plugin Structure

windows-nul-fix/
├── .claude-plugin/
│   └── plugin.json      # Plugin metadata (Windows-only)
├── hooks/
│   └── hooks.json       # PostToolUse hook configuration
├── scripts/
│   └── remove-nul.js    # NUL file removal script
└── README.md            # Documentation with manual workarounds

Test Plan

  • JavaScript syntax validation passes
  • plugin.json is valid JSON
  • hooks.json follows plugin wrapper format
  • Script only runs on Windows (platform check)
  • Handles missing input gracefully
  • Does not block workflow on errors

Test Evidence

### Test 2: Validate JavaScript Syntax
✅ JavaScript syntax valid

### Test 3: Validate plugin.json
{
  "name": "windows-nul-fix",
  "version": "1.0.0",
  "description": "Automatically removes 'nul' files created by Claude Code on Windows...",
  ...
}
✅ plugin.json is valid JSON

Installation (for users)

Once merged, users can install via:

claude /plugin install windows-nul-fix

Or manually copy to ~/.claude/plugins/

Related

🤖 Generated with Claude Code

…nul files

On Windows, when Claude Code runs bash commands using Git Bash, it sometimes
uses '2>nul' for stderr redirection (Windows CMD syntax). In Unix shells,
this creates a literal file named 'nul' instead of redirecting to the null
device, causing several issues:

- Cannot be easily deleted via Windows Explorer or PowerShell
- Breaks git add/commit operations
- Can corrupt source control history
- Appears repeatedly after each bash command

This plugin adds a PostToolUse hook that automatically removes any 'nul'
files from the current working directory after Bash tool execution.

Features:
- Only activates on Windows (os.platform() === "win32")
- Runs silently after every Bash tool execution
- Does not interrupt workflow on errors
- Minimal overhead (5s timeout)

Fixes anthropics#4928
@kp222x kp222x force-pushed the feature/windows-nul-fix-plugin branch from 76688ef to b654c00 Compare December 14, 2025 07:27
@ThoughtPhotography
Copy link

I can confirm this is an annoying issue on Win, and it's not just Git that doesn't like these files

I've added this to my CLAUDE.md, but it's not 100% reliable

## Important Notes

### Windows-Specific: NUL File Handling
**CRITICAL:** On Windows, avoid creating files named "nul" as they are reserved device names and cause severe issues:
- Windows Explorer cannot delete them (requires admin + force delete)
- Git cannot track/ignore them properly
- File sync tools (FreeFileSync, robocopy) fail when encountering them
- They break file operations in the containing directory

**Prevention:**
- NEVER use `2>nul` in bash commands (creates a literal file named "nul")
- Use `2>/dev/null` on Unix/Mac, `2>$null` in PowerShell, or omit error redirection entirely
- Prefer PowerShell commands on Windows when shell redirection is needed

**If "nul" files exist:**
```powershell
# Remove with PowerShell (run as Administrator if needed)
Remove-Item -Path "path\to\nul" -Force

# Or use full UNC path syntax
del "\\?\C:\full\path\to\nul"

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.

[BUG] file named nul created on windows

2 participants