claude-code - 💡(How to fix) Fix [FEATURE] Hook output to set session title from git/PR context at SessionStart [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52478Fetched 2026-04-24 06:06:08
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Timeline (top)
commented ×2labeled ×2closed ×1

When starting a session on a ticket branch or reviewing a PR, I want the session to be automatically named with a meaningful prefix (e.g. BAC-711: AI usage schema or PR #1234: auth refactor). Right now there's no way to do this without manually renaming each session.

Root Cause

Session lists become hard to navigate when every session is named generically. Ticket- and PR-prefixed names make it trivial to resume the right context. This is especially useful in monorepos where many branches/tickets are active simultaneously.

Fix Action

Workaround

Currently: save a memory/instruction telling Claude to suggest the session name in its first response, then rename manually.

Code Example

#!/bin/bash
branch=$(git branch --show-current 2>/dev/null)
if [[ "$branch" =~ bac-([0-9]+) ]]; then
  echo '{"sessionTitle": "BAC-'"${BASH_REMATCH[1]}"': '"$branch"'"}'
fi
RAW_BUFFERClick to expand / collapse

Summary

When starting a session on a ticket branch or reviewing a PR, I want the session to be automatically named with a meaningful prefix (e.g. BAC-711: AI usage schema or PR #1234: auth refactor). Right now there's no way to do this without manually renaming each session.

Desired behavior

Add support for a sessionTitle output from SessionStart hooks (similar to how UserPromptSubmit hooks can return hookSpecificOutput), so a shell script can inspect the git branch or PR context and set a title automatically.

Example hook script:

#!/bin/bash
branch=$(git branch --show-current 2>/dev/null)
if [[ "$branch" =~ bac-([0-9]+) ]]; then
  echo '{"sessionTitle": "BAC-'"${BASH_REMATCH[1]}"': '"$branch"'"}'
fi

Why this matters

Session lists become hard to navigate when every session is named generically. Ticket- and PR-prefixed names make it trivial to resume the right context. This is especially useful in monorepos where many branches/tickets are active simultaneously.

Related issues

  • #40496 — Allow skills/hooks to set session title programmatically
  • #29355 — Allow Claude to programmatically rename sessions
  • #44902 — Docs mention hookSpecificOutput.sessionTitle for UserPromptSubmit (but not SessionStart)

Workaround

Currently: save a memory/instruction telling Claude to suggest the session name in its first response, then rename manually.

extent analysis

TL;DR

Implement a SessionStart hook to automatically set a meaningful session title based on the git branch or PR context.

Guidance

  • Modify the existing hook script to handle both ticket branches and PRs by inspecting the git branch name and PR context.
  • Use the sessionTitle output in the SessionStart hook to set the title automatically, similar to how UserPromptSubmit hooks use hookSpecificOutput.
  • Test the hook script with different branch names and PR contexts to ensure it works as expected.
  • Consider contributing to the related issues (#40496, #29355, #44902) to add official support for programmatically setting session titles.

Example

#!/bin/bash
branch=$(git branch --show-current 2>/dev/null)
pr=$(git rev-parse --github-ref 2>/dev/null)
if [[ "$branch" =~ bac-([0-9]+) ]]; then
  echo '{"sessionTitle": "BAC-'"${BASH_REMATCH[1]}"': '"$branch"'"}'
elif [[ "$pr" =~ pull/([0-9]+) ]]; then
  echo '{"sessionTitle": "PR #'"${BASH_REMATCH[1]}"': '"$branch"'"}'
fi

Notes

The provided hook script only handles ticket branches, and you may need to modify it to handle PRs as well. Additionally, this solution relies on the sessionTitle output being supported in the SessionStart hook, which is not officially documented.

Recommendation

Apply workaround: Implement the modified hook script to automatically set a meaningful session title based on the git branch or PR context, as this provides a functional solution until official support is added.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING