Allow hooks to set session name (programmatic /rename)
Resolved 💬 2 comments Opened Mar 22, 2026 by rob-fb Closed Mar 22, 2026
Problem
There's no way to programmatically set a session name from a hook or external process. /rename only works interactively, and there's no CLI equivalent, API, or metadata file that can be modified to trigger a rename.
Use case
I want to automatically name sessions based on conversation content so I can distinguish multiple Claude Code terminal windows at a glance. The ideal flow:
- A
Stophook fires after the first response - The hook (or a
prompt-type hook) generates a short descriptive name from the transcript - The session name updates automatically — reflected in the terminal title and session list
What I tried
- CLAUDE.md directive telling Claude to call
/rename— Claude can't invoke built-in commands - Hook with ANSI escape sequences to set terminal title — subprocess stdout isn't connected to the parent terminal on Windows
- Hook with
cmd //c title— same subprocess isolation issue - Hook writing to
/dev/tty— not functional in Git Bash on Windows - Editing session files in
~/.claude/sessions/— they only contain pid/sessionId/cwd, no name field
Suggested solutions (any of these would work)
- Hook output mechanism: Allow a hook to return a
sessionNamefield in its JSON output that Claude Code applies - CLI command:
claude rename <session-id> "name"orclaude --rename "name" - Metadata file: A writable file per session (e.g.,
~/.claude/sessions/<pid>.jsongaining anamefield) that Claude Code watches - Prompt hook integration: Allow a
prompt-type hook onStoporSessionStartto return a session name
Environment
- Windows 11, Git Bash
- Claude Code 2.1.80
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗