The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep the parent thread highlighted while viewing its subagent (#15163)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Oct 20, 2026 at 05:07 UTC
a7b5d52c789c64e8c814b3e532a4b194f8d2931d
3 files changed
+97
-16
apps/web/src/components/Sidebar.logic.test.ts
+41
@@ -23,6 +23,7 @@ import {
23
hasUnseenCompletion,
24
isContextMenuPointerDown,
25
isSidebarSubagentThread,
26
+ resolveSidebarRowThreadId,
27
isSidebarThreadWorking,
28
isTrailingDoubleClick,
29
orderItemsByPreferredIds,
@@ -461,6 +462,46 @@ describe("sidebar thread lineage helpers", () => {
462
expect(isSidebarSubagentThread(makeThreadFixture())).toBe(false);
463
});
464
465
+ it("maps an open subagent to its nearest visible ancestor's sidebar row", () => {
466
+ const environmentId = EnvironmentId.make("environment-row");
467
+ const otherEnvironmentId = EnvironmentId.make("environment-other");
468
+ const subagentOf = (id: string, parentId: ThreadId, environment = environmentId) =>
469
+ makeThreadFixture({
470
+ id: ThreadId.make(id),
471
+ environmentId: environment,
472
+ lineage: {
473
+ rootThreadId: parentId,
474
+ parentThreadId: parentId,
475
+ relationshipToParent: "subagent",
476
+ },
477
+ });
478
+ const root = makeThreadFixture({ id: ThreadId.make("thread-root"), environmentId });
479
+ const fork = makeThreadFixture({
480
+ id: ThreadId.make("thread-fork"),
481
+ environmentId,
482
+ lineage: {
483
+ rootThreadId: root.id,
484
+ parentThreadId: root.id,
485
+ relationshipToParent: "fork",
486
+ },
487
+ });
488
+ const child = subagentOf("thread-child", root.id);
489
+ const grandchild = subagentOf("thread-grandchild", child.id);
490
+ const forkChild = subagentOf("thread-fork-child", fork.id);
491
+ const orphan = subagentOf("thread-orphan", ThreadId.make("thread-missing"));
492
+ const elsewhere = subagentOf("thread-elsewhere", root.id, otherEnvironmentId);
493
+ const threads = [root, fork, child, grandchild, forkChild, orphan, elsewhere];
494
+
495
+ expect(resolveSidebarRowThreadId(child.id, environmentId, threads)).toBe(root.id);
496
+ expect(resolveSidebarRowThreadId(grandchild.id, environmentId, threads)).toBe(root.id);
497
+ expect(resolveSidebarRowThreadId(forkChild.id, environmentId, threads)).toBe(fork.id);
498
+ expect(resolveSidebarRowThreadId(elsewhere.id, otherEnvironmentId, threads)).toBe(elsewhere.id);
499
+ expect(resolveSidebarRowThreadId(orphan.id, environmentId, threads)).toBe(orphan.id);
500
+ const loopA = subagentOf("thread-loop-a", ThreadId.make("thread-loop-b"));
501
+ const loopB = subagentOf("thread-loop-b", loopA.id);
502
+ expect(resolveSidebarRowThreadId(loopA.id, environmentId, [loopA, loopB])).toBe(loopA.id);
503
+ });
504
+
505
it("resolves the parent thread for fork sidebar affordances", () => {
506
const parentId = ThreadId.make("thread-parent");
507
const fallbackParentId = ThreadId.make("thread-fallback-parent");
apps/web/src/components/Sidebar.logic.ts
+20
@@ -517,6 +517,26 @@ export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "line
517
return thread.lineage.relationshipToParent === "subagent";
518
}
519
520
+// Subagent threads have no sidebar row, so an open subagent is represented by
521
+// its nearest non-subagent ancestor. A broken chain (missing parent, cycle,
522
+// other environment) resolves to the thread itself, which then matches no row.
523
+export function resolveSidebarRowThreadId(
524
+ threadId: ThreadId,
525
+ environmentId: EnvironmentId,
526
+ threads: readonly Pick<SidebarThreadSummary, "id" | "environmentId" | "lineage">[],
527
+): ThreadId {
528
+ const findThread = (id: ThreadId) =>
529
+ threads.find((thread) => thread.id === id && thread.environmentId === environmentId);
530
+ const visited = new Set<ThreadId>();
531
+ let thread = findThread(threadId);
532
+ while (thread !== undefined && isSidebarSubagentThread(thread)) {
533
+ if (thread.lineage.parentThreadId === null || visited.has(thread.id)) return threadId;
534
+ visited.add(thread.id);
535
+ thread = findThread(thread.lineage.parentThreadId);
536
+ }
537
+ return thread?.id ?? threadId;
538
+}
539
+
540
export function filterSidebarV2VisibleThreads<
541
T extends Pick<SidebarThreadSummary, "archivedAt" | "lineage"> & {
542
environmentId: string;
apps/web/src/components/Sidebar.tsx
+36
-16
@@ -231,6 +231,7 @@ import {
231
type SidebarListItem,
232
type SidebarListMarker,
233
type SidebarSection,
234
+ resolveSidebarRowThreadId,
235
} from "./Sidebar.logic";
236
import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";
237
import {
@@ -449,11 +450,24 @@ function useSidebarThreads(input: {
450
readonly scopedProjectKeys: ReadonlySet<string> | null;
451
readonly serverConfigs: ReadonlyMap<EnvironmentId, EnvironmentServerConfig>;
452
readonly optimisticDrop: SidebarOptimisticDrop | null;
452
- readonly routeThreadKey: string | null;
453
+ readonly routeThreadRef: ScopedThreadRef | null;
454
}) {
454
- const { projectScopeKey, scopedProjectKeys, serverConfigs, optimisticDrop, routeThreadKey } =
455
+ const { projectScopeKey, scopedProjectKeys, serverConfigs, optimisticDrop, routeThreadRef } =
456
input;
457
const threads = useThreadShells();
458
+ const routeRowThreadKey =
459
+ routeThreadRef === null
460
+ ? null
461
+ : scopedThreadKey(
462
+ scopeThreadRef(
463
+ routeThreadRef.environmentId,
464
+ resolveSidebarRowThreadId(
465
+ routeThreadRef.threadId,
466
+ routeThreadRef.environmentId,
467
+ threads,
468
+ ),
469
+ ),
470
+ );
471
const workingShelfEnabled = useClientSettings((s) => s.sidebarWorkingShelfEnabled);
472
const nowMinute = useNowMinute();
473
// Snooze wake times are second-precise, so classifying with the quantized
@@ -506,23 +520,23 @@ function useSidebarThreads(input: {
520
const visibleSettledThreads = (() => {
521
if (settledThreads.length <= settledVisibleCount) return settledThreads;
522
const visible = settledThreads.slice(0, settledVisibleCount);
509
- if (routeThreadKey !== null) {
523
+ if (routeRowThreadKey !== null) {
524
const routeThread = settledThreads
525
.slice(settledVisibleCount)
512
- .find((thread) => threadShellKey(thread) === routeThreadKey);
526
+ .find((thread) => threadShellKey(thread) === routeRowThreadKey);
527
if (routeThread !== undefined) visible.push(routeThread);
528
}
529
return visible;
530
})();
531
const renderedSettledThreads = settledShelfExpanded
532
? visibleSettledThreads
519
- : routeThreadOnly(visibleSettledThreads, routeThreadKey);
533
+ : routeThreadOnly(visibleSettledThreads, routeRowThreadKey);
534
const visibleSnoozedThreads = snoozedShelfExpanded
535
? snoozedThreads
522
- : routeThreadOnly(snoozedThreads, routeThreadKey);
536
+ : routeThreadOnly(snoozedThreads, routeRowThreadKey);
537
const visibleWorkingThreads = workingShelfExpanded
538
? workingThreads
525
- : routeThreadOnly(workingThreads, routeThreadKey);
539
+ : routeThreadOnly(workingThreads, routeRowThreadKey);
540
const orderedThreads = [
541
...pinnedThreads,
542
...activeThreads,
@@ -541,6 +555,7 @@ function useSidebarThreads(input: {
555
for (const thread of list) sectionByThreadKey.set(threadShellKey(thread), section);
556
}
557
return {
558
+ routeRowThreadKey,
559
...partition,
560
threads,
561
workingShelfEnabled,
@@ -1542,6 +1557,9 @@ type SidebarThreadRowProps = {
1557
snoozeWakeLabelText: string | null;
1558
wokeAt: string | null;
1559
isActive: boolean;
1560
+ // Unlike isActive, never true for the ancestor standing in for an open
1561
+ // subagent: drafts and PR clicks care about which composer is on screen.
1562
+ isRouteThread: boolean;
1563
openPullRequestsInRightPanel: boolean;
1564
jumpLabel: string | null;
1565
currentEnvironmentId: string | null;
@@ -1617,7 +1635,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
1635
});
1636
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
1637
const terminalProcessCount = runningTerminalIds.length;
1620
- const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isActive;
1638
+ const hasUnsentDraft = useThreadHasUnsentDraft(threadRef) && !props.isRouteThread;
1639
const handleDiscardDraftClick = (event: ReactMouseEvent) => {
1640
event.preventDefault();
1641
event.stopPropagation();
@@ -1895,7 +1913,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
1913
if (!url) return;
1914
const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
1915
const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
1898
- if (openedInRightPanel && showInRightPanel && !props.isActive) {
1916
+ if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
1917
onThreadActivate(threadRef);
1918
}
1919
};
@@ -2013,7 +2031,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
2031
: null;
2032
const handlePrListClick = () => {
2033
useRightPanelStore.getState().open(threadRef, "pull-requests");
2016
- if (!props.isActive) onThreadActivate(threadRef);
2034
+ if (!props.isRouteThread) onThreadActivate(threadRef);
2035
};
2036
const prBadge =
2037
prBadgeShape?.kind === "stack" || pr || currentLinkedPr ? (
@@ -2999,12 +3017,13 @@ export default function Sidebar() {
3017
activeKeys,
3018
pinnedKeysById,
3019
activeKeysById,
3020
+ routeRowThreadKey,
3021
} = useSidebarThreads({
3022
projectScopeKey,
3023
scopedProjectKeys,
3024
serverConfigs,
3025
optimisticDrop,
3007
- routeThreadKey,
3026
+ routeThreadRef,
3027
});
3028
3029
const isSearchingThreads = threadSearchQuery.trim().length > 0;
@@ -3637,7 +3656,7 @@ export default function Sidebar() {
3656
...(draggedActiveOrder === undefined ? {} : { activeOrder: draggedActiveOrder }),
3657
settledExpanded: settledShelfExpanded,
3658
settledVisibleCount,
3640
- routeThreadKey,
3659
+ routeThreadKey: routeRowThreadKey,
3660
snoozedThreadCount: snoozedThreads.length,
3661
});
3662
const draggedThreadKey = dragState?.activeKey;
@@ -4472,7 +4491,7 @@ export default function Sidebar() {
4491
navigateToThreadKey(
4492
resolveAdjacentThreadId({
4493
threadIds: orderedThreadKeys,
4475
- currentThreadId: routeThreadKey,
4494
+ currentThreadId: routeRowThreadKey,
4495
direction: traversalDirection,
4496
}),
4497
);
@@ -4488,8 +4507,8 @@ export default function Sidebar() {
4507
keybindings,
4508
navigateToThread,
4509
orderedThreadKeys,
4510
+ routeRowThreadKey,
4511
routeTerminalOpen,
4492
- routeThreadKey,
4512
threadByKey,
4513
]);
4514
@@ -4727,7 +4746,7 @@ export default function Sidebar() {
4746
EMPTY_PROVIDER_ENTRIES
4747
}
4748
isHighlighted={activeSearchResultIndex === index}
4730
- isRouteActive={routeThreadKey === threadKey}
4749
+ isRouteActive={routeRowThreadKey === threadKey}
4750
resultId={`sidebar-thread-search-result-${index}`}
4751
searchMatch={
4752
threadSearchMatchByKey.get(
@@ -4848,7 +4867,8 @@ export default function Sidebar() {
4867
: null
4868
}
4869
wokeAt={threadWokeAt(thread, { now: snoozeNow })}
4851
- isActive={routeThreadKey === threadKey}
4870
+ isActive={routeRowThreadKey === threadKey}
4871
+ isRouteThread={routeThreadKey === threadKey}
4872
openPullRequestsInRightPanel={routeThreadRef !== null}
4873
jumpLabel={
4874
showJumpHints ? (jumpLabelByKey.get(threadKey) ?? null) : null