-
Notifications
You must be signed in to change notification settings - Fork 725
Expand file tree
/
Copy pathsetup-init.sh
More file actions
executable file
·50 lines (43 loc) · 1.26 KB
/
Copy pathsetup-init.sh
File metadata and controls
executable file
·50 lines (43 loc) · 1.26 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
#!/bin/bash
# setup-init.sh
# Runs when Claude Code starts (v2.1.10+)
# Use with --init, --init-only, or --maintenance flags
INPUT=$(cat)
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
CWD=$(echo "$INPUT" | jq -r '.cwd // "unknown"')
# Create log directory if needed
LOG_DIR="$HOME/.claude/logs"
mkdir -p "$LOG_DIR"
# Log startup event
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "[$TIMESTAMP] Setup hook triggered - Session: $SESSION_ID - CWD: $CWD" >> "$LOG_DIR/setup.log"
# Check project requirements
if [[ -f "package.json" ]]; then
# Check if node_modules exists
if [[ ! -d "node_modules" ]]; then
cat << EOF
{
"systemMessage": "⚠️ Project setup incomplete: node_modules missing. Run 'npm install' before continuing.",
"hookSpecificOutput": {
"additionalContext": "Node.js project detected without dependencies installed."
}
}
EOF
exit 0
fi
fi
# Check git status
if git rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git branch --show-current)
UNCOMMITTED=$(git status --short | wc -l | tr -d ' ')
if [[ $UNCOMMITTED -gt 0 ]]; then
cat << EOF
{
"hookSpecificOutput": {
"additionalContext": "Git status: On branch $BRANCH with $UNCOMMITTED uncommitted changes."
}
}
EOF
fi
fi
exit 0