All articles

Running Checks When a Session Starts

Every session starts cold. Claude does not automatically know your current branch, what is uncommitted, or what changed since yesterday. A SessionStart hook fixes that by running a command the moment a session begins.

The basic idea

SessionStart fires once at the start of a session. It takes no tool matcher, since it is a lifecycle event rather than a tool call. A minimal version just surfaces your git state:

{
  "hooks": {
    "SessionStart": [
      { "hooks": [{ "type": "command", "command": "git status --short && git log --oneline -5" }] }
    ]
  }
}

Loading real context

The pattern shines when you feed in state that Claude should know before it does anything. A short script can gather several things at once:

#!/usr/bin/env bash
echo "== Current branch =="
git branch --show-current
echo "== Uncommitted files =="
git status --short
echo "== Open TODOs =="
grep -rn "TODO" src | head -20

Point your SessionStart hook at that script and every session opens with the branch, the working state, and outstanding TODOs already in view.

Good uses

Think about what you always end up telling Claude by hand at the start of a task. That is your hook's job. Common picks are the current branch and diff, recent commits, failing tests, or a note about which service you are working on.

Keep it fast and quiet

This runs on every session, so keep it quick. Avoid slow network calls or huge dumps of output that bury the useful bits. A tight, well-chosen summary means Claude starts productive instead of spending the first few turns rediscovering where things stand.

Comments

Be the first to comment.