Auto-rename active session to match current git branch
The problem
Claude Code sessions are branch-scoped in everyday use: a feature branch is a unit of work, a session is the conversation context for that unit of work, and they have a 1:1 relationship for most projects. But the session title doesn't reflect that — it's set once at launch (manually via claude -n, or via the shell history of the first user prompt) and never updates afterward.
The result: after even a few hours of work that involves switching branches, the session picker becomes unnavigable.
Concrete scenarios where this bites
1. Two sessions in the same project on different branches.
I have one Claude Code session open on branch CustomLFO working on a feature, and another open on main for unrelated triage. From the session picker they look identical — both labeled by the project name. I have to attach to one and check git branch --show-current (or the chat history) to figure out which is which.
2. In-session checkout.
I start a session named feature-A, finish that branch, merge it, switch to feature-B, and keep working in the same session. The session is now doing feature-B work but the title still says feature-A. Three sessions later, the names have no relationship to the actual work being done.
3. New branches.
I git checkout -b some-new-branch inside a session. The session has no way to know about this new context. From the picker it's still labeled by whatever was current at launch — a branch that may not even exist anymore.
The mental model
The branch is the work item. The session is the conversation about that work item. They should have the same name by default, with the session auto-following the branch as the user moves between work items. This is consistent with how IDEs treat the branch as ambient context (status bars, terminal prompts, etc.).
Proposed behavior
When Claude Code observes a working-directory branch change — via post-Bash git checkout, a lightweight HEAD-watch heartbeat, or a chdir into a different repo — automatically set the session title to $(git branch --show-current) (with sensible fallbacks: detached-HEAD → short SHA + (detached); non-git → don't rename).
Opt-out via a setting for users who prefer intent-based naming:
// ~/.claude/settings.json
{
"session": {
"autoNameFromGitBranch": true // default true in git repos
}
}
If the user has explicitly renamed the current session (via /rename), the auto-name should respect that and stop tracking until the user clears the override or restarts. This avoids stomping intentional names like prod-incident-2026-05-26.
Why the existing workarounds fail
Shell alias (alias cl='claude -n "$(git branch --show-current)"'):
- Only fires at launch. In-session checkouts don't update the name.
- Doesn't help for
claude --resumeor session-picker entries from history.
Manual /rename after every checkout:
- Nobody does it consistently. Within a day the picker is full of stale names again.
- It's the wrong shape — the user has already given Claude the information (via
git checkout); requiring a second redundant command is paying the same tax twice.
Looking at the chat history to figure out which session is which:
- Defeats the entire purpose of having titles.
Implementation notes (just food for thought)
A simple version would be a post-Bash hook that checks if the most recent shell command was git checkout, git switch, or git branch -m, and if so, runs git branch --show-current and updates the session title via the same mechanism /rename uses internally. That'd cover the 90% case without needing a polling loop.
A more thorough version would watch .git/HEAD for changes — handles external mutations (a different terminal doing the checkout while Claude is idle).
Workarounds for users today
Until this lands, the closest:
# ~/.zshrc — names a new session by current branch at launch only:
alias cl='claude -n "$(git branch --show-current 2>/dev/null || echo session)"'