[BUG] Built-in PreToolUse:Edit hook falsely blocks edits containing // (e.g. PHP/JS comments)
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?
A built-in PreToolUse:Edit hook blocks Edit operations when tool_input contains // (double forward slash) that is not part of ://. This means any edit involving PHP, JavaScript, or C-style comments (// comment) can be blocked, because the hook misidentifies // in comments as a UNC network path.
The hook is a node -e one-liner that concatenates all tool_input values (file_path, old_string, new_string), converts to lowercase, and checks for Windows/UNC path patterns. The relevant check is:
const unc = v.includes(bs+bs) || (v.includes('//') && !v.includes('://'));
Since PHP/JS/C/C++ comments start with // and do not contain ://, they match this UNC path check and the hook calls process.exit(2) to block the edit.
In practice, this makes it impossible to add, modify, or remove any //-style comment using the Edit tool.
Full hook source (from error message):
node -e "const c=[];process.stdin.on('data',d=>c.push(d));process.stdin.on('end',()=>{try{const t=JSON.parse(Buffer.concat(c));const v=Object.values(t.tool_input||{}).join(' ').toLowerCase();const bs=String.fromCharCode(92);const drives='defghijklmnopqrstuvwxyz'.split('');const win=drives.some(d=>v.includes(d+':/')||v.includes(d+':'+bs));const wsl=drives.some(d=>v.includes('/mnt/'+d+'/'));const unc=v.includes(bs+bs)||(v.includes('//')&&!v.includes('://'));if(win||wsl||unc)process.exit(2);}catch(e){process.exit(2);}});process.stdin.resume();"
"disableAllHooks": true in settings does NOT disable this built-in hook.
What Should Happen?
The Edit tool should be able to edit, add, or remove //-style comments in any language. The hook's UNC path detection should not match language comment syntax.
Error Messages/Logs
● Update(src/Controller/ExampleController.php)
⎿ Error: PreToolUse:Edit hook error: [node -e "const c=[];process.stdin.on('data',d=>c.push(d));process.stdin.on('end',()=>{try{const t=JSON.parse(Buffer.concat(c));const v=Object.values(t.tool_input||{}).join(' ').toLowerCase();const bs=String.fromCharCode(92);const drives='defghijklmnopqrstuvwxyz'.split('');const win=drives.some(d=>v.includes(d+':/')||v.includes(d+':'+bs));const wsl=drives.some(d=>v.includes('/mnt/'+d+'/'));const unc=v.includes(bs+bs)||(v.includes('//')&&!v.includes('://'));if(win||wsl||unc)process.exit(2);}catch(e){process.exit(2);}});process.stdin.resume();"]: No stderr output
Steps to Reproduce
- Create any PHP file containing a
//comment:
``php``
<?php
// This is a comment
function hello() {
return "world";
}
- Ask Claude Code to remove or modify the comment (e.g. "remove the comment from this file")
- Claude attempts to use the Edit tool with
old_stringcontaining// This is a comment - The built-in hook detects
//as a UNC path pattern and blocks the edit
Note: /* */ block comments can be edited and deleted without any issues — only // single-line comments are affected. This confirms the // pattern match is the cause.
This also affects JavaScript (// comment), TypeScript, C, C++, Java, Go, Rust, Swift, Kotlin — any language that uses // for single-line comments.
The same hook also blocks edits on Windows and WSL paths (C:\, /mnt/c/), but the // comment issue affects all platforms including macOS and Linux.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.91 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗