Skip to content

feat: show session name from /rename in notification title#1

Open
PhilipeeX wants to merge 2 commits into
polyphilz:mainfrom
PhilipeeX:feat/session-name-in-notifications
Open

feat: show session name from /rename in notification title#1
PhilipeeX wants to merge 2 commits into
polyphilz:mainfrom
PhilipeeX:feat/session-name-in-notifications

Conversation

@PhilipeeX

@PhilipeeX PhilipeeX commented Apr 13, 2026

Copy link
Copy Markdown

Summary

When users rename their Claude Code sessions with /rename, the custom name now appears in the notification subtitle alongside the project name:

  • Before: core
  • After: core · my-session

This makes it easy to identify which session triggered a notification when running multiple Claude Code instances.

How it works

  1. Walks up the process tree from the hook script to find the Claude Code PID
  2. Looks up ~/.claude/sessions/{PID}.json for the matching session file
  3. Extracts the name field (set by /rename)
  4. Appends it to the notification subtitle

Sessions without a custom name keep the original format unchanged — fully backward compatible.

Why PID ancestry instead of session_id?

The session_id in the hook JSON payload is a conversation/transcript ID, which differs from the sessionId stored in ~/.claude/sessions/*.json. However, the session files are named by the Claude Code process PID, so walking up the process tree reliably finds the correct file.

Test plan

  • Tested with a renamed session — subtitle shows core · Analytics database
  • Tested with Stop hook (real Claude Code trigger) — session name appears correctly
  • Tested with Needs Input hook — session name appears correctly
  • Tested with unnamed session — subtitle shows core (unchanged)
  • Tested /rename mid-session — next notification picks up the new name immediately

example:
image

Reads the session_id from the hook JSON payload and looks up the
corresponding session file in ~/.claude/sessions/ to extract the
name set by Claude Code's /rename command.

When a session has been renamed, notifications display:
  "Claude Code [session-name] — Done"
  "Claude Code [session-name] — Needs Input"

Sessions without a custom name keep the original format unchanged.
The session_id in the hook JSON payload differs from the sessionId
stored in ~/.claude/sessions/ files. Instead, walk up the process
tree to find the Claude Code PID that matches a session file.

Also moves the session name from the notification title to the
subtitle for better readability (title was being truncated).

Result: "core · Analytics database" in subtitle instead of
"Claude Code [Analytics database] — D..." in truncated title.
@PhilipeeX

Copy link
Copy Markdown
Author

@polyphilz 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant