Original Reddit post

In ~/.claude/hooks create a ps1 shell script, add this to it: ``` PreToolUse hook: Catch ‘> nul’ redirects and deny them. try { $jsonData = [System.Console]::In.ReadToEnd()

Quick bail-out: if the input doesn’t contain ‘nul’, allow through if ($jsonData -notmatch ‘>\s*nul’) exit 0 } # Make sure it’s not already /dev/null if ($jsonData -notmatch '(?<!/dev/)(?:>2>|&>)\s*nul\b’) { exit 0 # Deny the command by exiting with code 2 and message on stderr [Console]::Error.WriteLine(“Use /dev/null instead of nul. On Windows bash, ‘> nul’ creates an undeletable file.”) exit 2

} catch { exit 0 } ``` Then add a PreToolUse hook to CC: “PreToolUse”: [ { “matcher”: “Bash”, “hooks”: [ { “type”: “command”, “command”: “cmd.exe /c "powershell -NoProfile -ExecutionPolicy Bypass -File "%USERPROFILE%\.claude\hooks\fix-nul-redirect.ps1""”, “timeout”: 5 } ] } ] No more nul files in your project root. submitted by /u/SmallKiwi

Originally posted by u/SmallKiwi on r/ClaudeCode