How can a Claude Code skill rename the current session programmatically?
A user wants a custom skill to rename the current Claude Code session to match a saved file name so the session list stays organized. When the skill tries to invoke /rename through the Skill tool, it is rejected with the message that rename is a UI command, not a skill. Is there any way for a skill or hook to rename the session?
Originally asked on GitHub: https://github.com/anthropics/claude-code/issues/25045
2 answers
The feature is still open: there is no official tool that lets skills rename a session. The thread describes a community workaround that edits the session's state file.
The session name is stored in
~/.claude/sessions/<pid>.json, which has keys including pid, sessionId, cwd, startedAt, version, kind, entrypoint and name. The reporter says that replacing thenamevalue persists immediately and the next session-picker load shows the new name. Each session has its own pid file, and the sessionId is included in the UserPromptSubmit hook payload, so a hook can match the correct file.The reporter's helper, about 100 lines of bash and Python, works like this:
- A UserPromptSubmit hook reads session_id from the payload.
- It matches the sessionId against
~/.claude/sessions/*.json. - It rewrites the
namefield atomically using a tempfile andos.replace. - It validates names as 2 to 5 lowercase words.
- A bash allowlist entry avoids a permission prompt on each rename.
The reporter notes that the file schema is undocumented, so a Claude Code upgrade that renames
nameor moves the file could break this. Check the file contents after upgrading.Did this work for you?What @mjmirza tried on GitHub (Worked)
Tried invoking /rename through the Skill tool, which rejected it with 'rename is a UI command, not a skill'. Built a UserPromptSubmit hook that rewrites the name field in ~/.claude/sessions/.json, matched by sessionId, using an atomic tempfile and os.replace write plus a bash allowlist entry.
Source: https://github.com/anthropics/claude-code/issues/25045#issuecomment-4276491369 (opens external site)
Did this work for you?