Files
everything-claude-code/docs/fixes/INSTALL-HOOK-WRAPPER-FIX-20260422.md
suusuu0927 c32f0fffb1 fix(hooks): rewrite install_hook_wrapper.ps1 to avoid argv-dup bug
Under Claude Code v2.1.116 the first argv token of a hook command is
duplicated. When the token is a quoted Windows .exe path, bash.exe is
re-invoked with itself as script (exit 126). PR #1524 fixed the shape
of settings.local.json; this script keeps the installer consistent so
re-running it does not regenerate the broken form.

Changes:
- First token is now PATH-resolved `bash` instead of the quoted bash.exe
- Wrapper path is normalized to forward slashes for MSYS safety
- PreToolUse and PostToolUse get distinct pre/post positional arguments
- JSON output is written with LF endings (no mixed CRLF/LF)

Companion doc: docs/fixes/INSTALL-HOOK-WRAPPER-FIX-20260422.md
2026-04-22 06:19:15 +09:00

2.0 KiB

install_hook_wrapper.ps1 argv-dup bug workaround (2026-04-22)

Summary

docs/fixes/install_hook_wrapper.ps1 is the PowerShell helper that copies observe-wrapper.sh into ~/.claude/skills/continuous-learning/hooks/ and rewrites ~/.claude/settings.local.json so the observer hook points at it.

The previous version produced a hook command of the form:

"C:\Program Files\Git\bin\bash.exe" "C:\Users\...\observe-wrapper.sh"

Under Claude Code v2.1.116 the first argv token is duplicated. When that token is a quoted Windows executable path, bash.exe is re-invoked with itself as its $0, which fails with cannot execute binary file (exit 126). PR #1524 documents the root cause; this script is a companion that keeps the installer in sync with the fixed settings.local.json layout.

What the fix does

  • First token is now the PATH-resolved bash (no quoted .exe path), so the argv-dup bug no longer passes a binary as a script.
  • The wrapper path is normalized to forward slashes before it is embedded in the hook command, avoiding MSYS backslash handling surprises.
  • PreToolUse and PostToolUse receive distinct commands with explicit pre / post positional arguments, matching the shape the wrapper expects.
  • The settings file is written with LF line endings so downstream JSON parsers never see mixed CRLF/LF output from ConvertTo-Json.

Resulting command shape

bash "C:/Users/<you>/.claude/skills/continuous-learning/hooks/observe-wrapper.sh" pre
bash "C:/Users/<you>/.claude/skills/continuous-learning/hooks/observe-wrapper.sh" post

Usage

# Place observe-wrapper.sh next to this script, then:
pwsh -File docs/fixes/install_hook_wrapper.ps1

The script backs up settings.local.json to settings.local.json.bak-<timestamp> before writing.

  • PR #1524 — settings.local.json shape fix (same argv-dup root cause)
  • PR #1511 — skip AppInstallerPythonRedirector.exe in observer python resolution
  • PR #1539 — locale-independent detect-project.sh