Claude Hookbook

Hooks / context

Session-start repo snapshot

Hands Claude a bounded snapshot - branch, dirty state, recent commits - at every session start and resume.

SessionStartstartup|resumelow riskneeds manual check

What 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

EventSessionStart
Matcherstartup|resume
Scopeproject
Platformsmacos, linux
Timeout10s
Requiresgit
Failure modeobserve
Verified againstClaude Code hooks reference, event/matcher schema checked 2026-09-10
Test statusneeds 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

  1. Save the script to .claude/hooks/session-start-snapshot.sh and chmod +x it.
  2. Add the config fragment to .claude/settings.json.

Test it

Sources

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 check

Pro Pack (later)

Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.

Waitlist opens soon.