A Claude Code SessionStart hook that keeps the status-line branch label in sync with your actual git branch.
When you switch git branches and resume a conversation with --resume, the Claude Code UI continues showing the branch from the original session start. (#37429)
The hook runs git branch --show-current at every session start and emits a status-line update so the displayed branch always matches reality. It handles detached HEAD states gracefully by showing the short commit SHA.
# Clone and install
git clone <repo-url> && cd git-branch-refresh
bash install.shThis adds a SessionStart hook to ~/.claude/settings.json. No other configuration is needed.
- jq — used by the installer to safely merge into your settings file
- Git 2.22+ — for
git branch --show-current(older versions fall back torev-parse)
If you prefer, add the hook to ~/.claude/settings.json yourself:
{
"hooks": {
"SessionStart": [
{
"type": "command",
"command": "/absolute/path/to/git-branch-refresh.sh"
}
]
}
}Remove the git-branch-refresh.sh entry from the SessionStart array in ~/.claude/settings.json.
make test # syntax check (bash -n)
make lint # shellcheck