From f58e1b84f56ac071e7f189de075c586abb7bd08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20=C5=BDab=C4=8D=C3=ADk?= <35886301+dominikzabcik@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:43:47 +0100 Subject: [PATCH 1/3] fix(server): imported Claude threads show prompts, not Claude Code markup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude Code records its own UI as user turns. Imported threads showed raw `……` markup for slash commands, `` and `` for `!` shell runs, `` output, `` blocks and interruption markers. Threads opened with a skill were titled after that markup, and a launcher can save it as the session's custom title too. Slash commands and shell runs now import as typed (`/review the login flow`, `!npm test`). Their output, task notifications and interruption markers are left out. A command names the thread by its arguments, a markup custom or AI title falls back to the next title source, and a session of bare commands such as `/clear` that no reply followed is skipped. A bare command the agent answered, such as `/review`, is kept and names the thread. Claude Opus 5.5 in Claude Code. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 91 +++++++++++++++++-- .../server/src/project/AgentSessionScanner.ts | 81 ++++++++++++++--- docs/user/welcome-page.md | 5 +- 3 files changed, 157 insertions(+), 20 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index f9c7aaf3fd3d4..7f6648dfdbd17 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -2347,6 +2347,20 @@ describe("parseAgentSessionTranscript", () => { sessionId: "claude-session", message: { role: "user", content: [{ type: "tool_result", text: "hidden" }] }, }), + ...[ + "/review\nreview\nthe login flow", + "Enabled plan mode", + "npm test", + "1 passed", + "\na1\ncompleted\n", + "[Request interrupted by user for tool use]", + ].map((content) => + JSON.stringify({ + type: "user", + sessionId: "claude-session", + message: { role: "user", content }, + }), + ), JSON.stringify({ type: "assistant", sessionId: "claude-session", @@ -2378,6 +2392,8 @@ describe("parseAgentSessionTranscript", () => { model: "claude-sonnet-5", messages: [ { role: "user", text: "Fix authentication" }, + { role: "user", text: "/review the login flow" }, + { role: "user", text: "!npm test" }, { role: "assistant", text: "Updated the login flow" }, { role: "assistant", text: "The provider request failed" }, ], @@ -2388,6 +2404,20 @@ describe("parseAgentSessionTranscript", () => { { customTitles: ["Refactor auth module"], expected: "Refactor auth module" }, // Claude writes an empty customTitle when the user clears a rename. { customTitles: ["Refactor auth module", ""], expected: "Generated title" }, + // Some launchers rename the session to the raw markup of its opening command. + { + customTitles: ["pstack:poteto-mode"], + expected: "Generated title", + }, + { + customTitles: ["Enabled plan mode"], + expected: "Generated title", + }, + { customTitles: ["npm test"], expected: "Generated title" }, + { + customTitles: ["/reviewlogin flow"], + expected: "Generated title", + }, ])("uses Claude custom titles $customTitles over the AI title", ({ customTitles, expected }) => { const aiTitle = JSON.stringify({ type: "ai-title", @@ -2400,7 +2430,7 @@ describe("parseAgentSessionTranscript", () => { type: "user", sessionId: "claude-session", timestamp: "2026-08-24T10:00:00.000Z", - message: { role: "user", content: "/effort" }, + message: { role: "user", content: "Tighten the session checks" }, }), // Claude rewrites both records on every metadata flush with ai-title // last, so a later ai-title must not override the user's rename. @@ -2418,6 +2448,33 @@ describe("parseAgentSessionTranscript", () => { expect(thread?.title).toBe(expected); }); + it.each([ + { + first: + "/pstack:arenaCompare designs", + title: "Compare designs", + }, + { + first: "/clearclear", + title: "Plan the release", + }, + { first: "/Users/me/app fails to build", title: "/Users/me/app fails to build" }, + ])("titles a Claude thread after its request, not command markup: $title", ({ first, title }) => { + const thread = AgentSessionScanner.parseAgentSessionTranscript({ + contents: [first, "Plan the release"] + .map((content) => + JSON.stringify({ type: "user", sessionId: "claude-session", message: { content } }), + ) + .join("\n"), + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "fallback", + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), + }); + + expect(thread?.title).toBe(title); + }); + it("drops injected Codex instructions while keeping the visible user event", () => { const thread = AgentSessionScanner.parseAgentSessionTranscript({ contents: [ @@ -2861,18 +2918,38 @@ describe("parseAgentSessionTranscript", () => { expect(thread?.messages.map((message) => message.text)).toEqual([prompt]); }); - it("skips sessions without a visible user message", () => { + it.each([ + { + name: "only an assistant reply", + records: [{ type: "assistant", message: { content: "Done" } }], + expected: null, + }, + { + name: "only a bare command", + records: [{ type: "user", message: { content: "/clear" } }], + expected: null, + }, + { + name: "a bare command the agent answered", + records: [ + { type: "user", message: { content: "/review" } }, + { type: "assistant", message: { content: "Found two issues" } }, + ], + expected: { title: "/review", texts: ["/review", "Found two issues"] }, + }, + ])("imports a Claude session only if it got a request: $name", ({ records, expected }) => { const thread = AgentSessionScanner.parseAgentSessionTranscript({ - contents: JSON.stringify({ - type: "assistant", - message: { role: "assistant", content: "Done" }, - }), + contents: records.map((record) => JSON.stringify(record)).join("\n"), source: "claudeAgent", providerInstanceId: ProviderInstanceId.make("claudeAgent"), fallbackSessionId: "claude-session", lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), }); - expect(thread).toBeNull(); + expect( + thread === null + ? null + : { title: thread.title, texts: thread.messages.map((message) => message.text) }, + ).toEqual(expected); }); }); diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index dc67bd9387e04..12dedb1676ff2 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -325,10 +325,12 @@ function foldClaudeFields(fields: ClaudeFields, record: DecodedTranscriptRecord) const model = record.message?.model?.trim(); return { sessionId: record.sessionId?.trim() || fields.sessionId, - title: record.aiTitle?.trim() || fields.title, + title: claudeTitle(record.aiTitle) ?? fields.title, // Claude flushes the AI title after the user's rename; an empty rename clears it. customTitle: - record.customTitle === undefined ? fields.customTitle : record.customTitle.trim() || null, + record.customTitle === undefined + ? fields.customTitle + : (claudeTitle(record.customTitle) ?? null), // Claude uses this sentinel for local error responses. It is not a // model ID that can be selected when the imported session resumes. model: model && model !== "" ? model : fields.model, @@ -366,6 +368,44 @@ function codexHistoryBase(records: ReadonlyArray) { : undefined; } +// Claude Code records its own UI as user turns: slash commands, `!` shell runs and +// their output, task notifications. Keep what the user typed, as they typed it. +const CLAUDE_UI_OUTPUT = + /^(?:<(?:task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>|\[Request interrupted by user(?: for tool use)?\]$)/; + +/** + * A slash command as typed. Its arguments may name the thread; a bare command + * leaves that to a later prompt. Null for any other text. + */ +function claudeCommand(text: string): { readonly text: string; readonly titleText: string } | null { + if (!/^/.test(text)) return null; + const name = + /([^<]*)<\/command-name>/.exec(text)?.[1]?.trim() || + `/${/([^<]*)<\/command-message>/.exec(text)?.[1]?.trim() ?? ""}`; + const args = /([\s\S]*?)<\/command-args>/.exec(text)?.[1]?.trim() ?? ""; + return { text: args.length === 0 ? name : `${name} ${args}`, titleText: args }; +} + +/** What a Claude user turn shows the user typed, and the part of it that may name the thread. */ +function claudeUserText(text: string): { readonly text: string; readonly titleText: string } { + if (CLAUDE_UI_OUTPUT.test(text)) return { text: "", titleText: "" }; + const shellInput = /^([\s\S]*)<\/bash-input>$/.exec(text)?.[1]; + if (shellInput !== undefined) return { text: `!${shellInput}`, titleText: "" }; + return claudeCommand(text) ?? { text, titleText: text }; +} + +function claudeVisibleText(record: DecodedTranscriptRecord) { + const text = extractText(record.message?.content); + return record.type === "user" ? claudeUserText(text) : { text, titleText: text }; +} + +/** Saved titles can be the raw markup of a user turn, such as the command that opened the session. */ +function claudeTitle(title: string | undefined): string | undefined { + const trimmed = title?.trim(); + if (!trimmed) return undefined; + return claudeUserText(trimmed).text === trimmed ? trimmed : undefined; +} + function deriveTitle(source: AgentSessionSource, text: string): string | undefined { const request = source === "codex" ? text.replace(CODEX_TITLE_PREAMBLE, "") : text; return request.trim().split("\n")[0]?.slice(0, 100).trim() || undefined; @@ -440,6 +480,9 @@ function parseAgentSessionRecords( : (claudeFields.title ?? null); let model = claudeFields.model ?? null; let derivedTitle: string | undefined; + // Names a session whose only request was a bare command, such as `/review`. + let bareCommandTitle: string | undefined; + let hasAssistantMessage = false; let hasCodexSessionId = false; const messages: Array = []; let firstUserMessage: @@ -501,13 +544,16 @@ function parseAgentSessionRecords( let conversationMessageCount = 0; const retainMessage = ( message: AgentSessionThreadMessage & { readonly codexResponseUser: boolean }, + titleText = message.text, ) => { if (firstUserMessage === undefined && message.role === "user") { firstUserMessage = message; } if (derivedTitle === undefined && message.role === "user") { - derivedTitle = deriveTitle(input.source, message.text); + derivedTitle = deriveTitle(input.source, titleText); + bareCommandTitle ??= deriveTitle(input.source, message.text); } + hasAssistantMessage ||= message.role === "assistant"; conversationMessageCount += 1; messages.push(message); if (messages.length > MAX_IMPORTED_MESSAGES) messages.shift(); @@ -547,14 +593,17 @@ function parseAgentSessionRecords( if (input.source === "claudeAgent") { if (isHiddenClaudeRecord(record)) continue; if (record.type !== "user" && record.type !== "assistant") continue; - const text = extractText(record.message?.content); + const { text, titleText } = claudeVisibleText(record); if (text.length === 0) continue; - retainMessage({ - role: record.type, - text, - createdAt: normalizeTimestamp(record.timestamp, fallbackTimestamp), - codexResponseUser: false, - }); + retainMessage( + { + role: record.type, + text, + createdAt: normalizeTimestamp(record.timestamp, fallbackTimestamp), + codexResponseUser: false, + }, + titleText, + ); continue; } @@ -619,7 +668,14 @@ function parseAgentSessionRecords( const visibleMessages = messages.map( ({ codexResponseUser: _codexResponseUser, ...message }) => message, ); - if (providerSessionId.trim().length === 0 || firstUserMessage === undefined) return null; + if ( + providerSessionId.trim().length === 0 || + firstUserMessage === undefined || + // A Claude session of bare commands such as `/clear` that no reply followed did nothing. + (input.source === "claudeAgent" && derivedTitle === undefined && !hasAssistantMessage) + ) { + return null; + } const firstUserMessageRetained = messages.includes(firstUserMessage); const { codexResponseUser: _codexResponseUser, ...visibleFirstUserMessage } = firstUserMessage; const retainedMessages = firstUserMessageRetained @@ -630,7 +686,8 @@ function parseAgentSessionRecords( source: input.source, providerInstanceId: input.providerInstanceId, providerSessionId, - title: claudeFields.customTitle ?? title ?? derivedTitle ?? "Imported thread", + title: + claudeFields.customTitle ?? title ?? derivedTitle ?? bareCommandTitle ?? "Imported thread", model, createdAt: retainedMessages[0]?.createdAt ?? fallbackTimestamp, updatedAt: fallbackTimestamp, diff --git a/docs/user/welcome-page.md b/docs/user/welcome-page.md index f280ace079147..c5cf40f4c41d8 100644 --- a/docs/user/welcome-page.md +++ b/docs/user/welcome-page.md @@ -94,7 +94,10 @@ newest remaining visible user and assistant messages, with 200 messages total. It omits tool activity and attachments. For Codex, it omits generated setup context only when a canonical user event and a valid shared turn ID identify the same user turn. Ambiguous legacy or response-only context stays in the imported -conversation so T3 Code does not remove user text. It reads one conversation at +conversation so T3 Code does not remove user text. For Claude, slash commands +and `!` shell commands appear as you typed them; their output, background task +notifications and interruption markers are left out, and a conversation that +only ran commands such as `/clear`, with no reply, is skipped. It reads one conversation at a time and skips files larger than 4 GiB. It also skips a conversation when the message text and metadata it keeps need more than 32 MiB of memory. Tool output does not count toward that limit. It skips a conversation with more than 100,000 From c618270102bba0bcb32a9a86ed6169eca15d5b3a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 16:06:36 +0000 Subject: [PATCH 2/3] test(server): drop duplicate Claude custom-title case, rewrap import docs Co-Authored-By: Claude Opus 5.5 --- apps/server/src/project/AgentSessionScanner.test.ts | 4 ---- docs/user/welcome-page.md | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 563729f57c714..8d62379be3a0b 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3100,10 +3100,6 @@ describe("parseAgentSessionTranscript", () => { expected: "Generated title", }, { customTitles: ["npm test"], expected: "Generated title" }, - { - customTitles: ["/reviewlogin flow"], - expected: "Generated title", - }, ])("uses Claude custom titles $customTitles over the AI title", ({ customTitles, expected }) => { const aiTitle = JSON.stringify({ type: "ai-title", diff --git a/docs/user/welcome-page.md b/docs/user/welcome-page.md index f6b98736e417d..422a13ddbb57c 100644 --- a/docs/user/welcome-page.md +++ b/docs/user/welcome-page.md @@ -98,8 +98,8 @@ same user turn. Ambiguous legacy or response-only context stays in the imported conversation so T3 Code does not remove user text. For Claude, slash commands and `!` shell commands appear as you typed them; their output, background task notifications and interruption markers are left out, and a conversation that -only ran commands such as `/clear`, with no reply, is skipped. It reads one conversation at -a time and skips files larger than 4 GiB. It also skips a conversation when the +only ran commands such as `/clear`, with no reply, is skipped. It reads one +conversation at a time and skips files larger than 4 GiB. It also skips a conversation when the message text and metadata it keeps need more than 32 MiB of memory. Tool output does not count toward that limit. It skips a conversation with more than 100,000 records every time, so opening the page again does not import it. It ignores From 5819b56647c1f038cb34fb138c9dfd27377de618 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 16:20:43 +0000 Subject: [PATCH 3/3] fix(server): Claude Code output no longer evicts real messages from the import window The Claude history window kept records by raw content, so generated output such as took slots that real prompts and replies needed, and the session could then look command-only and be skipped. The window now keeps a record only when the parser would show it. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/project/AgentSessionScanner.test.ts | 10 ++++++++++ apps/server/src/project/AgentSessionScanner.ts | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 8d62379be3a0b..4287968c67ff2 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -2425,15 +2425,25 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { content: [{ type: "tool_result", tool_use_id: "toolu_1", content: "ok" }], }, }); + // Claude Code's own command output is not a message and must not take a history slot. + const commandOutput = record({ + type: "user", + message: { + role: "user", + content: "Compacted", + }, + }); yield* writeTranscript({ filePath: path.join(claudeHomePath, "projects", "-slug", "long-session.jsonl"), contents: [ record({ type: "attachment", cwd: workspace, aiTitle: "Old title" }), + commandOutput, record({ type: "user", message: { role: "user", content: "First prompt" } }), record({ type: "assistant", message: { role: "assistant", model: "claude-opus-5-5", content: "First reply" }, }), + ...Array.from({ length: 200 }, () => commandOutput), // Small tool records exceed the real 32 MiB selected-history budget in aggregate. ...Array.from({ length: 20_000 }, () => toolResult), record({ type: "user", message: { role: "user", content: "Latest prompt" } }), diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 8c209c8062e69..a8cb876cf0fec 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -743,12 +743,8 @@ function shouldRetainDecodedRecord( if (isHiddenClaudeRecord(record) || (record.type !== "user" && record.type !== "assistant")) { return false; } - const content = record.message?.content; - return typeof content === "string" - ? content.trim().length > 0 - : (content?.some( - (block) => isTextContentBlock(block) && (block.text?.trim().length ?? 0) > 0, - ) ?? false); + // Same rule as the parser, so Claude Code's own output never takes a history window slot. + return claudeVisibleText(record).text.length > 0; } if (extractDecodedCwd(record) !== null) return true; return (