Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Claude Code Windows Hook Fix

Fix for Claude Code v2.1.x hooks failing on Windows with "No such file or directory" errors.

The Problem

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.

Quick Fix

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.sh

What It Does

Changes 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.

⚠️ Important

This patch is overwritten when Claude Code updates. Re-run after updates.

Affected Versions

  • Claude Code v2.1.x on Windows with Git Bash
  • Confirmed on v2.1.9, v2.1.11

Related

License

MIT

About

Fix for Claude Code v2.1.x hooks failing on Windows with 'No such file or directory' errors

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages