MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / deriveTitle

Function deriveTitle

src/bridge/initReplBridge.ts:560–574  ·  view source on GitHub ↗

* Quick placeholder title: strip display tags, take the first sentence, * collapse whitespace, truncate to 50 chars. Returns undefined if the result * is empty (e.g. message was only ). Replaced by * generateSessionTitle once Haiku resolves (~1-15s).

(raw: string)

Source from the content-addressed store, hash-verified

558 * generateSessionTitle once Haiku resolves (~1-15s).
559 */
560function deriveTitle(raw: string): string | undefined {
561 // Strip <ide_opened_file>, <session-start-hook>, etc. — these appear in
562 // user messages when IDE/hooks inject context. stripDisplayTagsAllowEmpty
563 // returns '' (not the original) so pure-tag messages are skipped.
564 const clean = stripDisplayTagsAllowEmpty(raw)
565 // First sentence is usually the intent; rest is often context/detail.
566 // Capture group instead of lookbehind — keeps YARR JIT happy.
567 const firstSentence = /^(.*?[.!?])\s/.exec(clean)?.[1] ?? clean
568 // Collapse newlines/tabs — titles are single-line in the claude.ai list.
569 const flat = firstSentence.replace(/\s+/g, ' ').trim()
570 if (!flat) return undefined
571 return flat.length > TITLE_MAX_LEN
572 ? flat.slice(0, TITLE_MAX_LEN - 1) + '\u2026'
573 : flat
574}

Callers 2

initReplBridgeFunction · 0.85
onUserMessageFunction · 0.85

Calls 1

Tested by

no test coverage detected