Feature: Programmatic session/thread renaming via hooks or tools

Status Open
Maintainer reply None cached
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:

  1. Start work on an issue → session name becomes #42 - Fix auth bug
  2. 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)
  • /rename changes 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)

  1. New hook event — e.g., RenameSession that allows hooks or tools to set the session name
  2. Scriptable /rename — allow /rename to be called from within tool execution or hook scripts
  3. New built-in tool — a SetSessionName tool that Claude can call during a conversation (e.g., after creating a PR via gh 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

View original on GitHub ↗

7 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/33181
  2. https://github.com/anthropics/claude-code/issues/34243
  3. https://github.com/anthropics/claude-code/issues/29355

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

yurukusa · 5 months ago

A PostToolUse hook can maintain a logical session name based on activity:

INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty')
SESSION_FILE="/tmp/cc-session-context.json"
[ -f "$SESSION_FILE" ] || echo '{"files":[],"issue":null}' > "$SESSION_FILE"
case "$TOOL" in
    Edit|Write)
        FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
        [ -n "$FILE" ] && jq --arg f "$(basename "$FILE")" '.files = (.files + [$f] | unique | .[-3:])' "$SESSION_FILE" > "${SESSION_FILE}.tmp" && mv "${SESSION_FILE}.tmp" "$SESSION_FILE"
        ;;
    Bash)
        CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
        if echo "$CMD" | grep -qE 'gh (issue|pr) (view|create)'; then
            NUM=$(echo "$CMD" | grep -oE '#?[0-9]+' | head -1)
            [ -n "$NUM" ] && jq --arg n "$NUM" '.issue = $n' "$SESSION_FILE" > "${SESSION_FILE}.tmp" && mv "${SESSION_FILE}.tmp" "$SESSION_FILE"
        fi
        ;;
esac
ISSUE=$(jq -r '.issue // empty' "$SESSION_FILE")
FILES=$(jq -r '.files | join(", ")' "$SESSION_FILE")
BRANCH=$(git branch --show-current 2>/dev/null)
TITLE=""
[ -n "$ISSUE" ] && TITLE+="#$ISSUE "
[ -n "$BRANCH" ] && TITLE+="[$BRANCH] "
[ -n "$FILES" ] && TITLE+="$FILES"
[ -n "$TITLE" ] && printf '\033]2;CC: %s\033\\' "$TITLE" >&2
exit 0

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.

ElliotDrel · 5 months ago

This is essentially the same request as #33165 — a programmatic API for renaming sessions.

I built a workaround skill called /better-title that 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-title

It works, but it's a hack — a proper rename API or hook event would make this much cleaner.

ElliotDrel · 4 months ago

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.

ElliotDrel · 3 months ago

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.

ElliotDrel · 3 months ago

The PostToolUse hook 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-title skill has the same limitation: it works until Claude Code's session indexer rewrites the file.

A first-party SetSessionName tool 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.

micktaiwan · 14 days ago

Cross-session messaging (2.1.224+) turned the session name into an address rather than a label, which makes this worth more than cosmetics. SendMessage addresses 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. /rename is the only fix and it is interactive only, so a skill or a SessionStart hook 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 new name into 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.