2026-07-07 14:05:36 -07:00
|
|
|
#!/bin/sh
|
2026-07-08 15:02:13 -07:00
|
|
|
# Sync the current project if it is a beardrive project (has a .bdrive/ settings dir).
|
2026-07-07 14:05:36 -07:00
|
|
|
# Fast no-op otherwise, so this hook is safe on every turn in every project.
|
|
|
|
|
#
|
|
|
|
|
# Runs blocking on UserPromptSubmit (fresh files before Claude reads them)
|
|
|
|
|
# and async on Stop (push edits out without delaying the turn).
|
2026-07-11 10:56:53 -07:00
|
|
|
#
|
|
|
|
|
# Hooks receive JSON on stdin with a session_id; it is passed as the sync
|
|
|
|
|
# note so every change journaled during this session — including ones the
|
|
|
|
|
# background daemon commits — is stamped with the Claude Code session that
|
|
|
|
|
# made it, and shows up in `bdrive log` and the hub's history views.
|
2026-07-07 14:05:36 -07:00
|
|
|
cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0
|
2026-07-08 15:02:13 -07:00
|
|
|
[ -d .bdrive ] || exit 0
|
2026-07-07 15:02:40 -07:00
|
|
|
command -v bdrive >/dev/null 2>&1 || exit 0
|
2026-07-11 10:56:53 -07:00
|
|
|
sid=""
|
|
|
|
|
if [ ! -t 0 ]; then
|
|
|
|
|
sid=$(head -c 8192 | sed -n 's/.*"session_id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)
|
|
|
|
|
fi
|
|
|
|
|
if [ -n "$sid" ]; then
|
|
|
|
|
bdrive sync . --note "claude-code session $sid" >/dev/null 2>&1 || true
|
|
|
|
|
else
|
|
|
|
|
bdrive sync . >/dev/null 2>&1 || true
|
|
|
|
|
fi
|