mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-23 10:33:32 +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.
* docs: addendum for HOOK-FIX-20260421 (v2.1.116 argv duplication detail)
- Documents Claude Code v2.1.116 argv duplication bug as the underlying
cause of the bash.exe:bash.exe:cannot execute binary file error
- Records night-session fix variant using explicit `bash <path>` prefix
(matches hooks.json observer pattern, avoids EFTYPE on Node spawn)
- Keeps morning commit 527c18b intact; both variants are now documented
---------
Co-authored-by: suusuu0927 <sugi.go.go.gm@gmail.com>
61 lines
1.5 KiB
Bash
61 lines
1.5 KiB
Bash
#!/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"
|