Claude Code can run a hook when a session starts. That is the right place to inject context you always want: current branch, dirty files, open TODOs — without typing it every time.
Minimal SessionStart hook
In .claude/settings.json (or settings.local.json for personal-only rules):
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "bash -lc 'echo \"## Session context\"; echo \"Branch: $(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo n/a)\"; echo; git status -sb 2>/dev/null | head -40'"
}
]
}
]
}
}
When Claude Code opens, the command runs once. Its stdout is added to the session context, so the model already knows which branch you are on and what is dirty.
Keep it short
- Cap the output (
head -40) so you do not dump a huge status into every chat. - Prefer
settings.local.jsonif the hook is personal and should stay out of git. - Fail soft: wrap git calls so a non-repo folder does not break session start.
Pair it with house rules
Your project CLAUDE.md still loads as usual. The SessionStart hook is for live facts (branch, status); put stable rules (coding style, never push main) in CLAUDE.md instead.
Want the rest of the setup?
I keep copy-ready Claude Code configs (CLAUDE.md templates, slash commands, hooks, permission rules) in Vildanden Agent Config. There's a free sample: https://justly-mia-429.rehost.page/
Top comments (1)
One thing that bit me with SessionStart: the facts go stale inside long sessions. I run a few Claude Code sessions on the same repo (my PC plus a VPS that pulls every couple of minutes), so the branch and dirty-file snapshot from the start of a session was wrong a few hours later, and the model kept working from it.
I moved the injection to UserPromptSubmit and kept it cheap: hash a short list of shared state files, compare against a stored manifest, and print only the paths that changed plus a "stale" flag. Most prompts get one line. When something moved under the session, it gets the list. This morning it flagged 26 changed paths in a session I'd have trusted otherwise.
Agree on the split, by the way. Live facts in the hook, stable rules in CLAUDE.md.