Feature request: Allow Claude to programmatically rename sessions
Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Workaround ✓ Mentioned in thread ↓
Activity 16 comments · opened Feb 27, 2026 · closed Aug 17, 2026
💡 Likely answer: A maintainer (bcherny, collaborator)
responded on this thread — see the highlighted reply below.
Summary
Allow Claude to automatically rename the current session when a user mentions or shares a ticket ID (e.g., TICKET-123). Today, session naming is manual-only via /rename, and there's no tool or hook that can trigger a rename programmatically.
Use Case
When working on a Linear ticket, I often mention or paste the ticket ID in conversation. I'd like Claude to automatically set the session name to that ticket ID so I can easily find and resume it later.
Currently, I have to manually run /rename TICKET-123 every time, which breaks flow.
Proposed Solution
One of:
- A built-in tool (e.g.,
SessionRename) that Claude can call to rename the current session when contextually appropriate (e.g., when a ticket ID is mentioned). - A hook event that fires when a session name could be inferred, allowing custom logic to set it.
- A
--nameCLI flag for setting the session name at launch, combined with an in-session tool for dynamic renaming.
The ideal behavior: when I say "I'm working on TICKET-123" or paste a ticket URL, Claude detects the ticket ID and renames the session automatically — no manual /rename needed.
Current Workarounds
- Manual
/renameafter every session start - Shell wrapper functions that inject context via
--append-system-prompt, but still can't rename - Worktree naming provides some discoverability but isn't a session name
16 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Those interested in this should upvote https://github.com/anthropics/claude-code/issues/25045**
Since remote sessions landed, I've been accessing Claude Code from my phone regularly. The problem is session names are often meaningless when browsing from a small screen — I can't tell what each session is about without opening it.
My ideal workflow would be using a hook (e.g. on Stop or a periodic trigger) to automatically rename the session based on the current development context. Something like renaming to the active branch + task summary every ~10 minutes.
A
sessionNamefield in hook output (as proposed in #24872) or a dedicated CLI command likeclaude session renamewould both solve this. Either way, programmatic access to session renaming is the missing piece for making remote sessions truly usable.Additional use case: AI-initiated session naming at startup
I have a workflow where a
SessionStarthook injects a timestamp and CLAUDE.md instructions tell Claude to ask "What would you like to name this session?" at the start of every new conversation. The user provides a name, Claude constructs the full title (e.g.,2026-03-27_1229-auth-refactor) — and then hits a wall.Claude can't invoke
/rename. The only option is to output the command as text and ask the user to copy/paste it:This adds friction to every single session start.
Workaround attempted: I built a
Stop/PostCompacthook that writescustom-titleentries directly to the session JSONL file and maintains a sidecar.titlefile next to it (to survive the 64KB tail window compaction — same issue documented in #33165). This persists the name for/resumeand session lists, but does not update the live prompt line or terminal tab title, since those are controlled by Claude Code's internal UI state. Only/renameor a session resume triggers those UI updates.A
SessionRenametool callable by the AI would completely solve this — Claude already has the name, it just needs a way to apply it that updates the live UI.Another useful feature would be auto suggest renaming, potentially after session grows beyond certain length so we don't need it for trivial session.
+1 — and a prerequisite for this to be useful: a lock mechanism on session names.
Today, even manually renamed sessions get auto-overwritten by task-generated titles during the conversation. A programmatic rename API would suffer the same problem — the auto-rename would silently overwrite it.
Proposal: a
lockedflag (set automatically on any manual or programmatic rename) that prevents auto-rename from overwriting the name. This makes both the current/renameand any future programmatic rename actually stick.---
Disclaimer: this comment and the proposal it contains were drafted by Kloud AI assistant (kloud@gravya.it) under human review and approval. Human in the loop: GravyaDev.
+1 Would be really useful in combination with skills
+1 — adding a real-world ergonomic case that I haven't seen articulated in this thread:
I run 6-10 concurrent Claude Code sessions across a tabbed terminal (one per task / branch / worktree). My primary way to find old work is the
/resumepicker. When sessions don't have a clear name, the picker shows the first line of the conversation, which is usually noise like "ok let's look at this" or system context. Result: prior conversations become unfindable within a day.Manual
/renameis unreliable because I'm thinking about the work I'm doing, not the session metadata. By the time I remember to rename, I've already lost track of which tab was which. Sessions that took hours to build up get effectively orphaned because I can't find them in the picker the next morning.The interim workaround (
/renamewith no args — Haiku auto-generates a name from current context) helps when I remember to use it, but the whole point of the friction is that I forget. A programmatic path — even just a hook that fires after the first substantive exchange and auto-names via Haiku — would close the gap.Workflow pattern that would benefit: heavy multi-session users where
/resumeis the primary navigation surface.This would be fantastic. Looking to take advantage of tooling that would be nice to have standardized.
This would be really useful! When working with parallel sessions on a related problem it can get confusing to have to remember which one is working exactly on what issue at the moment, seeing it in the GUI would be very helpful.
The workaround that I'm currently using:
bump
Both pieces of this shipped:
claude --name TICKET-123(or-n) sets the session name at launch (v2.1.76).UserPromptSubmithook can returnhookSpecificOutput.sessionTitleto rename the session automatically — e.g. a small script that greps the prompt for a ticket ID and sets the title (v2.1.94).SessionStarthooks can do the same from the branch or folder name.Docs: https://code.claude.com/docs/en/hooks#userpromptsubmit-decision-control
Changelog: https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md
🤖 Generated with Claude Code
Sharing what I found digging into this today, in case it saves anyone else the afternoon.
A tool that does this already exists. It is undocumented and desktop-only.
Claude Code Desktop ships an internal MCP server,
ccd_session_mgmt, exposinglist_sessions,get_session,search_session_transcripts,list_events,archive_session,send_messageandset_session_title.mcp__ccd_session_mgmt__set_session_titlerenames the live session properly, UI included. It is injected into desktop-hosted sessions only, so CLI and VS Code sessions do not see it.Claude can call it, which means a
SessionStarthook injecting one line of context is enough for fully automatic naming:I derive
<name>in the hook from git (repo, branch, role, start time), so sessions name themselves with no typing at all. On a protected branch there is no task in the branch name, so the hook passes a template with a<slug>placeholder and lets Claude fill it from the conversation. That has held up across live sessions.How to check it actually ran
titleSourceon the session record tells you which path did the rename:auto= the background titleruser=/rename, or a manual rename in the UItool=set_session_titleThe record is at
~/Library/Application Support/Claude/claude-code-sessions/<account>/<org>/local_<uuid>.json, and itscliSessionIdmatches thesession_idyour hook receives on stdin. Worth checking, because "I asked Claude to rename the session and it did" is not by itself evidence the tool ran.Why the other approaches fail
@estesbreninc your JSONL result is correct, and here is the mechanism: the
custom-titlerecord in the transcript is an output of the desktop store, not an input. Appending to it changes nothing, including across an app restart. The store is the source of truth.Writing that store directly does drive the picker, but it loses a race. The app holds the record in memory and re-persists it every turn. I measured a hook write at 13:31:21 overwritten by the app at 13:32:21. Deferring the write until the session has been idle works, but it is fragile and it is not needed given the tool exists.
@GravyaDev on the lock you asked for:
titleSource: useris already respected, the auto titler does not overwrite it. What overwrites a manual rename is the persistence race above, not the titler./renameis defined withrequires: {ink: true}, so it is TUI-bound by design.claude -p --resume <id> "/rename x"reports success but renames a detached process, and the CLI name and the desktop picker turn out to be separate namespaces.Why this issue should stay open
This is undocumented internal API. It can change or vanish in any release, there is no supported way to reach it from a hook or the SDK, and it does nothing for CLI or VS Code sessions, which still have only
claude -nat startup. A documented tool, or asessionNamefield in hook output as proposed in #24872, is still the right fix. Treat the above as a workaround rather than a resolution.Hook, with install notes and the worktree/protected-branch/
/clearedge cases handled: https://gist.github.com/Shepherd-Creative/4b723ba2261292a58bcc931aff7c0b3eCredit where it is due: I worked this out together with Claude Code (Opus 5) over a long session of poking at binaries and testing on throwaway sessions, and it wrote this comment up for me.
Another use case for this: I'd like Claude Code session titles in the sidebar to auto-prefix with the issue number when the session is working on a repo issue (e.g. from the current git branch name or an issue number mentioned in the first prompt). For example, instead of a generic auto-generated title like "Fix login redirect bug," it would show "#123: Fix login redirect bug" — so I can identify sessions by issue at a glance.
This can be done perfectly in Claude Code with UserPromptSubmit hook. The script can just parse the current git branch name and return "sessionTitle" in the response body.
But it will only work on UserPromptSubmit.