-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·163 lines (146 loc) · 4.73 KB
/
setup.sh
File metadata and controls
executable file
·163 lines (146 loc) · 4.73 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Install claude-code-save: session continuity for Claude Code
#
# Usage:
# git clone https://github.com/andrew-shwetzer/claude-code-save.git
# cd claude-code-save
# ./setup.sh
#
# Or run directly:
# curl -sSL https://raw.githubusercontent.com/andrew-shwetzer/claude-code-save/main/setup.sh | bash
set -e
SYNC_REMOTE=""
for arg in "$@"; do
case "$arg" in
--sync=*) SYNC_REMOTE="${arg#--sync=}" ;;
--sync) shift; SYNC_REMOTE="$1" ;;
esac
done
# Detect if running from cloned repo or piped from curl
if [ -f "$(dirname "$0")/commands/save.md" ]; then
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
else
# Running from curl pipe: clone to temp dir
TMPDIR=$(mktemp -d)
echo "Downloading claude-code-save..."
git clone --quiet https://github.com/andrew-shwetzer/claude-code-save.git "$TMPDIR/claude-code-save"
SCRIPT_DIR="$TMPDIR/claude-code-save"
trap "rm -rf $TMPDIR" EXIT
fi
CLAUDE_DIR="$HOME/.claude"
SAVES_DIR="$CLAUDE_DIR/saves"
COMMANDS_DIR="$CLAUDE_DIR/commands"
HOOKS_DIR="$CLAUDE_DIR/hooks"
SCRIPTS_DIR="$SAVES_DIR/scripts"
echo ""
echo " Installing claude-code-save"
echo " ==========================="
echo ""
# 1. Create directories
mkdir -p "$SAVES_DIR" "$COMMANDS_DIR" "$HOOKS_DIR" "$SCRIPTS_DIR"
# 2. Install commands
for cmd in save.md load.md saves.md; do
cp "$SCRIPT_DIR/commands/$cmd" "$COMMANDS_DIR/$cmd"
echo " + /$(basename $cmd .md) command"
done
# 3. Install hook
cp "$SCRIPT_DIR/hooks/save-progress.sh" "$HOOKS_DIR/save-progress.sh"
chmod +x "$HOOKS_DIR/save-progress.sh"
echo " + SessionEnd hook"
# 4. Install helper scripts
cp "$SCRIPT_DIR/scripts/detect-project.sh" "$SCRIPTS_DIR/detect-project.sh"
chmod +x "$SCRIPTS_DIR/detect-project.sh"
echo " + detect-project.sh"
# 5. Create default config if none exists
if [ ! -f "$SAVES_DIR/config.json" ]; then
SYNC_ENABLED="false"
[ -n "$SYNC_REMOTE" ] && SYNC_ENABLED="true"
cat > "$SAVES_DIR/config.json" << CONFIGEOF
{
"max_saves_per_project": 50,
"projects": {},
"sync": {
"enabled": $SYNC_ENABLED
},
"markdown_progress": {
"enabled": true,
"directory": "~/Desktop/Claude Completed Tasks"
}
}
CONFIGEOF
echo " + default config"
fi
# 5b. Set up git sync if --sync was provided
if [ -n "$SYNC_REMOTE" ]; then
if [ ! -d "$SAVES_DIR/.git" ]; then
cd "$SAVES_DIR"
git init --quiet
# Don't track config.json (machine-specific)
echo "config.json" > .gitignore
git add -A
git commit -m "init: claude-code-save sync" --quiet --no-gpg-sign 2>/dev/null || true
git remote add origin "$SYNC_REMOTE" 2>/dev/null || git remote set-url origin "$SYNC_REMOTE"
git branch -M main 2>/dev/null || true
echo " + git sync initialized (remote: $SYNC_REMOTE)"
echo ""
echo " Run 'cd ~/.claude/saves && git push -u origin main' to complete setup."
echo " After that, saves auto-sync on every /save and session exit."
cd - >/dev/null 2>&1
else
# Already a git repo, just update remote
cd "$SAVES_DIR"
git remote set-url origin "$SYNC_REMOTE" 2>/dev/null || git remote add origin "$SYNC_REMOTE"
echo " + git sync remote updated to: $SYNC_REMOTE"
cd - >/dev/null 2>&1
fi
# Enable sync in config
python3 -c "
import json
with open('$SAVES_DIR/config.json') as f:
cfg = json.load(f)
cfg.setdefault('sync', {})['enabled'] = True
with open('$SAVES_DIR/config.json', 'w') as f:
json.dump(cfg, f, indent=2)
" 2>/dev/null || true
fi
# 6. Create empty index if none exists
touch "$SAVES_DIR/index.jsonl"
# 7. Copy schema for reference
mkdir -p "$SAVES_DIR/schema"
cp "$SCRIPT_DIR/schema/save-state.schema.json" "$SAVES_DIR/schema/" 2>/dev/null || true
# 8. Register hook in settings.json
echo ""
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
HOOK_CMD="$HOME/.claude/hooks/save-progress.sh"
if [ -f "$SETTINGS_FILE" ]; then
if grep -q "save-progress.sh" "$SETTINGS_FILE" 2>/dev/null; then
echo " Hook already registered in settings.json"
else
echo " Add this to your ~/.claude/settings.json SessionEnd hooks:"
echo ""
echo " {\"type\": \"command\", \"command\": \"$HOOK_CMD\", \"timeout\": 30}"
echo ""
fi
else
echo " No settings.json found. To enable auto-save on session exit, create:"
echo ""
echo " ~/.claude/settings.json"
echo ""
echo " {"
echo " \"hooks\": {"
echo " \"SessionEnd\": ["
echo " {\"type\": \"command\", \"command\": \"$HOOK_CMD\", \"timeout\": 30}"
echo " ]"
echo " }"
echo " }"
echo ""
fi
echo " ==========================="
echo " Installed! Commands: /save /load /saves"
echo " Saves stored in: $SAVES_DIR"
echo ""
echo " Quick start:"
echo " /save Save your current session"
echo " /load Resume where you left off"
echo " /saves Browse past saves"
echo ""