#!/usr/bin/env bash
# Auto-commit any staged or unstaged changes at session end.
# Called by Stop + SessionEnd hooks in .claude/settings.local.json (async).
# Never pushes — auto-sync.sh cron handles push separately.

set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
cd "$REPO_ROOT"

# Nothing to do if working tree clean
if git diff --quiet && git diff --cached --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then
  exit 0
fi

TIMESTAMP="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
git add -A
git commit -m "auto-commit: session-end $TIMESTAMP

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>"
