Add SessionRename (PreSessionRename / PostSessionRename) hook event

Open 💬 2 comments Opened Jun 9, 2026 by jameswniu

Summary

We have a user-level rule that session titles must be 8 chars or fewer, lowercase, single token, no dashes/underscores. The /rename command bypasses every existing hook event. This was empirically verified by registering a probe on UserPromptSubmit and observing that /rename foo and /rename (no arg) both completed without firing the probe; the next user prompt was the first event that fired.

Current state (Claude Code, macOS, latest)

  • /rename <arg> and /rename (no arg, auto-generated title) both run inside the local CLI engine and complete before any hook fires.
  • The full 31-event hook inventory has no session-rename-related event.
  • UserPromptSubmit stdin DOES include the current session_title, which permits reactive nagging but not prevention or transformation.

Ask

Add a hook event fired at session rename time, with the same protocol as PreToolUse: receive the proposed new title on stdin (JSON), allow the hook to either approve, mutate (return a replacement title), or block (return a rejection reason that gets surfaced to the user). Suggested event names: PreSessionRename (mutate/block) and/or PostSessionRename (observe).

Why

Users who care about session naming conventions (organizational, archival, scripting) have no way to enforce them today. The auto-rename path produces multi-word dashed titles by default; some users want them collapsed to short tokens. A pre-event hook would let ~/.claude/hooks/ enforce arbitrary policy.

Minimal repro

  1. Set ~/.claude/CLAUDE.md to require a strict session-naming rule (max 8 chars, lowercase, no dashes).
  2. Run /rename with no argument in a session.
  3. Observe that the auto-generated title violates the rule with no recourse other than typing /rename <compliant> manually.
  4. Register a probe hook on UserPromptSubmit and confirm /rename does NOT fire it; the next user prompt is the first event that does.

Workaround attempted

Reactive UserPromptSubmit hook reading session_title from stdin. Works to nag the user on the next prompt, cannot prevent the bad title from landing. Rejected as user-hostile: a warning fires every turn until the user manually renames.

Suggested API shape

// stdin to PreSessionRename hook
{
  "session_id": "...",
  "hook_event_name": "PreSessionRename",
  "current_title": "session-naming-rules",
  "proposed_title": "session-naming-rules",
  "source": "auto" | "user"
}

// stdout (optional)
{ "approve": true }
// or
{ "replace_with": "snmrul" }
// or
{ "block": true, "reason": "violates user naming rule" }

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗