@devries-cameron20 / t3code Mirror · read-only / commits / 4908d8ce46
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(server): keep Claude renames when importing sessions (#12292)

Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Guillermo Casanova committed Oct 20, 2026 at 01:12 UTC 4908d8ce4615ad1a65989344280d6b9abf481d8f
2 files changed +42 -1
apps/server/src/project/AgentSessionScanner.test.ts
+34
@@ -2808,6 +2808,40 @@ describe("parseAgentSessionTranscript", () => {
2808 });
2809 });
2810
2811 + it.each([
2812 + { customTitles: ["Refactor auth module"], expected: "Refactor auth module" },
2813 + // Claude writes an empty customTitle when the user clears a rename.
2814 + { customTitles: ["Refactor auth module", ""], expected: "Generated title" },
2815 + ])("uses Claude custom titles $customTitles over the AI title", ({ customTitles, expected }) => {
2816 + const aiTitle = JSON.stringify({
2817 + type: "ai-title",
2818 + aiTitle: "Generated title",
2819 + sessionId: "claude-session",
2820 + });
2821 + const thread = AgentSessionScanner.parseAgentSessionTranscript({
2822 + contents: [
2823 + JSON.stringify({
2824 + type: "user",
2825 + sessionId: "claude-session",
2826 + timestamp: "2026-08-24T10:00:00.000Z",
2827 + message: { role: "user", content: "<command-name>/effort</command-name>" },
2828 + }),
2829 + // Claude rewrites both records on every metadata flush with ai-title
2830 + // last, so a later ai-title must not override the user's rename.
2831 + ...customTitles.flatMap((customTitle) => [
2832 + JSON.stringify({ type: "custom-title", customTitle, sessionId: "claude-session" }),
2833 + aiTitle,
2834 + ]),
2835 + ].join("\n"),
2836 + source: "claudeAgent",
2837 + providerInstanceId: ProviderInstanceId.make("claudeAgent"),
2838 + fallbackSessionId: "fallback",
2839 + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"),
2840 + });
2841 +
2842 + expect(thread?.title).toBe(expected);
2843 + });
2844 +
2845 it("drops injected Codex instructions while keeping the visible user event", () => {
2846 const thread = AgentSessionScanner.parseAgentSessionTranscript({
2847 contents: [
apps/server/src/project/AgentSessionScanner.ts
+8 -1
@@ -88,6 +88,7 @@ const TranscriptRecord = Schema.Struct({
88 cwd: Schema.optional(Schema.String),
89 sessionId: Schema.optional(Schema.String),
90 aiTitle: Schema.optional(Schema.String),
91 + customTitle: Schema.optional(Schema.String),
92 isSidechain: Schema.optional(Schema.Boolean),
93 isMeta: Schema.optional(Schema.Boolean),
94 isCompactSummary: Schema.optional(Schema.Boolean),
@@ -277,6 +278,7 @@ function parseAgentSessionRecords(
278 // timestamp text, so only transcript metadata can provide a resumable ID.
279 let providerSessionId = input.source === "codex" ? "" : input.fallbackSessionId;
280 let title: string | null = null;
281 + let customTitle: string | null = null;
282 let derivedTitle: string | undefined;
283 let model: string | null = null;
284 let hasCodexSessionId = false;
@@ -379,6 +381,10 @@ function parseAgentSessionRecords(
381 }
382 if (record.sessionId?.trim()) providerSessionId = record.sessionId.trim();
383 if (record.aiTitle?.trim()) title = record.aiTitle.trim();
384 + // Claude rewrites both title records on every flush, so the user's
385 + // rename is tracked separately instead of racing the later ai-title.
386 + // An empty customTitle is how Claude clears a rename.
387 + if (record.customTitle !== undefined) customTitle = record.customTitle.trim() || null;
388 const messageModel = record.message?.model?.trim();
389 // Claude uses this sentinel for local error responses. It is not a
390 // model ID that can be selected when the imported session resumes.
@@ -471,7 +477,7 @@ function parseAgentSessionRecords(
477 source: input.source,
478 providerInstanceId: input.providerInstanceId,
479 providerSessionId,
474 - title: title ?? derivedTitle ?? "Imported thread",
480 + title: customTitle ?? title ?? derivedTitle ?? "Imported thread",
481 model,
482 createdAt: retainedMessages[0]?.createdAt ?? fallbackTimestamp,
483 updatedAt: fallbackTimestamp,
@@ -495,6 +501,7 @@ function shouldRetainDecodedRecord(
501 record.type === "assistant" ||
502 record.sessionId !== undefined ||
503 record.aiTitle !== undefined ||
504 + record.customTitle !== undefined ||
505 record.message?.model !== undefined
506 );
507 }