#!/bin/bash
# Save session state when stopping

STATE_DIR=".claude/state"
STATE_FILE="$STATE_DIR/session.json"

# Ensure state directory exists
mkdir -p "$STATE_DIR"

# Get current timestamp
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Create or update state file
cat > "$STATE_FILE" << EOF
{
  "lastUpdated": "$TIMESTAMP",
  "workingDirectory": "$(pwd)",
  "gitBranch": "$(git branch --show-current 2>/dev/null || echo 'none')",
  "gitStatus": "$(git status --porcelain 2>/dev/null | head -5 | tr '\n' ' ' || echo 'clean')"
}
EOF

echo "✓ Session state saved"
exit 0
