Session-start repo snapshot
Hands Claude a bounded snapshot - branch, dirty state, recent commits - at every session start and resume.
SessionStartstartup|resumelow riskneeds manual checkWhat it does
Fires on SessionStart for startup and resume. Prints the current branch, a one-line dirty-file count, and the last 5 commits to stdout, which SessionStart adds to context. Bounded on purpose: a wall of git log at every start is context pollution, not context.
When it runs
| Event | SessionStart |
| Matcher | startup|resume |
| Scope | project |
| Platforms | macos, linux |
| Timeout | 10s |
| Requires | git |
| Failure mode | observe |
| Verified against | Claude Code hooks reference, event/matcher schema checked 2026-09-10 |
| Test status | needs manual check - run the test steps below before relying on it |
Config
Merge this into .claude/settings.json - or use the generator to combine hooks.
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/session-start-snapshot.sh",
"timeout": 10
}
],
"matcher": "startup|resume"
}
]
}
}Script
Save as .claude/hooks/session-start-snapshot.sh and chmod +x it.
#!/bin/bash
# session-start-snapshot: bounded git snapshot into context.
set -u
cd "${CLAUDE_PROJECT_DIR:-$PWD}" || exit 0
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
branch=$(git branch --show-current 2>/dev/null || echo detached)
dirty=$(git status --porcelain 2>/dev/null | wc -l | tr -d ' ')
echo "Repo snapshot: branch=$branch, uncommitted files=$dirty"
echo "Recent commits:"
git log --oneline -5 2>/dev/null
exit 0
Install
- Save the script to .claude/hooks/session-start-snapshot.sh and chmod +x it.
- Add the config fragment to .claude/settings.json.
Test it
- Positive: start a session in a repo with uncommitted changes - Claude knows the branch and dirty count without running git itself.
- Negative: outside a git repo, nothing is printed.
Sources
- Claude Code hooks reference (checked 2026-09-10)
Related hooks
Re-inject project context after compaction
Restores your project's key facts into Claude's context right after a compaction wipes the details.
SessionStartcompactlow riskneeds manual checkPro Pack (later)
Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.
Waitlist opens soon.