@devries-cameron20 / t3code-1 / commits / 4e08e9d141
Fork 0

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

fix(server): imported Codex threads keep their saved Codex names (#24982)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 31, 2026 at 03:45 UTC 4e08e9d1416509e54d9260a4e2c461864a986141
2 files changed +111 -1
apps/server/src/project/AgentSessionScanner.test.ts
+50
@@ -1245,6 +1245,56 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1245 }),
1246 );
1247
1248 + it.effect("titles Codex sessions with their newest saved Codex name", () =>
1249 + Effect.gen(function* () {
1250 + const fileSystem = yield* FileSystem.FileSystem;
1251 + const path = yield* Path.Path;
1252 + const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1253 + yield* TestClock.setTime(nowMs);
1254 + const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1255 + const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1256 + const workspace = yield* makeTempDir("t3code-workspace-");
1257 +
1258 + yield* writeTranscript({
1259 + filePath: path.join(codexHomePath, "sessions", "2026", "08", "24", "rollout-named.jsonl"),
1260 + contents: [
1261 + encodeTranscriptRecord({
1262 + type: "session_meta",
1263 + payload: { id: "named-session", cwd: workspace },
1264 + }),
1265 + encodeTranscriptRecord({
1266 + type: "event_msg",
1267 + payload: {
1268 + type: "user_message",
1269 + message:
1270 + '<external_codex_apps_open_page>{"page_id":null}</external_codex_apps_open_page>\nHey, what\'s up?',
1271 + },
1272 + }),
1273 + ].join("\n"),
1274 + mtimeMs: nowMs,
1275 + });
1276 + yield* fileSystem.writeFileString(
1277 + path.join(codexHomePath, "session_index.jsonl"),
1278 + [
1279 + { id: "named-session", thread_name: "First name" },
1280 + { id: "other-session", thread_name: "Other chat" },
1281 + { id: "named-session", thread_name: "Renamed chat" },
1282 + { id: "named-session", thread_name: " " },
1283 + ]
1284 + .map((entry) => `${encodeTranscriptRecord({ ...entry, updated_at: "unknown" })}\n`)
1285 + .join(""),
1286 + );
1287 +
1288 + const threads = yield* runRecentThreads({
1289 + claudeHomePath,
1290 + codexHomePath,
1291 + workspaceRoot: workspace,
1292 + });
1293 +
1294 + expect(threads.map((thread) => thread.title)).toEqual(["Renamed chat"]);
1295 + }),
1296 + );
1297 +
1298 it.effect("excludes Codex subagents from discovery and the recent-thread budget", () =>
1299 Effect.gen(function* () {
1300 const path = yield* Path.Path;
apps/server/src/project/AgentSessionScanner.ts
+61 -1
@@ -46,6 +46,7 @@ import {
46 const TRANSCRIPT_PREFIX_BYTES = 32 * 1024;
47 const METADATA_READ_BYTES = 8 * 1024;
48 const MAX_TRANSCRIPT_SCAN_BYTES = 1024 * 1024;
49 +const MAX_CODEX_SESSION_INDEX_BYTES = 1024 * 1024;
50
51 const MAX_TRANSCRIPTS_PER_SOURCE = 5000;
52
@@ -108,6 +109,11 @@ const TranscriptRecord = Schema.Struct({
109 ),
110 });
111
112 +const CodexSessionIndexEntry = Schema.Struct({
113 + id: Schema.String,
114 + thread_name: Schema.String,
115 +});
116 +
117 const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings);
118 const decodeCodexSettings = Schema.decodeUnknownOption(CodexSettings);
119 const decodeTranscriptRecord = Schema.decodeUnknownOption(Schema.fromJsonString(TranscriptRecord));
@@ -121,6 +127,9 @@ const decodePiEntryLinks = Schema.decodeUnknownOption(
127 );
128 const selectTranscriptPath = createTranscriptJsonSelector(TranscriptRecord);
129 const decodeCodexTurnMetadata = Schema.decodeUnknownOption(CodexTurnMetadata);
130 +const decodeCodexSessionIndexEntry = Schema.decodeUnknownOption(
131 + Schema.fromJsonString(CodexSessionIndexEntry),
132 +);
133
134 type DecodedTranscriptRecord = typeof TranscriptRecord.Type;
135
@@ -175,6 +184,7 @@ interface RawCandidate {
184 readonly cwd: string;
185 readonly source: AgentSessionSource;
186 readonly providerInstanceId: ProviderInstanceId;
187 + readonly homePath: string;
188 readonly threadCount: number;
189 readonly lastActiveAtMs: number | null;
190 readonly transcripts: ReadonlyArray<{
@@ -187,6 +197,7 @@ interface TranscriptCandidate {
197 readonly filePath: string;
198 readonly mtimeMs: number;
199 readonly providerInstanceId: ProviderInstanceId;
200 + readonly homePath: string;
201 readonly size: number;
202 }
203
@@ -295,6 +306,17 @@ function foldClaudeFields(fields: ClaudeFields, record: DecodedTranscriptRecord)
306 const CODEX_TITLE_PREAMBLE =
307 /^(?:\s*(?:<(recommended_plugins|environment_context|user_instructions|INSTRUCTIONS|in-app-browser-context)(?:\s[^>]*)?>[\s\S]*?<\/\1>|# AGENTS\.md instructions\b[^\n]*|## My request for Codex:))+/;
308
309 +// Codex appends an entry per rename; like Codex, the newest nonempty name wins.
310 +function parseCodexThreadNames(contents: string): ReadonlyMap<string, string> {
311 + const names = new Map<string, string>();
312 + for (const line of contents.split("\n")) {
313 + const entry = Option.getOrUndefined(decodeCodexSessionIndexEntry(line));
314 + const name = entry?.thread_name.trim();
315 + if (entry !== undefined && name) names.set(entry.id, name);
316 + }
317 + return names;
318 +}
319 +
320 function deriveTitle(source: AgentSessionSource, text: string): string | undefined {
321 const request = source === "codex" ? text.replace(CODEX_TITLE_PREAMBLE, "") : text;
322 return request.trim().split("\n")[0]?.slice(0, 100).trim() || undefined;
@@ -984,6 +1006,29 @@ export const make = Effect.gen(function* () {
1006 );
1007 });
1008
1009 + const readCodexThreadNames = Effect.fn("AgentSessionScanner.readCodexThreadNames")(function* (
1010 + homePath: string,
1011 + ) {
1012 + const indexPath = path.join(homePath, "session_index.jsonl");
1013 + return yield* Effect.scoped(
1014 + Effect.gen(function* () {
1015 + const file = yield* fileSystem.open(indexPath, { flag: "r" });
1016 + const size = Number((yield* file.stat).size);
1017 + const start = Math.max(0, size - MAX_CODEX_SESSION_INDEX_BYTES);
1018 + yield* file.seek(BigInt(start), "start");
1019 + const bytes = yield* file.readAlloc(size - start);
1020 + const contents = Option.match(bytes, {
1021 + onNone: () => "",
1022 + onSome: (value) => new TextDecoder().decode(value),
1023 + });
1024 + // A tail read can start mid-record.
1025 + return parseCodexThreadNames(
1026 + start > 0 ? contents.slice(contents.indexOf("\n") + 1) : contents,
1027 + );
1028 + }),
1029 + ).pipe(Effect.orElseSucceed((): ReadonlyMap<string, string> => new Map()));
1030 + });
1031 +
1032 const resolveClaudeConfigDir = (homePath: string, environmentHome?: string): string => {
1033 const configured = homePath.trim();
1034 if (configured.length > 0) {
@@ -1040,6 +1085,7 @@ export const make = Effect.gen(function* () {
1085 filePath,
1086 mtimeMs: stats.value.mtime.value.getTime(),
1087 providerInstanceId,
1088 + homePath,
1089 size: Number(stats.value.size),
1090 });
1091 }
@@ -1101,6 +1147,7 @@ export const make = Effect.gen(function* () {
1147 filePath,
1148 mtimeMs: stats.value.mtime.value.getTime(),
1149 providerInstanceId,
1150 + homePath,
1151 size: Number(stats.value.size),
1152 });
1153 }
@@ -1175,6 +1222,7 @@ export const make = Effect.gen(function* () {
1222 {
1223 cwd: string;
1224 providerInstanceId: ProviderInstanceId;
1225 + homePath: string;
1226 lastActiveAtMs: number;
1227 transcripts: Array<{ filePath: string; mtimeMs: number }>;
1228 }
@@ -1192,6 +1240,7 @@ export const make = Effect.gen(function* () {
1240 byOwnerAndCwd.set(key, {
1241 cwd,
1242 providerInstanceId: transcript.providerInstanceId,
1243 + homePath: transcript.homePath,
1244 lastActiveAtMs: transcript.mtimeMs,
1245 transcripts: [transcript],
1246 });
@@ -1202,6 +1251,7 @@ export const make = Effect.gen(function* () {
1251 cwd: group.cwd,
1252 source,
1253 providerInstanceId: group.providerInstanceId,
1254 + homePath: group.homePath,
1255 threadCount: group.transcripts.length,
1256 lastActiveAtMs: group.lastActiveAtMs,
1257 transcripts: group.transcripts,
@@ -1504,6 +1554,7 @@ export const make = Effect.gen(function* () {
1554 (source) => `${source.providerInstanceId}\0${source.filePath}`,
1555 );
1556 const importedSessions = new Set<string>();
1557 + const codexThreadNamesByHome = new Map<string, ReadonlyMap<string, string>>();
1558 let bytesRemaining = MAX_IMPORT_BYTES;
1559 let transcriptsRemaining = MAX_IMPORT_TRANSCRIPTS;
1560 let recordsRemaining = MAX_IMPORT_RECORDS;
@@ -1582,6 +1633,14 @@ export const make = Effect.gen(function* () {
1633 if (parsedThread === null) {
1634 return Option.some<AgentSessionRecentThread>({ _tag: "Skipped" });
1635 }
1636 + let savedTitle: string | undefined;
1637 + if (candidate.source === "codex") {
1638 + const names =
1639 + codexThreadNamesByHome.get(candidate.homePath) ??
1640 + (yield* readCodexThreadNames(candidate.homePath));
1641 + codexThreadNamesByHome.set(candidate.homePath, names);
1642 + savedTitle = names.get(parsedThread.providerSessionId);
1643 + }
1644
1645 const source: AgentSessionImportSource = {
1646 ...identity,
@@ -1596,7 +1655,8 @@ export const make = Effect.gen(function* () {
1655 importedSessions.add(sessionKey);
1656 return Option.some<AgentSessionRecentThread>({
1657 _tag: "Importable",
1599 - thread: parsedThread,
1658 + thread:
1659 + savedTitle === undefined ? parsedThread : { ...parsedThread, title: savedTitle },
1660 source,
1661 });
1662 }).pipe(importReadLock.withPermits(1)),