Feature: Programmatic session/thread renaming via hooks or tools
Status Open
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 7 comments · opened Mar 28, 2026
Summary
Add the ability to programmatically rename a Claude Code session/thread mid-conversation via a hook event or tool, rather than requiring manual /rename input.
Use Case
When working with GitHub issues and PRs, I want the session name to automatically reflect what I'm working on:
- Start work on an issue → session name becomes
#42 - Fix auth bug - Create a PR from that work → session name changes to
PR #123 - Fix auth bug
This enables at-a-glance tracking of which conversation maps to which issue/PR, especially when juggling multiple sessions.
Current Behavior
claude -n "name"sets the name at startup (manual, one-time)/renamechanges the name mid-session (manual, interactive-only)- Hooks (e.g., SessionStart) cannot modify session metadata
- No tool or API exists to set the session name programmatically
Proposed Solutions (any of these would work)
- New hook event — e.g.,
RenameSessionthat allows hooks or tools to set the session name - Scriptable
/rename— allow/renameto be called from within tool execution or hook scripts - New built-in tool — a
SetSessionNametool that Claude can call during a conversation (e.g., after creating a PR viagh pr create)
Example Workflow
User: Work on issue #42
Claude: [reads issue, starts work, sets session name to "#42 - Fix auth bug"]
... development happens ...
Claude: [creates PR #123, sets session name to "PR #123 - Fix auth bug"]
Environment
- Claude Code CLI + Desktop App
- macOS
7 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
A
PostToolUsehook can maintain a logical session name based on activity:This auto-updates the terminal title to reflect what you're working on (e.g.,
CC: #42 [fix-auth] auth.ts, middleware.ts). Works with tmux, iTerm2, and most modern terminals.This is essentially the same request as #33165 — a programmatic API for renaming sessions.
I built a workaround skill called
/better-titlethat analyzes the conversation, suggests 3 descriptive titles, and applies the chosen one by appending directly to the session JSONL file: https://github.com/ElliotDrel/elliots-skills/tree/main/better-titleIt works, but it's a hack — a proper rename API or hook event would make this much cleaner.
Another duplicate just filed: #43700 — multi-agent system needing programmatic session IDs. That's at least 3 independent requests for a rename API/tool in the last week.
For reference: #44786 was filed recently with essentially the same request (hooks-callable rename), making this at least the 4th independent ask for a programmatic rename API. The use cases are converging on multi-agent systems needing structured session IDs. Demand is clearly growing — worth keeping this open.
The
PostToolUsehook workaround from @yurukusa is clever but it only sets the terminal title — it doesn't update the session name stored in the JSONL metadata, so the programmatic name doesn't persist in the sessions list or survive terminal restarts. The JSONL-append hack in my/better-titleskill has the same limitation: it works until Claude Code's session indexer rewrites the file.A first-party
SetSessionNametool would solve both cases cleanly and would unblock multi-agent workflows where the orchestrator needs stable, human-readable session identifiers to route context between agents.Cross-session messaging (2.1.224+) turned the session name into an address rather than a label, which makes this worth more than cosmetics.
SendMessageaddresses a peer by its exact name, so a session that cannot name itself cannot be usefully reached.I run 20 to 40 sessions in parallel, often several on the same repo in separate worktrees. Derived names come out as
api-2b,api-9f,api-a1, all indistinguishable to a human and to the agent picking a recipient./renameis the only fix and it is interactive only, so a skill or aSessionStarthook that knows exactly what the session is for still cannot set the name.One data point on the workaround, in case it helps scope the fix. The peer-visible name is read from
~/.claude/sessions/<pid>.json. Writing a newnameinto that file does change what other sessions see: a second session on the same machine called ListAgents and returned my patched name. The TUI kept displaying the old one, and the periodic write from the owning process preserved the patched value instead of restoring its own. So the file write does not rename a session, it silently splits the name in two, one for the display and one for every peer. Verified on 2.1.233, macOS.Any of the three options in the description would remove the need for that. Option 3 is the one that helps most here, since the session usually learns what it is working on several turns in.