In a fresh session, Claude Code usually starts by working out where it is: which branch, what changed, what the last commits were. I’d rather hand it that on a plate. A SessionStart hook runs a command when a session begins, and whatever that command prints to stdout ends up in Claude’s context.
Put this in .claude/settings.json in your project:
{
"hooks": {
"SessionStart": [
{
"matcher": "startup|resume",
"hooks": [
{
"type": "command",
"command": "git status --short --branch && git log --oneline -5"
}
]
}
]
}
}
The matcher decides when it fires. startup is a new session and resume covers --continue, --resume and /resume. You can also match clear (after /clear), compact (after a compaction) and fork. Because the hook runs again on a resume, Claude gets the repo as it is now instead of how it looked yesterday.
Plain text is all you need. Claude Code adds a SessionStart hook’s plain stdout to the context, so there’s no JSON to build. If you ever want more control, the hook can print JSON with hookSpecificOutput.additionalContext instead.
My advice is to keep it small and quick. The hook runs on every session, and Claude’s first answer waits until it’s done. Everything it prints also costs context, and output over 10,000 characters gets moved to a file with only a 2,000-character preview. Five commits and a short status are plenty; a full git log is not. Fixed rules like “use pnpm” belong in CLAUDE.md, which the docs point to as well. The hook is for things that change between sessions.
One catch: in a folder that isn’t a git repository, git exits with an error. Claude Code shows that as a non-blocking hook error and carries on, so nothing breaks, but you’ll see the notice. That’s a good reason to put this hook in a project’s settings file and not in your user settings.
Further reading: SessionStart in the Claude Code hooks reference, Claude Code hooks guide