显示 Claude Code 自己的会话标题,而不是第一条 prompt - #293
Merged
Merged
Conversation
Claude Code 2.x 已经不再往 transcript 里写 `summary` 记录,它把自己 UI 上显示的 标题存成 `custom-title` 记录,并且每轮对话都会重写一次。`ConversationParser` 只 认 `summary`,所以对当前版本的 transcript 而言 `ConversationInfo.summary` 恒为 nil,`SessionState.displayTitle` 一路掉到被截断成 50 字符的第一条用户消息 —— 会 话不管聊到哪里,标题始终是用户最开始输入的那句话。 在已有的倒序扫描里读取 `custom-title`,倒序第一个命中的就是最新标题,并优先于旧 的 `summary`。空白标题会被忽略。提前退出的条件改成接受任一来源,因此两种记录都没 有的 transcript 仍然扫到文件末尾并回退到第一条用户消息,与改动前完全一致。 标题喂给已有的 `ConversationInfo.summary` 字段而不是新增字段,所以 `displayTitle`、 副标题 badge、Codex 辅助会话判断等现有消费方都不需要改动即可生效。 Tested: Prototype 129 tests;Xcode PingIslandTests,其中包含五个新增的 ConversationParser 用例,覆盖 custom-title 优先、取最新标题、旧 summary 路径、 无标题回退、空白标题被拒。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
michaelawea
force-pushed
the
fix/claude-code-custom-title
branch
from
August 30, 2026 19:52
3dc1091 to
9912cd4
Compare
Contributor
Author
|
CI 的失败与本 PR 无关:报错是 |
Owner
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Island 里的 Claude Code 会话,标题显示的是用户的第一条 prompt,而不是 Claude Code 自己为这个会话显示的标题。而且它永远不变 —— 一个以「标题为什么不对?」开头的会话,之后无论聊到哪里,行上挂的还是这句话。
SessionState.displayTitle的优先级是sessionName → conversationInfo.summary → firstUserMessage → projectName,而ConversationParser里summary只有一个来源:transcript 中{"type":"summary"}的记录。Claude Code 2.x 已经不再写这种记录了。它把自己 UI 上显示的标题存成另一种记录,并且每轮对话都会重写一次:
{"type":"custom-title","customTitle":"双窗口重复显示bug","sessionId":"faa1378d-…"}在本地
~/.claude/projects上做了统计(418 份 transcript,Claude Code 2.1.247):含summary记录的 0 份,含custom-title的 88 份;最近两周内有改动的 118 份里 87 份带custom-title。也就是说summary在实际使用中恒为 nil,当前所有 Claude Code 会话都会掉到firstUserMessage,还被截断到 50 字符。改动
在
parseContent已有的倒序扫描里读取custom-title,倒序第一个命中的就是最新标题,并优先于旧的summary。标题喂给已有的
ConversationInfo.summary字段,而不是新增一个字段,所以所有现有消费方 ——displayTitle、副标题 badge、Codex 辅助会话判断 —— 不需要任何改动即可生效。兼容性:
summary的 Claude 兼容客户端不受影响,该路径原样保留并作为 fallback。parse()按文件 mtime 缓存,Claude Code 改写标题时会更新 mtime,标题能自动刷新,不需要额外的失效逻辑。测试
新增
PingIslandTests/ConversationParserTests.swift(此前这个 parser 没有直接的测试覆盖):custom-title 优先于第一条用户消息、存在多条时取最新的、旧的summary路径仍可解析、两者都没有时回退、空白标题被忽略。CI 的两项检查在本分支上于本地均已通过:
swift test --package-path Prototype(129 tests)与-only-testing:PingIslandTests。🤖 Generated with Claude Code