docs(hooks): align README Example 8 with session-end.sh and add install steps (#101)

Closes #99

- Replace shell-interpolated JSON build with the argv-based Python pattern
  from session-end.sh, so notes containing quotes or backslashes don't
  produce invalid JSON.
- Add mkdir/cp/chmod install block before the Configuration section so
  the path in settings.json resolves to a real file.
This commit is contained in:
Luong NGUYEN
2026-04-27 00:01:43 +02:00
committed by GitHub
parent e43872e9bd
commit 8e2b745749
+23 -4
View File
@@ -1030,14 +1030,25 @@ done | paste -sd ',' -)
printf " Notes? (optional, press Enter to skip): "
read -r NOTES </dev/tty
SESSION="{\"date\":\"$DATE\",\"time\":\"$TIME\",\"modules\":[${MODULES_JSON}],\"notes\":\"${NOTES}\"}"
python3 - "$PROGRESS_FILE" "$SESSION" <<'PYEOF'
# Pass NOTES as a separate argument so Python handles JSON escaping —
# avoids broken JSON when notes contain quotes or backslashes.
python3 - "$PROGRESS_FILE" "$DATE" "$TIME" "$MODULES_JSON" "$NOTES" <<'PYEOF'
import sys, json
path, new_session = sys.argv[1], json.loads(sys.argv[2])
path, date, time_str, modules_raw, notes = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]
new_session = {
"date": date,
"time": time_str,
"modules": json.loads(f"[{modules_raw}]") if modules_raw else [],
"notes": notes,
}
with open(path, 'r') as f:
data = json.load(f)
data.setdefault('sessions', []).append(new_session)
with open(path, 'w') as f:
json.dump(data, f, indent=2)
PYEOF
@@ -1045,6 +1056,14 @@ PYEOF
echo " Saved to $PROGRESS_FILE"
```
**Install** — copy the script into the project's hook directory so the path in `settings.json` resolves:
```bash
mkdir -p .claude/hooks
cp 06-hooks/session-end.sh .claude/hooks/
chmod +x .claude/hooks/session-end.sh
```
**Configuration** (in `.claude/settings.json`):
```json