claude-code - ✅(Solved) Fix Feature: Native auto-session-title generation on first user message [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47176Fetched 2026-04-13 05:39:25
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2cross-referenced ×1referenced ×1

Claude Code should natively generate a meaningful session title from the first user message, similar to how ChatGPT, Claude.ai, and other AI chat interfaces automatically name conversations.

Root Cause

Claude Code should natively generate a meaningful session title from the first user message, similar to how ChatGPT, Claude.ai, and other AI chat interfaces automatically name conversations.

Fix Action

Fix / Workaround

Workaround (for now)

PR fix notes

PR #47178: feat(examples): add session auto-title UserPromptSubmit hook

Description (problem / solution / changelog)

Summary

Adds examples/hooks/session_auto_title_example.py — a UserPromptSubmit hook that automatically injects a title-setting instruction into the model context on the first message of each new Claude Code session.

Related issue: #47176

Problem

Session titling currently relies entirely on system-prompt injection (e.g. from the Happy app), which is fragile:

  • MCP tools like mcp__happy__change_title are deferred in Claude Code — their schemas are not pre-loaded
  • Setting a title requires a two-step ToolSearch → tool-call sequence
  • The LLM executes this inconsistently, leading to sessions with missing or stale titles that don't appear in /resume

Solution

Inject the title instruction via additionalContext on the first user-message turn — the same technique already used by Happy for Codex and Gemini:

output = {
    "hookSpecificOutput": {
        "hookEventName": "UserPromptSubmit",
        "additionalContext": _TITLE_INSTRUCTION,
    }
}

A per-session flag file in the OS temp directory (/tmp/cc-autotitle-<session_id>.done) ensures the instruction is injected exactly once, with zero overhead on subsequent messages.

How it works

Session start (first message)
  → hook writes flag file
  → hook outputs additionalContext
  → model sets title (via mcp__happy__change_title or /rename)

All subsequent messages
  → flag file exists → hook exits 0 silently

Usage

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "python3 /path/to/examples/hooks/session_auto_title_example.py"
          }
        ]
      }
    ]
  }
}

Testing

# First call → outputs JSON with additionalContext
CLAUDE_SESSION_ID="test-123" python3 examples/hooks/session_auto_title_example.py
# → {"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}

# Second call → silent (flag exists)
CLAUDE_SESSION_ID="test-123" python3 examples/hooks/session_auto_title_example.py
# → (no output, exit 0)

Checklist

  • Follows the same style as bash_command_validator_example.py
  • Pure stdlib — no dependencies
  • Cross-platform (Linux / macOS / Windows via tempfile.gettempdir())
  • Race-safe flag file creation (open(..., 'x'))
  • Degrades gracefully when CLAUDE_SESSION_ID is absent

Changed files

  • examples/hooks/README.md (added, +57/-0)
  • examples/hooks/session_auto_title_example.js (added, +116/-0)
  • examples/hooks/session_auto_title_example.py (added, +105/-0)

Code Example

// runCodex-CQJbJWfw.mjs:1964
  const turnPrompt = first
    ? message.message + "\n\n" + CHANGE_TITLE_INSTRUCTION
    : message.message;

---

{
  "hooks": {
    "UserPromptSubmit": [{
      "hooks": [{
        "type": "command",
        "command": "node ~/.claude/scripts/hooks/user-prompt-auto-title.js",
        "timeout": 5
      }]
    }]
  }
}
RAW_BUFFERClick to expand / collapse

Feature Request

Summary

Claude Code should natively generate a meaningful session title from the first user message, similar to how ChatGPT, Claude.ai, and other AI chat interfaces automatically name conversations.

Problem / Motivation

Currently, session titling in Claude Code relies entirely on:

  1. External MCP tools (e.g. mcp__happy__change_title from the Happy app) injecting a system-prompt instruction, OR
  2. Manual /rename by the user

The system-prompt approach has a fragility problem: mcp__happy__change_title is listed as a deferred tool in Claude Code (schema not pre-loaded). The model must first call ToolSearch to load the schema, then call the tool — a two-step process the LLM executes inconsistently. The result is sessions with untitled or stale titles, making /resume and session navigation difficult.

Proposed Solution

Add native session auto-titling built into Claude Code itself:

  1. Trigger: After the first user message in a new session (not --resume / --continue)
  2. Mechanism: Asynchronously (fire-and-forget, non-blocking) call an internal lightweight model to generate a ≤60-char title from the first user message
  3. Storage: Write the title to the session JSONL as a custom-title entry (the format already used by /rename)
  4. Settings opt-out: Respect a new autoTitle: false setting in settings.json for users who prefer manual control

Prior Art / Evidence

  • Happy app (largest Claude Code mobile client) already does this for Codex and Gemini by appending CHANGE_TITLE_INSTRUCTION to the first user message:

    // runCodex-CQJbJWfw.mjs:1964
    const turnPrompt = first
      ? message.message + "\n\n" + CHANGE_TITLE_INSTRUCTION
      : message.message;

    For Claude Code it relies only on system-prompt injection, which is less reliable due to deferred tool loading.

  • The terminalTitleFromRename setting already exists in Claude Code's schema, showing the infrastructure for session titling is partially in place.

  • The custom-title JSONL entry format is already used and read by /resume, so no new storage schema is needed.

Workaround (for now)

A UserPromptSubmit hook injects the instruction on the first message of each session:

{
  "hooks": {
    "UserPromptSubmit": [{
      "hooks": [{
        "type": "command",
        "command": "node ~/.claude/scripts/hooks/user-prompt-auto-title.js",
        "timeout": 5
      }]
    }]
  }
}

The script outputs { "hookSpecificOutput": { "hookEventName": "UserPromptSubmit", "additionalContext": "..." } } only on the first message of each session (tracked via a CLAUDE_SESSION_ID-keyed flag file in /tmp).

This works but requires per-user setup and still relies on the model following instructions — a native solution would be deterministic.

Acceptance Criteria

  • New sessions (not resumed) automatically get a title generated from the first user message
  • Title generation is async and does not block the first response
  • Title appears in /resume list
  • autoTitle: false in settings.json disables the feature
  • Works without any external MCP server or plugin

Claude Code Version

2.1.104

Platform

Linux (Ubuntu 24.04)

extent analysis

TL;DR

Implementing native session auto-titling in Claude Code by asynchronously generating a title from the first user message and storing it in the session JSONL would improve the user experience.

Guidance

  • To achieve native session auto-titling, modify the Claude Code to trigger an internal lightweight model after the first user message in a new session, generating a title and storing it in the session JSONL as a custom-title entry.
  • Respect a new autoTitle: false setting in settings.json to allow users to opt-out of this feature.
  • Ensure the title generation is asynchronous and non-blocking to prevent delaying the first response.
  • Verify the implementation by checking if new sessions automatically receive a generated title, if the title appears in the /resume list, and if the autoTitle: false setting correctly disables the feature.

Example

No specific code example is provided as the implementation details depend on the internal architecture of Claude Code. However, the UserPromptSubmit hook workaround provided in the issue body demonstrates a possible approach to injecting the title generation instruction.

Notes

The proposed solution builds upon existing infrastructure, such as the custom-title JSONL entry format and the terminalTitleFromRename setting, to minimize the introduction of new complexity. The asynchronous nature of the title generation ensures that it does not interfere with the responsiveness of the system.

Recommendation

Apply the proposed native session auto-titling solution, as it provides a deterministic and reliable way to generate session titles without relying on external tools or user intervention, improving the overall user experience.

FAIL-SAFE

Given the information provided, the recommended approach focuses on implementing a native solution within Claude Code, avoiding dependencies on external tools or complex workarounds. If the implementation details are unclear, focusing on the asynchronous generation and storage of the title, along with the opt-out mechanism, provides a solid foundation for the feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - ✅(Solved) Fix Feature: Native auto-session-title generation on first user message [1 pull requests, 2 comments, 2 participants]