Fix for Claude Code v2.1.x hooks failing on Windows with "No such file or directory" errors.
Claude Code v2.1.x on Windows has a critical bug where all hooks fail:
/bin/bash: /c/hooks/stop.sh: No such file or directory
This happens because Claude Code invokes bash without the MSYS environment that provides path translation.
Run this in Git Bash:
# Backup and patch
cp "$(npm root -g)/@anthropic-ai/claude-code/cli.js" "$(npm root -g)/@anthropic-ai/claude-code/cli.js.backup"
sed -i 's/hB7(V,\[\],{env:F,cwd:j1(),shell:!0})/hB7(process.env.SHELL||"bash",["-l","-c",V],{env:F,cwd:j1(),shell:!1})/g' "$(npm root -g)/@anthropic-ai/claude-code/cli.js"Or use the included script:
./fix-claude-hooks.shChanges hook execution from:
spawn(command, [], {shell: true})To:
spawn(bash, ["-l", "-c", command], {shell: false})The -l flag runs bash as a login shell, which initializes the MSYS environment including path translation.
This patch is overwritten when Claude Code updates. Re-run after updates.
- Claude Code v2.1.x on Windows with Git Bash
- Confirmed on v2.1.9, v2.1.11
- GitHub Issue #3417
- See
skill.mdfor detailed technical explanation
MIT