Repository navigation
Expand file tree
/
Copy pathapply-hook-fix.sh
More file actions
60 lines (52 loc) · 1.46 KB
/
Copy pathapply-hook-fix.sh
File metadata and controls
60 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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"