-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-start.sh
More file actions
executable file
·31 lines (25 loc) · 1.32 KB
/
session-start.sh
File metadata and controls
executable file
·31 lines (25 loc) · 1.32 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
#!/bin/bash
# session-start.sh — Cleans up .claude/recall-context.md on session start.
#
# After compaction, CLAUDE.md is re-read and pulls in recall-context.md via @-reference.
# This hook empties the file AFTER it's been read, preventing stale content from
# persisting into the next compaction or new session.
#
# Hook input (stdin JSON): { "session_id": "...", "cwd": "...", "source": "...", ... }
INPUT=$(cat)
CWD=$(echo "$INPUT" | python3 -c "import json,sys; print(json.load(sys.stdin).get('cwd',''))" 2>/dev/null)
if [ -z "$CWD" ]; then
exit 0
fi
# Always clean up, regardless of source (startup, compact, resume, clear).
# After compaction: CLAUDE.md was already re-read (content consumed), so cleaning is safe.
# Cleaning after compact is important for parallel sessions in the same project —
# stale content from one session's compaction must not leak into another session.
# On fresh starts: prevents leftover content from a previous session (e.g., user exited
# mid-compaction) from being injected into the new session's context.
CONTEXT_FILE="$CWD/.claude/recall-context.md"
# Empty the file if it exists (write a blank placeholder so the @-reference doesn't error)
if [ -f "$CONTEXT_FILE" ]; then
echo "<!-- No recall context available. This file is populated by the PreCompact hook. -->" > "$CONTEXT_FILE"
fi
exit 0