fix: prevent undeletable nul file on Windows#13406
Open
ASidorenkoCode wants to merge 1 commit intoanomalyco:devfrom
Open
fix: prevent undeletable nul file on Windows#13406ASidorenkoCode wants to merge 1 commit intoanomalyco:devfrom
ASidorenkoCode wants to merge 1 commit intoanomalyco:devfrom
Conversation
On Windows, OpenCode uses Git Bash as the shell. When the AI model generates Windows-style `> nul` or `2>nul` redirection, Git Bash interprets this literally and creates a file named `nul` instead of routing to the null device. Since `nul` is a reserved Windows device name, the file cannot be deleted through normal Windows file operations. This adds a `sanitizeNullRedirect()` helper that rewrites null-device redirections to match the actual shell: `>nul` becomes `>/dev/null` for Git Bash, and vice versa for cmd.exe/PowerShell. Applied in both the bash tool and the shell execution path. Also adds guidance to the bash tool description so models prefer `/dev/null`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The regex The |
|
How to delete the undeletable file: https://dev.to/tishonator/how-to-delete-the-un-deletable-nul-file-created-by-claude-console-on-windows-11-33a9 (Still needs fixing, of course.) |
This was referenced Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, OpenCode uses Git Bash as the shell for executing commands. When the AI model generates commands with Windows-style
> nulor2>nulredirection, Git Bash interprets this literally (creating a file namednul) instead of routing to the null device. Sincenulis a reserved Windows device name, the file cannot be deleted through normal Windows file operations.Before (v1.1.63) —
nulfile created, shows in Modified FilesThe undeletable
nulfile in Windows ExplorerAfter (this fix) — no
nulfile createdRoot cause
spawn('echo test 2>nul', { shell: 'C:/Program Files/Git/bin/bash.exe' })creates a literalnulfile because Git Bash doesn't recognizenulas a Windows null device — it treats it as a regular filename.Fix
Two-pronged approach:
Command sanitization (
Shell.sanitizeNullRedirect()): Before spawning any command, rewrites null-device redirections to match the actual shell:>nul/2>nul→>/dev/null/2>/dev/null>/dev/null→>NUL(reverse direction)Applied in both
bash.ts(tool execution) andprompt.ts(shell execution path).Model guidance: Added a note to the bash tool description instructing models to use
/dev/nullinstead ofnulon Windows.Changes
packages/opencode/src/shell/shell.ts: AddedisUnixLike()andsanitizeNullRedirect()utilities to theShellnamespacepackages/opencode/src/tool/bash.ts: CallShell.sanitizeNullRedirect()before spawningpackages/opencode/src/tool/bash.txt: Added Windows/dev/nullguidance for modelspackages/opencode/src/session/prompt.ts: CallShell.sanitizeNullRedirect()before spawning in shell execution pathTested
On Windows 11 with Git Bash. Before:
echo test 2>nulcreates an undeletablenulfile. After: nonulfile is created, output is correctly suppressed.Fixes #13369
Fixes #11586
Fixes #11403
Fixes #8108