Allow hooks to set session name via response field

Resolved 💬 3 comments Opened Mar 17, 2026 by cballou Closed Mar 21, 2026

Problem

There's no way for hooks to programmatically set the session name. The only options are --name at launch time or /rename interactively mid-session.

For users who keep a single Claude Code session running across multiple features/branches (never restarting), the session name goes stale quickly. A SessionStart hook can nudge the user to run /rename, but it can't do it automatically — and there's no hook event for "branch changed" or "new task started" that could trigger it later.

Proposed Solution

Add a sessionName field to the hook JSON response schema:

{
  "systemMessage": "...",
  "sessionName": "opensea-data:feature/new-endpoint"
}

When a hook returns sessionName, Claude Code updates the session name (and terminal tab title) as if /rename had been called.

This would be useful on any hook event, but especially:

  • SessionStart — auto-name based on repo + branch
  • UserPromptSubmit — detect branch changes and update the name dynamically

Use Case

# In a SessionStart hook:
REPO=$(git remote get-url origin 2>/dev/null | sed 's/.*\///;s/\.git$//')
BRANCH=$(git branch --show-current 2>/dev/null)
if [[ -n "$REPO" ]]; then
  NAME="${REPO}:${BRANCH:-main}"
else
  NAME="$(basename "$PWD")"
fi
echo "{\"sessionName\": \"$NAME\"}"

Current Workaround

SessionStart hook emits a systemMessage nudging the user/agent to run /rename <suggested-name> manually. Works but adds friction and context noise.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗