mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-23 02:23:33 +08:00
fix: resolve Claude Code Bash hook "cannot execute binary file" on Windows
Root cause in ~/.claude/settings.local.json (user-global): 1. UTF-8 BOM + CRLF line endings left by patch_settings_cl_v2_simple.ps1 2. Double-wrapped command "\"bash.exe\" \"wrapper.sh\"" broke Windows argument splitting on the space in "Program Files", making bash.exe try to execute itself as a script. Fix: - Rewrite settings.local.json as UTF-8 (no BOM), LF, with the hook command pointing directly at observe-wrapper.sh and passing "pre"/"post" as a positional arg so HOOK_PHASE is populated correctly in observe.sh. Docs: - docs/fixes/HOOK-FIX-20260421.md — full root-cause analysis. - docs/fixes/apply-hook-fix.sh — idempotent applier script.
This commit is contained in:
60
docs/fixes/apply-hook-fix.sh
Normal file
60
docs/fixes/apply-hook-fix.sh
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
# Apply ECC hook fix to ~/.claude/settings.local.json.
|
||||
#
|
||||
# - Creates a timestamped backup next to the original.
|
||||
# - Rewrites the file as UTF-8 (no BOM), LF line endings.
|
||||
# - Routes hook commands directly at observe-wrapper.sh with a "pre"/"post" arg.
|
||||
#
|
||||
# Related fix doc: docs/fixes/HOOK-FIX-20260421.md
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TARGET="${1:-$HOME/.claude/settings.local.json}"
|
||||
WRAPPER="${ECC_OBSERVE_WRAPPER:-$HOME/.claude/skills/continuous-learning/hooks/observe-wrapper.sh}"
|
||||
|
||||
if [ ! -f "$WRAPPER" ]; then
|
||||
echo "[hook-fix] wrapper not found: $WRAPPER" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$TARGET")"
|
||||
|
||||
if [ -f "$TARGET" ]; then
|
||||
ts="$(date +%Y%m%d-%H%M%S)"
|
||||
cp "$TARGET" "$TARGET.bak-hookfix-$ts"
|
||||
echo "[hook-fix] backup: $TARGET.bak-hookfix-$ts"
|
||||
fi
|
||||
|
||||
# Convert wrapper path to forward-slash form for JSON.
|
||||
wrapper_fwd="$(printf '%s' "$WRAPPER" | tr '\\\\' '/')"
|
||||
|
||||
# Write the new config as UTF-8 (no BOM), LF line endings.
|
||||
printf '%s\n' '{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "*",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "'"$wrapper_fwd"' pre"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "*",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "'"$wrapper_fwd"' post"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}' > "$TARGET"
|
||||
|
||||
echo "[hook-fix] wrote: $TARGET"
|
||||
echo "[hook-fix] restart the claude CLI for changes to take effect"
|
||||
Reference in New Issue
Block a user