The best way to control Claude Code, Codex and more from any computer or phone
fix(server): long Claude sessions import instead of being skipped (#29183)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 12:00 UTC
c4cf58511b1cc957ba3efa92563d0d187d0ff768
2 files changed
+131
-5
apps/server/src/project/AgentSessionScanner.test.ts
+89
@@ -2034,6 +2034,95 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
2034
}),
2035
);
2036
2037
+ it.effect("imports long Claude history beyond the selected-history and record limits", () =>
2038
+ Effect.gen(function* () {
2039
+ const path = yield* Path.Path;
2040
+ const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
2041
+ yield* TestClock.setTime(nowMs);
2042
+ const claudeHomePath = yield* makeTempDir("t3code-long-conversation-claude-");
2043
+ const codexHomePath = yield* makeTempDir("t3code-long-conversation-codex-");
2044
+ const workspace = yield* makeTempDir("t3code-long-conversation-workspace-");
2045
+ const record = (fields: Record<string, unknown>) =>
2046
+ encodeTranscriptRecord({ sessionId: "claude-long", ...fields });
2047
+ const longText = "x".repeat(64 * 1024);
2048
+ const middleCount = 600;
2049
+ yield* writeTranscript({
2050
+ filePath: path.join(claudeHomePath, "projects", "-slug", "claude-long.jsonl"),
2051
+ contents: [
2052
+ record({
2053
+ type: "user",
2054
+ cwd: workspace,
2055
+ message: { role: "user", content: "First prompt" },
2056
+ }),
2057
+ // 600 x 64 KiB exceeds the 32 MiB selected-history budget; the shown window fits.
2058
+ ...Array.from({ length: middleCount }, (_, index) => {
2059
+ const role = index % 2 === 0 ? "assistant" : "user";
2060
+ return record({ type: role, message: { role, content: longText } });
2061
+ }),
2062
+ // Tool and progress records push the file past the 100,000-record limit.
2063
+ ...Array.from({ length: 100_000 }, () => "{}"),
2064
+ record({ type: "user", message: { role: "user", content: "Latest prompt" } }),
2065
+ ].join("\n"),
2066
+ mtimeMs: nowMs - 60_000,
2067
+ });
2068
+
2069
+ const outcomes = yield* runRecentThreadOutcomes({
2070
+ claudeHomePath,
2071
+ codexHomePath,
2072
+ workspaceRoot: workspace,
2073
+ });
2074
+
2075
+ expect(outcomes.map((outcome) => outcome._tag)).toEqual(["Importable"]);
2076
+ const thread = outcomes[0]?._tag === "Importable" ? outcomes[0].thread : undefined;
2077
+ expect(thread?.messages[0]).toMatchObject({ role: "user", text: "First prompt" });
2078
+ expect(thread?.messages.at(-1)).toMatchObject({ role: "user", text: "Latest prompt" });
2079
+ expect(thread?.messages).toHaveLength(200);
2080
+ expect(thread?.omittedMessageCount).toBe(middleCount + 2 - 200);
2081
+ }),
2082
+ );
2083
+
2084
+ it.effect("imports a late first Claude prompt once when older replies are dropped", () =>
2085
+ Effect.gen(function* () {
2086
+ const path = yield* Path.Path;
2087
+ const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
2088
+ yield* TestClock.setTime(nowMs);
2089
+ const claudeHomePath = yield* makeTempDir("t3code-late-prompt-claude-");
2090
+ const codexHomePath = yield* makeTempDir("t3code-late-prompt-codex-");
2091
+ const workspace = yield* makeTempDir("t3code-late-prompt-workspace-");
2092
+ const contents = [
2093
+ encodeTranscriptRecord({ type: "attachment", sessionId: "late-prompt", cwd: workspace }),
2094
+ // The first prompt is still among the latest 200 messages after older replies drop out.
2095
+ ...Array.from({ length: 250 }, (_, index) => {
2096
+ const role = index < 60 || index % 2 === 1 ? "assistant" : "user";
2097
+ return encodeTranscriptRecord({
2098
+ type: role,
2099
+ sessionId: "late-prompt",
2100
+ message: { role, content: `${role} ${index}` },
2101
+ });
2102
+ }),
2103
+ ].join("\n");
2104
+ const filePath = path.join(claudeHomePath, "projects", "-slug", "late-prompt.jsonl");
2105
+ yield* writeTranscript({ filePath, contents, mtimeMs: nowMs - 60_000 });
2106
+
2107
+ const [thread] = yield* runRecentThreads({
2108
+ claudeHomePath,
2109
+ codexHomePath,
2110
+ workspaceRoot: workspace,
2111
+ });
2112
+
2113
+ expect(thread?.messages[0]).toMatchObject({ role: "assistant", text: "assistant 50" });
2114
+ expect(thread).toEqual(
2115
+ AgentSessionScanner.parseAgentSessionTranscript({
2116
+ source: "claudeAgent",
2117
+ providerInstanceId: ProviderInstanceId.make("claudeAgent"),
2118
+ fallbackSessionId: "late-prompt",
2119
+ lastActiveAtMs: nowMs - 60_000,
2120
+ contents,
2121
+ }),
2122
+ );
2123
+ }),
2124
+ );
2125
+
2126
it.effect("skips growth during reading without exceeding the reserved bytes", () =>
2127
Effect.gen(function* () {
2128
const path = yield* Path.Path;
apps/server/src/project/AgentSessionScanner.ts
+42
-5
@@ -431,13 +431,14 @@ export function parseAgentSessionTranscript(
431
input.source === "claudeAgent"
432
? records.reduce(foldClaudeFields, emptyClaudeFields)
433
: emptyClaudeFields;
434
- return parseAgentSessionRecords(input, records, claudeFields);
434
+ return parseAgentSessionRecords(input, records, claudeFields, 0);
435
}
436
437
function parseAgentSessionRecords(
438
input: AgentSessionTranscriptMetadata,
439
records: ReadonlyArray<DecodedTranscriptRecord>,
440
claudeFields: ClaudeFields,
441
+ droppedMessageCount: number,
442
): AgentSessionThread | null {
443
const fallbackTimestamp = DateTime.formatIso(DateTime.makeUnsafe(input.lastActiveAtMs));
444
// Claude filenames are session IDs. Codex rollout filenames include extra
@@ -650,7 +651,7 @@ function parseAgentSessionRecords(
651
createdAt: retainedMessages[0]?.createdAt ?? fallbackTimestamp,
652
updatedAt: fallbackTimestamp,
653
messages: retainedMessages,
653
- omittedMessageCount: conversationMessageCount - retainedMessages.length,
654
+ omittedMessageCount: conversationMessageCount + droppedMessageCount - retainedMessages.length,
655
};
656
}
657
@@ -687,6 +688,31 @@ function shouldRetainDecodedRecord(
688
);
689
}
690
691
+// The import shows only the first user message and the latest messages, so a
692
+// long Claude session holds just those and counts the rest as dropped.
693
+function createClaudeHistoryWindow() {
694
+ const recent: Array<{ readonly record: DecodedTranscriptRecord; readonly bytes: number }> = [];
695
+ let firstUser: DecodedTranscriptRecord | undefined;
696
+ let droppedMessageCount = 0;
697
+ return {
698
+ // Takes a record shouldRetainDecodedRecord kept; returns the bytes it released.
699
+ push: (record: DecodedTranscriptRecord, bytes: number): number => {
700
+ if (firstUser === undefined && record.type === "user") firstUser = record;
701
+ recent.push({ record, bytes });
702
+ if (recent.length <= MAX_IMPORTED_MESSAGES) return 0;
703
+ const evicted = recent.shift();
704
+ if (evicted === undefined || evicted.record === firstUser) return 0;
705
+ droppedMessageCount += 1;
706
+ return evicted.bytes;
707
+ },
708
+ records: () => {
709
+ const held = recent.map((entry) => entry.record);
710
+ return firstUser === undefined || held.includes(firstUser) ? held : [firstUser, ...held];
711
+ },
712
+ droppedMessageCount: () => droppedMessageCount,
713
+ };
714
+}
715
+
716
function normalizeForWorktreeMatch(value: string, caseFold: boolean): string {
717
const normalized = `${value.replaceAll("\\", "/")}/`;
718
return caseFold ? normalized.toLowerCase() : normalized;
@@ -1056,6 +1082,7 @@ export const make = Effect.gen(function* () {
1082
return null;
1083
}
1084
const records: Array<DecodedTranscriptRecord> = [];
1085
+ const claudeHistory = createClaudeHistoryWindow();
1086
let cwd = Option.none<string>();
1087
let claudeFields = emptyClaudeFields;
1088
let historyBytes = prefix?.historyBytes ?? 0;
@@ -1077,7 +1104,8 @@ export const make = Effect.gen(function* () {
1104
const finishRecord = () => {
1105
reader.write(decoder.decode());
1106
recordCount += 1;
1080
- if (recordCount > MAX_IMPORT_RECORDS) return false;
1107
+ // Claude keeps a bounded window, so only the byte budgets limit its length.
1108
+ if (recordCount > MAX_IMPORT_RECORDS && source !== "claudeAgent") return false;
1109
const value = reader.finish();
1110
const decoded = decodeTranscriptValue(value);
1111
if (Option.isNone(decoded) && source === "pi") {
@@ -1089,7 +1117,9 @@ export const make = Effect.gen(function* () {
1117
claudeFields = foldClaudeFields(claudeFields, decoded.value);
1118
}
1119
if (shouldRetainDecodedRecord(source, decoded.value)) {
1092
- if (
1120
+ if (source === "claudeAgent") {
1121
+ historyBytes += recordBytes - claudeHistory.push(decoded.value, recordBytes);
1122
+ } else if (
1123
source === "pi" &&
1124
decoded.value.type === "message" &&
1125
!isPiConversationRecord(decoded.value)
@@ -1147,7 +1177,13 @@ export const make = Effect.gen(function* () {
1177
)
1178
return null;
1179
return sameTranscriptIdentity(expected, transcriptIdentity(filePath, yield* file.stat))
1150
- ? { records, cwd, claudeFields, historyBytes }
1180
+ ? {
1181
+ records: source === "claudeAgent" ? claudeHistory.records() : records,
1182
+ droppedMessageCount: claudeHistory.droppedMessageCount(),
1183
+ cwd,
1184
+ claudeFields,
1185
+ historyBytes,
1186
+ }
1187
: null;
1188
}),
1189
),
@@ -1900,6 +1936,7 @@ export const make = Effect.gen(function* () {
1936
? snapshot.records
1937
: [...inheritedRecords, ...snapshot.records],
1938
snapshot.claudeFields,
1939
+ snapshot.droppedMessageCount,
1940
);
1941
if (parsedThread === null) {
1942
return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });