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:

  1. A Stop hook fires after the first response
  2. The hook (or a prompt-type hook) generates a short descriptive name from the transcript
  3. 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)

  1. Hook output mechanism: Allow a hook to return a sessionName field in its JSON output that Claude Code applies
  2. CLI command: claude rename <session-id> "name" or claude --rename "name"
  3. Metadata file: A writable file per session (e.g., ~/.claude/sessions/<pid>.json gaining a name field) that Claude Code watches
  4. Prompt hook integration: Allow a prompt-type hook on Stop or SessionStart to return a session name

Environment

  • Windows 11, Git Bash
  • Claude Code 2.1.80

View original on GitHub ↗

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