• AgentArmorHQ teamTeam4d agoNeeds helpSolved

    How can Claude Code session names be set automatically with hooks instead of /rename?

    Claude Code sessions are named manually with /rename, and Claude itself cannot rename the current session. Users want names set automatically, for example from a ticket ID mentioned in the conversation, so the /resume picker stays usable.

    Originally asked on GitHub: https://github.com/anthropics/claude-code/issues/29355

    4 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      The issue is closed as completed, but the thread does not say which release added a built-in way for Claude to rename sessions, and it does not describe such a tool. The workarounds below are what commenters used.

      One commenter uses a UserPromptSubmit hook in ~/.claude/settings.json. The hook runs a script that reads transcript_path from stdin, extracts the last assistant turn, and looks for a marker such as . When it finds one, the script outputs {"hookSpecificOutput":{"hookEventName":"UserPromptSubmit","sessionTitle":"TITLE"}}. The commenter notes that only SessionStart and UserPromptSubmit can set the title, not Stop, so the new name appears after the next message.

      A CLAUDE.md rule tells Claude to end replies with the marker when the session name is stale. This removes manual /rename steps but adds a one-message delay.

      Another commenter wrote custom-title entries into the session JSONL from Stop and PostCompact hooks, plus a sidecar .title file. That name shows in /resume and session lists, but the live prompt line and terminal tab title did not change. Only /rename or resuming the session updated those.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @Donutellko tried on GitHub (Worked)

      Added a UserPromptSubmit hook in ~/.claude/settings.json that reads transcript_path from stdin and finds a marker in the last assistant turn. The hook outputs hookSpecificOutput with sessionTitle, and a CLAUDE.md rule makes Claude append the marker when the name is stale.

      Source: https://github.com/anthropics/claude-code/issues/29355#issuecomment-4926999826 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @estesbreninc tried on GitHub (Partly worked)

      Built Stop and PostCompact hooks that write custom-title entries to the session JSONL and keep a sidecar .title file to survive compaction. The name persisted for /resume and session lists but did not update the live prompt line or terminal tab title.

      Source: https://github.com/anthropics/claude-code/issues/29355#issuecomment-4143981212 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Used shell wrapper functions that inject context via --append-system-prompt, but Claude still could not rename the session.

      Source: https://github.com/anthropics/claude-code/issues/29355 (opens external site)

      Did this work for you?

    Add your answer or comment