The best way to control Claude Code, Codex and more from any computer or phone
Persist changed-files expansion state per thread (#1858)
Ibrahim Elkamali committed
Apr 10, 2026 at 20:41 UTC
9385314d26aba97d1fed1e05066e4562dbdf56bc
6 files changed
+237
-17
apps/web/src/components/ChatView.tsx
+23
-2
@@ -172,6 +172,7 @@ const IMAGE_ONLY_BOOTSTRAP_PROMPT =
172
const EMPTY_ACTIVITIES: OrchestrationThreadActivity[] = [];
173
const EMPTY_PROPOSED_PLANS: Thread["proposedPlans"] = [];
174
const EMPTY_PROVIDERS: ServerProvider[] = [];
175
+const EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID: Record<string, boolean> = {};
176
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
177
178
type ThreadPlanCatalogEntry = Pick<Thread, "id" | "proposedPlans">;
@@ -574,6 +575,7 @@ export default function ChatView(props: ChatViewProps) {
575
() => scopeThreadRef(environmentId, threadId),
576
[environmentId, threadId],
577
);
578
+ const routeThreadKey = useMemo(() => scopedThreadKey(routeThreadRef), [routeThreadRef]);
579
const composerDraftTarget: ScopedThreadRef | DraftId =
580
routeKind === "server" ? routeThreadRef : props.draftId;
581
const serverThread = useStore(
@@ -584,10 +586,17 @@ export default function ChatView(props: ChatViewProps) {
586
);
587
const setStoreThreadError = useStore((store) => store.setError);
588
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
589
+ const setThreadChangedFilesExpanded = useUiStateStore(
590
+ (store) => store.setThreadChangedFilesExpanded,
591
+ );
592
const activeThreadLastVisitedAt = useUiStateStore((store) =>
593
+ routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined,
594
+ );
595
+ const changedFilesExpandedByTurnId = useUiStateStore((store) =>
596
routeKind === "server"
589
- ? store.threadLastVisitedAtById[scopedThreadKey(scopeThreadRef(environmentId, threadId))]
590
- : undefined,
597
+ ? (store.threadChangedFilesExpandedById[routeThreadKey] ??
598
+ EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID)
599
+ : EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID,
600
);
601
const settings = useSettings();
602
const setStickyComposerModelSelection = useComposerDraftStore(
@@ -981,6 +990,16 @@ export default function ChatView(props: ChatViewProps) {
990
[openOrReuseProjectDraftThread],
991
);
992
993
+ const handleSetChangedFilesExpanded = useCallback(
994
+ (turnId: TurnId, expanded: boolean) => {
995
+ if (routeKind !== "server") {
996
+ return;
997
+ }
998
+ setThreadChangedFilesExpanded(routeThreadKey, turnId, expanded);
999
+ },
1000
+ [routeKind, routeThreadKey, setThreadChangedFilesExpanded],
1001
+ );
1002
+
1003
useEffect(() => {
1004
if (!serverThread?.id) return;
1005
if (!latestTurnSettled) return;
@@ -3337,6 +3356,8 @@ export default function ChatView(props: ChatViewProps) {
3356
activeThreadEnvironmentId={activeThread.environmentId}
3357
expandedWorkGroups={expandedWorkGroups}
3358
onToggleWorkGroup={onToggleWorkGroup}
3359
+ changedFilesExpandedByTurnId={changedFilesExpandedByTurnId}
3360
+ onSetChangedFilesExpanded={handleSetChangedFilesExpanded}
3361
onOpenTurnDiff={onOpenTurnDiff}
3362
revertTurnCountByUserMessageId={revertTurnCountByUserMessageId}
3363
onRevertUserMessage={onRevertUserMessage}
apps/web/src/components/chat/MessagesTimeline.test.tsx
+4
@@ -82,6 +82,8 @@ describe("MessagesTimeline", () => {
82
nowIso="2026-03-17T19:12:30.000Z"
83
expandedWorkGroups={{}}
84
onToggleWorkGroup={() => {}}
85
+ changedFilesExpandedByTurnId={{}}
86
+ onSetChangedFilesExpanded={() => {}}
87
onOpenTurnDiff={() => {}}
88
revertTurnCountByUserMessageId={new Map()}
89
onRevertUserMessage={() => {}}
@@ -128,6 +130,8 @@ describe("MessagesTimeline", () => {
130
nowIso="2026-03-17T19:12:30.000Z"
131
expandedWorkGroups={{}}
132
onToggleWorkGroup={() => {}}
133
+ changedFilesExpandedByTurnId={{}}
134
+ onSetChangedFilesExpanded={() => {}}
135
onOpenTurnDiff={() => {}}
136
revertTurnCountByUserMessageId={new Map()}
137
onRevertUserMessage={() => {}}
apps/web/src/components/chat/MessagesTimeline.tsx
+8
-11
@@ -77,6 +77,8 @@ interface MessagesTimelineProps {
77
nowIso: string;
78
expandedWorkGroups: Record<string, boolean>;
79
onToggleWorkGroup: (groupId: string) => void;
80
+ changedFilesExpandedByTurnId: Record<string, boolean>;
81
+ onSetChangedFilesExpanded: (turnId: TurnId, expanded: boolean) => void;
82
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
83
revertTurnCountByUserMessageId: Map<MessageId, number>;
84
onRevertUserMessage: (messageId: MessageId) => void;
@@ -113,6 +115,8 @@ export const MessagesTimeline = memo(function MessagesTimeline({
115
nowIso,
116
expandedWorkGroups,
117
onToggleWorkGroup,
118
+ changedFilesExpandedByTurnId,
119
+ onSetChangedFilesExpanded,
120
onOpenTurnDiff,
121
revertTurnCountByUserMessageId,
122
onRevertUserMessage,
@@ -296,15 +300,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({
300
301
const virtualRows = rowVirtualizer.getVirtualItems();
302
const nonVirtualizedRows = rows.slice(virtualizedRowCount);
299
- const [allDirectoriesExpandedByTurnId, setAllDirectoriesExpandedByTurnId] = useState<
300
- Record<string, boolean>
301
- >({});
302
- const onToggleAllDirectories = useCallback((turnId: TurnId) => {
303
- setAllDirectoriesExpandedByTurnId((current) => ({
304
- ...current,
305
- [turnId]: !(current[turnId] ?? true),
306
- }));
307
- }, []);
303
304
const renderRowContent = (row: TimelineRow) => (
305
<div
@@ -466,7 +461,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
461
const summaryStat = summarizeTurnDiffStats(checkpointFiles);
462
const changedFileCountLabel = String(checkpointFiles.length);
463
const allDirectoriesExpanded =
469
- allDirectoriesExpandedByTurnId[turnSummary.turnId] ?? true;
464
+ changedFilesExpandedByTurnId[turnSummary.turnId] ?? true;
465
return (
466
<div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5">
467
<div className="mb-1.5 flex items-center justify-between gap-2">
@@ -488,7 +483,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({
483
size="xs"
484
variant="outline"
485
data-scroll-anchor-ignore
491
- onClick={() => onToggleAllDirectories(turnSummary.turnId)}
486
+ onClick={() =>
487
+ onSetChangedFilesExpanded(turnSummary.turnId, !allDirectoriesExpanded)
488
+ }
489
>
490
{allDirectoriesExpanded ? "Collapse all" : "Expand all"}
491
</Button>
apps/web/src/components/chat/MessagesTimeline.virtualization.browser.tsx
+17
@@ -61,6 +61,9 @@ function MessagesTimelineBrowserHarness(
61
const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>(
62
() => props.expandedWorkGroups,
63
);
64
+ const [changedFilesExpandedByTurnId, setChangedFilesExpandedByTurnId] = useState<
65
+ Record<string, boolean>
66
+ >(() => props.changedFilesExpandedByTurnId);
67
const handleToggleWorkGroup = useCallback(
68
(groupId: string) => {
69
setExpandedWorkGroups((current) => ({
@@ -71,6 +74,16 @@ function MessagesTimelineBrowserHarness(
74
},
75
[props],
76
);
77
+ const handleSetChangedFilesExpanded = useCallback(
78
+ (turnId: TurnId, expanded: boolean) => {
79
+ setChangedFilesExpandedByTurnId((current) => ({
80
+ ...current,
81
+ [turnId]: expanded,
82
+ }));
83
+ props.onSetChangedFilesExpanded(turnId, expanded);
84
+ },
85
+ [props],
86
+ );
87
88
return (
89
<div
@@ -84,6 +97,8 @@ function MessagesTimelineBrowserHarness(
97
scrollContainer={scrollContainer}
98
expandedWorkGroups={expandedWorkGroups}
99
onToggleWorkGroup={handleToggleWorkGroup}
100
+ changedFilesExpandedByTurnId={changedFilesExpandedByTurnId}
101
+ onSetChangedFilesExpanded={handleSetChangedFilesExpanded}
102
/>
103
</div>
104
);
@@ -168,6 +183,8 @@ function createBaseTimelineProps(input: {
183
nowIso: isoAt(10_000),
184
expandedWorkGroups: input.expandedWorkGroups ?? {},
185
onToggleWorkGroup: () => {},
186
+ changedFilesExpandedByTurnId: {},
187
+ onSetChangedFilesExpanded: () => {},
188
onOpenTurnDiff: () => {},
189
revertTurnCountByUserMessageId: new Map(),
190
onRevertUserMessage: () => {},
apps/web/src/uiStateStore.test.ts
+49
@@ -6,6 +6,7 @@ import {
6
markThreadUnread,
7
reorderProjects,
8
setProjectExpanded,
9
+ setThreadChangedFilesExpanded,
10
syncProjects,
11
syncThreads,
12
type UiState,
@@ -16,6 +17,7 @@ function makeUiState(overrides: Partial<UiState> = {}): UiState {
17
projectExpandedById: {},
18
projectOrder: [],
19
threadLastVisitedAtById: {},
20
+ threadChangedFilesExpandedById: {},
21
...overrides,
22
};
23
}
@@ -137,6 +139,14 @@ describe("uiStateStore pure functions", () => {
139
[thread1]: "2026-02-25T12:35:00.000Z",
140
[thread2]: "2026-02-25T12:36:00.000Z",
141
},
142
+ threadChangedFilesExpandedById: {
143
+ [thread1]: {
144
+ "turn-1": false,
145
+ },
146
+ [thread2]: {
147
+ "turn-2": false,
148
+ },
149
+ },
150
});
151
152
const next = syncThreads(initialState, [{ key: thread1 }]);
@@ -144,6 +154,11 @@ describe("uiStateStore pure functions", () => {
154
expect(next.threadLastVisitedAtById).toEqual({
155
[thread1]: "2026-02-25T12:35:00.000Z",
156
});
157
+ expect(next.threadChangedFilesExpandedById).toEqual({
158
+ [thread1]: {
159
+ "turn-1": false,
160
+ },
161
+ });
162
});
163
164
it("syncThreads seeds visit state for unseen snapshot threads", () => {
@@ -183,10 +198,44 @@ describe("uiStateStore pure functions", () => {
198
threadLastVisitedAtById: {
199
[thread1]: "2026-02-25T12:35:00.000Z",
200
},
201
+ threadChangedFilesExpandedById: {
202
+ [thread1]: {
203
+ "turn-1": false,
204
+ },
205
+ },
206
});
207
208
const next = clearThreadUi(initialState, thread1);
209
210
expect(next.threadLastVisitedAtById).toEqual({});
211
+ expect(next.threadChangedFilesExpandedById).toEqual({});
212
+ });
213
+
214
+ it("setThreadChangedFilesExpanded stores collapsed turns per thread", () => {
215
+ const thread1 = ThreadId.make("thread-1");
216
+ const initialState = makeUiState();
217
+
218
+ const next = setThreadChangedFilesExpanded(initialState, thread1, "turn-1", false);
219
+
220
+ expect(next.threadChangedFilesExpandedById).toEqual({
221
+ [thread1]: {
222
+ "turn-1": false,
223
+ },
224
+ });
225
+ });
226
+
227
+ it("setThreadChangedFilesExpanded removes thread overrides when expanded again", () => {
228
+ const thread1 = ThreadId.make("thread-1");
229
+ const initialState = makeUiState({
230
+ threadChangedFilesExpandedById: {
231
+ [thread1]: {
232
+ "turn-1": false,
233
+ },
234
+ },
235
+ });
236
+
237
+ const next = setThreadChangedFilesExpanded(initialState, thread1, "turn-1", true);
238
+
239
+ expect(next.threadChangedFilesExpandedById).toEqual({});
240
});
241
});
apps/web/src/uiStateStore.ts
+136
-4
@@ -18,6 +18,7 @@ const LEGACY_PERSISTED_STATE_KEYS = [
18
interface PersistedUiState {
19
expandedProjectCwds?: string[];
20
projectOrderCwds?: string[];
21
+ threadChangedFilesExpandedById?: Record<string, Record<string, boolean>>;
22
}
23
24
export interface UiProjectState {
@@ -27,6 +28,7 @@ export interface UiProjectState {
28
29
export interface UiThreadState {
30
threadLastVisitedAtById: Record<string, string>;
31
+ threadChangedFilesExpandedById: Record<string, Record<string, boolean>>;
32
}
33
34
export interface UiState extends UiProjectState, UiThreadState {}
@@ -45,6 +47,7 @@ const initialState: UiState = {
47
projectExpandedById: {},
48
projectOrder: [],
49
threadLastVisitedAtById: {},
50
+ threadChangedFilesExpandedById: {},
51
};
52
53
const persistedExpandedProjectCwds = new Set<string>();
@@ -69,13 +72,47 @@ function readPersistedState(): UiState {
72
}
73
return initialState;
74
}
72
- hydratePersistedProjectState(JSON.parse(raw) as PersistedUiState);
73
- return initialState;
75
+ const parsed = JSON.parse(raw) as PersistedUiState;
76
+ hydratePersistedProjectState(parsed);
77
+ return {
78
+ ...initialState,
79
+ threadChangedFilesExpandedById: sanitizePersistedThreadChangedFilesExpanded(
80
+ parsed.threadChangedFilesExpandedById,
81
+ ),
82
+ };
83
} catch {
84
return initialState;
85
}
86
}
87
88
+function sanitizePersistedThreadChangedFilesExpanded(
89
+ value: PersistedUiState["threadChangedFilesExpandedById"],
90
+): Record<string, Record<string, boolean>> {
91
+ if (!value || typeof value !== "object") {
92
+ return {};
93
+ }
94
+
95
+ const nextState: Record<string, Record<string, boolean>> = {};
96
+ for (const [threadId, turns] of Object.entries(value)) {
97
+ if (!threadId || !turns || typeof turns !== "object") {
98
+ continue;
99
+ }
100
+
101
+ const nextTurns: Record<string, boolean> = {};
102
+ for (const [turnId, expanded] of Object.entries(turns)) {
103
+ if (turnId && typeof expanded === "boolean" && expanded === false) {
104
+ nextTurns[turnId] = false;
105
+ }
106
+ }
107
+
108
+ if (Object.keys(nextTurns).length > 0) {
109
+ nextState[threadId] = nextTurns;
110
+ }
111
+ }
112
+
113
+ return nextState;
114
+}
115
+
116
function hydratePersistedProjectState(parsed: PersistedUiState): void {
117
persistedExpandedProjectCwds.clear();
118
persistedProjectOrderCwds.length = 0;
@@ -106,11 +143,20 @@ function persistState(state: UiState): void {
143
const cwd = currentProjectCwdById.get(projectId);
144
return cwd ? [cwd] : [];
145
});
146
+ const threadChangedFilesExpandedById = Object.fromEntries(
147
+ Object.entries(state.threadChangedFilesExpandedById).flatMap(([threadId, turns]) => {
148
+ const nextTurns = Object.fromEntries(
149
+ Object.entries(turns).filter(([, expanded]) => expanded === false),
150
+ );
151
+ return Object.keys(nextTurns).length > 0 ? [[threadId, nextTurns]] : [];
152
+ }),
153
+ );
154
window.localStorage.setItem(
155
PERSISTED_STATE_KEY,
156
JSON.stringify({
157
expandedProjectCwds,
158
projectOrderCwds,
159
+ threadChangedFilesExpandedById,
160
} satisfies PersistedUiState),
161
);
162
if (!legacyKeysCleanedUp) {
@@ -146,6 +192,23 @@ function projectOrdersEqual(left: readonly string[], right: readonly string[]):
192
);
193
}
194
195
+function nestedBooleanRecordsEqual(
196
+ left: Record<string, Record<string, boolean>>,
197
+ right: Record<string, Record<string, boolean>>,
198
+): boolean {
199
+ const leftEntries = Object.entries(left);
200
+ const rightEntries = Object.entries(right);
201
+ if (leftEntries.length !== rightEntries.length) {
202
+ return false;
203
+ }
204
+ for (const [key, value] of leftEntries) {
205
+ if (!(key in right) || !recordsEqual(value, right[key]!)) {
206
+ return false;
207
+ }
208
+ }
209
+ return true;
210
+}
211
+
212
export function syncProjects(state: UiState, projects: readonly SyncProjectInput[]): UiState {
213
const previousProjectCwdById = new Map(currentProjectCwdById);
214
const previousProjectIdByCwd = new Map(
@@ -260,12 +323,24 @@ export function syncThreads(state: UiState, threads: readonly SyncThreadInput[])
323
nextThreadLastVisitedAtById[thread.key] = thread.seedVisitedAt;
324
}
325
}
263
- if (recordsEqual(state.threadLastVisitedAtById, nextThreadLastVisitedAtById)) {
326
+ const nextThreadChangedFilesExpandedById = Object.fromEntries(
327
+ Object.entries(state.threadChangedFilesExpandedById).filter(([threadId]) =>
328
+ retainedThreadIds.has(threadId),
329
+ ),
330
+ );
331
+ if (
332
+ recordsEqual(state.threadLastVisitedAtById, nextThreadLastVisitedAtById) &&
333
+ nestedBooleanRecordsEqual(
334
+ state.threadChangedFilesExpandedById,
335
+ nextThreadChangedFilesExpandedById,
336
+ )
337
+ ) {
338
return state;
339
}
340
return {
341
...state,
342
threadLastVisitedAtById: nextThreadLastVisitedAtById,
343
+ threadChangedFilesExpandedById: nextThreadChangedFilesExpandedById,
344
};
345
}
346
@@ -316,14 +391,68 @@ export function markThreadUnread(
391
}
392
393
export function clearThreadUi(state: UiState, threadId: string): UiState {
319
- if (!(threadId in state.threadLastVisitedAtById)) {
394
+ const hasVisitedState = threadId in state.threadLastVisitedAtById;
395
+ const hasChangedFilesState = threadId in state.threadChangedFilesExpandedById;
396
+ if (!hasVisitedState && !hasChangedFilesState) {
397
return state;
398
}
399
const nextThreadLastVisitedAtById = { ...state.threadLastVisitedAtById };
400
+ const nextThreadChangedFilesExpandedById = { ...state.threadChangedFilesExpandedById };
401
delete nextThreadLastVisitedAtById[threadId];
402
+ delete nextThreadChangedFilesExpandedById[threadId];
403
return {
404
...state,
405
threadLastVisitedAtById: nextThreadLastVisitedAtById,
406
+ threadChangedFilesExpandedById: nextThreadChangedFilesExpandedById,
407
+ };
408
+}
409
+
410
+export function setThreadChangedFilesExpanded(
411
+ state: UiState,
412
+ threadId: string,
413
+ turnId: string,
414
+ expanded: boolean,
415
+): UiState {
416
+ const currentThreadState = state.threadChangedFilesExpandedById[threadId] ?? {};
417
+ const currentExpanded = currentThreadState[turnId] ?? true;
418
+ if (currentExpanded === expanded) {
419
+ return state;
420
+ }
421
+
422
+ if (expanded) {
423
+ if (!(turnId in currentThreadState)) {
424
+ return state;
425
+ }
426
+
427
+ const nextThreadState = { ...currentThreadState };
428
+ delete nextThreadState[turnId];
429
+ if (Object.keys(nextThreadState).length === 0) {
430
+ const nextState = { ...state.threadChangedFilesExpandedById };
431
+ delete nextState[threadId];
432
+ return {
433
+ ...state,
434
+ threadChangedFilesExpandedById: nextState,
435
+ };
436
+ }
437
+
438
+ return {
439
+ ...state,
440
+ threadChangedFilesExpandedById: {
441
+ ...state.threadChangedFilesExpandedById,
442
+ [threadId]: nextThreadState,
443
+ },
444
+ };
445
+ }
446
+
447
+ return {
448
+ ...state,
449
+ threadChangedFilesExpandedById: {
450
+ ...state.threadChangedFilesExpandedById,
451
+ [threadId]: {
452
+ ...currentThreadState,
453
+ [turnId]: false,
454
+ },
455
+ },
456
};
457
}
458
@@ -382,6 +511,7 @@ interface UiStateStore extends UiState {
511
markThreadVisited: (threadId: string, visitedAt?: string) => void;
512
markThreadUnread: (threadId: string, latestTurnCompletedAt: string | null | undefined) => void;
513
clearThreadUi: (threadId: string) => void;
514
+ setThreadChangedFilesExpanded: (threadId: string, turnId: string, expanded: boolean) => void;
515
toggleProject: (projectId: string) => void;
516
setProjectExpanded: (projectId: string, expanded: boolean) => void;
517
reorderProjects: (draggedProjectId: string, targetProjectId: string) => void;
@@ -396,6 +526,8 @@ export const useUiStateStore = create<UiStateStore>((set) => ({
526
markThreadUnread: (threadId, latestTurnCompletedAt) =>
527
set((state) => markThreadUnread(state, threadId, latestTurnCompletedAt)),
528
clearThreadUi: (threadId) => set((state) => clearThreadUi(state, threadId)),
529
+ setThreadChangedFilesExpanded: (threadId, turnId, expanded) =>
530
+ set((state) => setThreadChangedFilesExpanded(state, threadId, turnId, expanded)),
531
toggleProject: (projectId) => set((state) => toggleProject(state, projectId)),
532
setProjectExpanded: (projectId, expanded) =>
533
set((state) => setProjectExpanded(state, projectId, expanded)),