Skip to content

armgit / Wake

Public Imported from GitHub
0

All your AI agent sessions in one place — browse, search, resume. Rust + GPUI.

Rust

fix(claude): title sessions with the name Claude Code gave them (#74)

Corey Chiu6bd9757c3c32
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8d03dc..ea029d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fix: Claude Code sessions take the title Claude Code gave them instead of their first message (#74, thanks @hoixding)
- Fix: Codex sessions that Codex has compressed show up again, with their titles and archived status (#72, thanks @suiyun08)
- Fix: Sessions recorded by older Codex versions show their messages and titles instead of appearing empty
- Fix: Clean Up no longer refuses Codex and Claude Code sessions written by recent versions
diff --git a/crates/wake-core/src/adapters/claude.rs b/crates/wake-core/src/adapters/claude.rs
index ea9b80a..e1ea92c 100644
--- a/crates/wake-core/src/adapters/claude.rs
+++ b/crates/wake-core/src/adapters/claude.rs
@@ -89,12 +89,13 @@ struct Branch {
original: PathBuf,
}
-/// 整份文件的 uuid 集合与最后一条自定义标题。只给分支之前的那几份读(绝大多数会话没有
-/// 分支,一份都不用读)
+/// 整份文件的 uuid 集合与最后一条自定义标题、AI 标题。只给分支之前的那几份读(绝大多数
+/// 会话没有分支,一份都不用读)
#[derive(Clone)]
struct Lineage {
uuids: Arc<HashSet<String>>,
custom_title: Option<String>,
+ ai_title: Option<String>,
}
/// 一个项目目录的分支分组,按目录 mtime 校验:文件进出、改名都会改它;文件追加不会,也
@@ -121,13 +122,12 @@ struct BranchCache {
lineages: HashMap<PathBuf, ((i64, i64), Lineage)>,
}
-/// 一份分支会话的继承段:比它早写下的同根文件里出现过的 uuid。文件开头连续落在这些集合
-/// 里的行是从原件复制来的
+/// 一份分支会话的继承段:比它早写下的同根文件(原件在其中)。文件开头连续落在它们 uuid 集合
+/// 里的行是复制来的;分支的自定义标题、AI 标题跟其中哪一份的一样(分支时照抄过来)也不当标题
+/// 用,往下退——否则父子两行标题一模一样,看不出分支在问什么。每一份都比、不只比原件:A 分出
+/// B、B 改了名再分出 C,C 抄来的是 B 的名字
struct Inherited {
earlier: Vec<Lineage>,
- /// 原件最后一条自定义标题:分支的自定义标题跟它一样(分支时照抄过来)就不当标题用,
- /// 改用分支自己的第一句话——否则父子两行标题一模一样,看不出分支在问什么
- parent_title: Option<String>,
}
impl Inherited {
@@ -224,8 +224,14 @@ fn custom_title_of(v: Option<&Value>) -> Option<String> {
optional_string(v).filter(|t| t != PLACEHOLDER_TITLE)
}
-/// 读整份文件的 uuid 集合与最后一条自定义标题。逐行只反序列化这三个字段;坏行跳过,
-/// 读错误整份失败(读不全就宁可不折)
+/// `ai-title` 行里命令行自己起的名字(2.1 起,#74)。解析与 read_lineage 都经这里取,分支的
+/// 标题与原件的才比得上
+fn ai_title_of(v: Option<&Value>) -> Option<String> {
+ optional_string(v)
+}
+
+/// 读整份文件的 uuid 集合与最后一条自定义标题、AI 标题。逐行只反序列化这几个字段;坏行
+/// 跳过,读错误整份失败(读不全就宁可不折)
fn read_lineage(path: &Path) -> Result<Lineage> {
#[derive(Deserialize)]
struct Row {
@@ -234,22 +240,28 @@ fn read_lineage(path: &Path) -> Result<Lineage> {
typ: Option<String>,
#[serde(rename = "customTitle")]
custom_title: Option<Value>,
+ #[serde(rename = "aiTitle")]
+ ai_title: Option<Value>,
}
let mut uuids = HashSet::new();
let mut title = None;
+ let mut ai_title = None;
for row in jsonl_rows::<Row, _>(BufReader::with_capacity(1 << 20, fs::File::open(path)?)) {
let Some(row) = row? else { continue };
if let Some(uuid) = row.uuid.filter(|u| !u.is_empty()) {
uuids.insert(uuid);
}
- // 与解析同一个取法(custom_title_of),分支标题与原件标题才比得上
- if row.typ.as_deref() == Some("custom-title") {
- title = custom_title_of(row.custom_title.as_ref()).or(title);
+ // 与解析同一个取法,分支标题与原件标题才比得上
+ match row.typ.as_deref() {
+ Some("custom-title") => title = custom_title_of(row.custom_title.as_ref()).or(title),
+ Some("ai-title") => ai_title = ai_title_of(row.ai_title.as_ref()).or(ai_title),
+ _ => {}
}
}
Ok(Lineage {
uuids: Arc::new(uuids),
custom_title: title,
+ ai_title,
})
}
@@ -412,7 +424,7 @@ impl ClaudeAdapter {
Ok(lineage)
}
- /// `file` 是分支的话,它的继承段与原件的标题;不是分支给 None。更早的文件读不出来就报错,
+ /// `file` 是分支的话,它的继承段;不是分支给 None。更早的文件读不出来就报错,
/// 不能当成"不是分支"照常入库:等它读得出来,分支的引用没变、扫描不会重来,索引停在没
/// 折叠的那份,现场解析却折叠了,两边的 seq 对不上(不变量 1)。解析失败时库里的旧行
/// 留着,下一轮再试
@@ -433,11 +445,7 @@ impl ClaudeAdapter {
})
})
.collect::<Result<Vec<_>>>()?;
- let parent_title = self.lineage(&branch.original)?.custom_title;
- Ok(Some(Inherited {
- earlier,
- parent_title,
- }))
+ Ok(Some(Inherited { earlier }))
}
/// 会话的解析(parse_session 与 parse_transcript 共用):分支先拿继承段;子代理的转录整份
@@ -455,7 +463,8 @@ impl ClaudeAdapter {
mark_subagent(&mut meta, path);
let desktop = self.desktop_owned();
meta.archived = archived_in(&desktop, r);
- // 转录里没起过名字(或只有桌面端的占位名):用桌面会话的名字,再退回首条提问
+ // 转录里没起过名字(或只有桌面端的占位名):用桌面会话的名字(用户在桌面端看到的
+ // 就是它),再退回 AI 标题、首条提问
if !parsed.titled {
if let Some(title) = desktop_title(&desktop, r) {
meta.title = title.to_string();
@@ -541,7 +550,7 @@ fn decode_project_dir(name: &str) -> Option<String> {
struct ParseResult {
messages: Vec<TranscriptMessage>,
title: String,
- /// 标题是转录里起的名字(`custom-title`),不是退回来的首条提问
+ /// 标题是转录里起的名字(`custom-title`),不是 AI 标题或退回来的首条提问
titled: bool,
cwd: String,
git_branch: Option<String>,
@@ -626,6 +635,8 @@ fn parse_claude_jsonl(
// tool_use id → (消息占位:回填时按 id 在已 flush 消息与 pending 中查)
let mut tool_index: HashMap<String, (usize, usize)> = HashMap::new();
let mut custom_title = String::new();
+ // 2.1 起命令行自己起的标题;只用命令行、没有桌面端写 custom-title 的会话全靠它(#74)
+ let mut ai_title = String::new();
let mut fallback_title = String::new();
let mut cwd = String::new();
let mut git_branch: Option<String> = None;
@@ -671,6 +682,12 @@ fn parse_claude_jsonl(
}
continue;
}
+ if typ == "ai-title" {
+ if let Some(t) = ai_title_of(row.get("aiTitle")) {
+ ai_title = t;
+ }
+ continue;
+ }
if typ != "user" && typ != "assistant" && typ != "system" {
if typ.is_empty() || !KNOWN_SKIP_TYPES.contains(&typ) {
unknown_lines += 1;
@@ -901,21 +918,30 @@ fn parse_claude_jsonl(
if own_created_at > 0 {
created_at = own_created_at;
}
- if inh.parent_title.as_deref() == Some(custom_title.as_str()) {
+ let earlier = &inh.earlier;
+ if earlier
+ .iter()
+ .any(|l| l.custom_title.as_deref() == Some(&custom_title))
+ {
custom_title.clear();
}
+ if earlier
+ .iter()
+ .any(|l| l.ai_title.as_deref() == Some(&ai_title))
+ {
+ ai_title.clear();
+ }
}
assign_seq(&mut messages);
+ let titled = !custom_title.is_empty();
+ let title = [custom_title, ai_title, fallback_title]
+ .into_iter()
+ .find(|t| !t.is_empty())
+ .unwrap_or_else(|| UNTITLED.to_string());
Ok(ParseResult {
- titled: !custom_title.is_empty(),
- title: if !custom_title.is_empty() {
- custom_title
- } else if !fallback_title.is_empty() {
- fallback_title
- } else {
- UNTITLED.to_string()
- },
+ titled,
+ title,
messages,
cwd,
git_branch,
diff --git a/crates/wake-core/src/db.rs b/crates/wake-core/src/db.rs
index d8e3c23..6f6f382 100644
--- a/crates/wake-core/src/db.rs
+++ b/crates/wake-core/src/db.rs
@@ -247,8 +247,12 @@ CREATE TABLE IF NOT EXISTS claimed_sessions (
/// 提问);桌面端已经没有记录的老会话引用不变,靠这轮重解析写对;
/// "18" = Codex 2025 年的老格式 rollout(首行没有信封、条目不带 payload)读得出消息、标题与工作
/// 目录;标题不再是 IDE 扩展的编辑器上下文包装(`# Context from my IDE setup`),取其后的
-/// 提问。文件早就不再变,原先入库的是空会话,靠这轮重解析写对。
-pub const FTS_FORMAT: &str = "18";
+/// 提问。文件早就不再变,原先入库的是空会话,靠这轮重解析写对;
+/// "19" = Claude Code 命令行自己起的标题(`ai-title`,#74)在没有 custom-title 时当标题(原先退回
+/// 首条提问);分支照抄来的标题与每一份更早的同根文件比,不只比原件——分支的分支抄的是
+/// 中间那份的名字;2.1 起的记账记录(agent-name、cost-state 等)不再计未知行。"18" 推上
+/// main 时还没有这几条,跑过那时构建的库已经戳着它,所以另起一档
+pub const FTS_FORMAT: &str = "19";
/// FTS 压缩的节奏(见 `Store::compact_fts`):距上次压缩满一天、或从没压过才压。没有记录
/// 就算到期——老库升级后、新建库首轮扫描收尾各压一次;`FTS_FORMAT` 换代时 open_conn 把
diff --git a/crates/wake-core/tests/adapter_contracts.rs b/crates/wake-core/tests/adapter_contracts.rs
index 2746f05..fa404ae 100644
--- a/crates/wake-core/tests/adapter_contracts.rs
+++ b/crates/wake-core/tests/adapter_contracts.rs
@@ -981,6 +981,113 @@ fn claude_branches_fold_the_copied_history_and_nest_under_the_original() {
assert_eq!(adapter.parent_links(), Some(Vec::new()));
}
+/// Claude Code 2.1 起命令行自己给会话起名(`ai-title`,#74):没有 custom-title 时它就是标题,
+/// 不算未知行;分支照抄原件的 AI 标题与 custom-title 一样不用;用户改过的名字照旧压过它
+#[test]
+fn claude_ai_titles_name_sessions() {
+ let tmp = tempfile::tempdir().unwrap();
+ let projects = tmp.path().join("projects");
+ let (dir, a, b) = common::stage_claude_branch(&projects);
+ // 两份文件里的自定义标题都换成 AI 标题:命令行起的名字,分支照抄了原件那一条
+ let path = |id: &str| dir.join(format!("{id}.jsonl"));
+ for id in [&a, &b] {
+ let text = fs::read_to_string(path(id))
+ .unwrap()
+ .replace(r#""type":"custom-title""#, r#""type":"ai-title""#)
+ .replace(r#""customTitle":"#, r#""aiTitle":"#);
+ fs::write(path(id), text).unwrap();
+ }
+ let adapter = ClaudeAdapter::new().with_custom_root(projects);
+ let parse = |id: &str| {
+ adapter
+ .parse_session(&adapter.file_ref(&path(id)).unwrap())
+ .unwrap()
+ };
+
+ let sa = parse(&a);
+ assert_eq!(sa.meta.title, "修复登录超时");
+ assert_eq!(sa.unknown_line_count, 0);
+ assert_eq!(
+ parse(&b).meta.title,
+ "换个思路:登录改成异步队列",
+ "照抄的 AI 标题不用"
+ );
+
+ let renamed =
+ serde_json::json!({"type": "custom-title", "customTitle": "登录超时排查", "sessionId": a});
+ let text = fs::read_to_string(path(&a)).unwrap() + &format!("{renamed}\n");
+ fs::write(path(&a), text).unwrap();
+ assert_eq!(
+ parse(&a).meta.title,
+ "登录超时排查",
+ "改过的名字压过 AI 标题"
+ );
+}
+
+/// 分支的分支:A 分出 B、B 改了名再分出 C,C 开头照抄的是 B 的名字——只和原件 A 比去不掉,
+/// C 就和 B 同名。要与每一份更早的同根文件比。自定义标题与 AI 标题同一条规则,各搭一遍
+/// (Codex review 2026-10-21)
+#[test]
+fn claude_branch_of_a_branch_drops_the_title_it_copied() {
+ for (kind, field) in [("custom-title", "customTitle"), ("ai-title", "aiTitle")] {
+ let tmp = tempfile::tempdir().unwrap();
+ let projects = tmp.path().join("projects");
+ let (dir, a, b) = common::stage_claude_branch(&projects);
+ let path = |id: &str| dir.join(format!("{id}.jsonl"));
+ let renamed = |session: &str| serde_json::json!({ "type": kind, field: "登录改成异步队列", "sessionId": session });
+ if kind == "ai-title" {
+ for id in [&a, &b] {
+ let text = fs::read_to_string(path(id))
+ .unwrap()
+ .replace(r#""type":"custom-title""#, r#""type":"ai-title""#)
+ .replace(r#""customTitle":"#, r#""aiTitle":"#);
+ fs::write(path(id), text).unwrap();
+ }
+ }
+ let text = fs::read_to_string(path(&b)).unwrap() + &format!("{}\n", renamed(&b));
+ fs::write(path(&b), text).unwrap();
+
+ // C 从 B 分出:开头照抄 B 的名字与 B 的消息行,之后问了自己的一句;照抄来的名字在分叉点
+ // 之后还会再写(本机的分支文件里就是这样)
+ let c = "c1a0de00-0000-4000-8000-0000000000c3";
+ let mut rows = vec![
+ renamed(c),
+ serde_json::json!({ "type": "queue-operation", "operation": "enqueue", "timestamp": "2026-09-03T10:00:00.000Z", "sessionId": c }),
+ ];
+ for line in fs::read_to_string(path(&b)).unwrap().lines() {
+ let mut row: serde_json::Value = serde_json::from_str(line).unwrap();
+ if row.get("uuid").is_some() {
+ row["sessionId"] = c.into();
+ rows.push(row);
+ }
+ }
+ rows.push(serde_json::json!({
+ "parentUuid": "c1a0de00-2222-4000-8000-000000000004",
+ "isSidechain": false,
+ "cwd": "/Users/tester/Github/branchfx",
+ "sessionId": c,
+ "type": "user",
+ "message": { "role": "user", "content": "队列满了怎么办" },
+ "uuid": "c1a0de00-3333-4000-8000-000000000005",
+ "timestamp": "2026-09-03T10:00:10.000Z",
+ }));
+ rows.push(renamed(c));
+ let text: String = rows.iter().map(|r| format!("{r}\n")).collect();
+ fs::write(path(c), text).unwrap();
+
+ let adapter = ClaudeAdapter::new().with_custom_root(projects);
+ let title = |id: &str| {
+ adapter
+ .parse_session(&adapter.file_ref(&path(id)).unwrap())
+ .unwrap()
+ .meta
+ .title
+ };
+ assert_eq!(title(&b), "登录改成异步队列", "{kind}: B 自己改的名字照用");
+ assert_eq!(title(c), "队列满了怎么办", "{kind}: C 照抄 B 的名字不用");
+ }
+}
+
#[test]
fn codex_parse_contract() {
setup();