-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsave_state.sh
More file actions
executable file
·40 lines (32 loc) · 1.32 KB
/
save_state.sh
File metadata and controls
executable file
·40 lines (32 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
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# PreCompact hook: save research state before context is compressed
# Captures current working context so long research sessions don't lose
# important state when the conversation approaches context limits.
#
# Saves to .claude/research-state.md — the assistant can read this
# to recover context after compaction.
set -uo pipefail
state_dir="${HOME}/.claude"
state_file="${state_dir}/research-state.md"
mkdir -p "$state_dir"
# Gather current state information
timestamp=$(date -Iseconds)
git_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
git_status=$(git status --short 2>/dev/null | head -20 || echo "not a git repo")
pwd_dir=$(pwd)
cat > "$state_file" << ENDSTATE
# Research State (saved at context compaction)
**Saved**: ${timestamp}
**Directory**: ${pwd_dir}
**Branch**: ${git_branch}
## Recent Git Changes
\`\`\`
${git_status}
\`\`\`
## Note
Context was approaching its limit. This state was auto-saved.
Consider starting a fresh session for complex tasks to avoid
rushed conclusions from compressed context.
ENDSTATE
# Emit advisory message
echo '{"decision": "allow", "reason": "CONTEXT LIMIT: Research state saved to ~/.claude/research-state.md. Long sessions lead to compressed context and potentially rushed conclusions. Consider starting a fresh session if you have complex remaining tasks."}'