run-hook.cmd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. : << 'CMDBLOCK'
  2. @echo off
  3. REM ============================================================================
  4. REM DEPRECATED: This polyglot wrapper is no longer used as of Claude Code 2.1.x
  5. REM ============================================================================
  6. REM
  7. REM Claude Code 2.1.x changed the Windows execution model for hooks:
  8. REM
  9. REM Before (2.0.x): Hooks ran with shell:true, using the system default shell.
  10. REM This wrapper provided cross-platform compatibility by
  11. REM being both a valid .cmd file (Windows) and bash script.
  12. REM
  13. REM After (2.1.x): Claude Code now auto-detects .sh files in hook commands
  14. REM and prepends "bash " on Windows. This broke the wrapper
  15. REM because the command:
  16. REM "run-hook.cmd" session-start.sh
  17. REM became:
  18. REM bash "run-hook.cmd" session-start.sh
  19. REM ...and bash cannot execute a .cmd file.
  20. REM
  21. REM The fix: hooks.json now calls session-start.sh directly. Claude Code 2.1.x
  22. REM handles the bash invocation automatically on Windows.
  23. REM
  24. REM This file is kept for reference and potential backward compatibility.
  25. REM ============================================================================
  26. REM
  27. REM Original purpose: Polyglot wrapper to run .sh scripts cross-platform
  28. REM Usage: run-hook.cmd <script-name> [args...]
  29. REM The script should be in the same directory as this wrapper
  30. if "%~1"=="" (
  31. echo run-hook.cmd: missing script name >&2
  32. exit /b 1
  33. )
  34. "C:\Program Files\Git\bin\bash.exe" -l "%~dp0%~1" %2 %3 %4 %5 %6 %7 %8 %9
  35. exit /b
  36. CMDBLOCK
  37. # Unix shell runs from here
  38. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  39. SCRIPT_NAME="$1"
  40. shift
  41. "${SCRIPT_DIR}/${SCRIPT_NAME}" "$@"