The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): Back from a subagent thread returns to its parent on Android (#21033)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
voida6 committed
Oct 20, 2026 at 16:06 UTC
c5f536cc0c7a0c5dd411cc3b68ca513459506b97
6 files changed
+151
-19
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+17
-8
@@ -8,7 +8,7 @@ import {
8
useThreadShell,
9
} from "../../state/entities";
10
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
11
-import { useNavigation } from "@react-navigation/native";
11
+import { StackActions, useNavigation } from "@react-navigation/native";
12
import type { WorktreeSetupCardProps } from "./worktree-setup-card";
13
import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
14
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
@@ -109,6 +109,7 @@ import { ThreadBrowserFloat } from "../browser/ThreadBrowserFloat";
109
import { useThreadServerBrowserTabs } from "../../state/preview";
110
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
111
import { scopedThreadKey } from "../../lib/scopedEntities";
112
+import { parentThreadIsBelow } from "../../lib/android-workspace-navigation";
113
import {
114
clearThreadComposerError,
115
threadComposerErrorsAtom,
@@ -552,10 +553,12 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
553
accessibilityLabel: `Open ${childInput.hasPendingApprovals ? "approval" : "question"} from ${childInput.title}`,
554
onPress: () => {
555
Keyboard.dismiss();
555
- navigation.navigate("Thread", {
556
- environmentId: props.environmentId,
557
- threadId: childInput.id,
558
- });
556
+ navigation.dispatch(
557
+ StackActions.push("Thread", {
558
+ environmentId: props.environmentId,
559
+ threadId: childInput.id,
560
+ }),
561
+ );
562
},
563
};
564
}
@@ -1379,11 +1382,17 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
1382
onOpenParent={
1383
props.selectedThread.lineage.parentThreadId === null
1384
? null
1382
- : () =>
1383
- navigation.navigate("Thread", {
1385
+ : () => {
1386
+ const parent = {
1387
environmentId: String(props.environmentId),
1388
threadId: String(props.selectedThread.lineage.parentThreadId),
1386
- })
1389
+ };
1390
+ navigation.dispatch((state) =>
1391
+ parentThreadIsBelow(state, parent)
1392
+ ? StackActions.pop()
1393
+ : StackActions.push("Thread", parent),
1394
+ );
1395
+ }
1396
}
1397
/>
1398
</View>
apps/mobile/src/features/threads/ThreadHeader.tsx
+3
-3
@@ -5,7 +5,7 @@ import type { AppBarAction } from "../../components/ui/AppBar.types";
5
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
6
import type { ThreadInspectorMode } from "./thread-inspector-content-stack";
7
import { useThreadHeaderOptions } from "./useThreadHeaderOptions";
8
-import { useWorkspaceListNavigation } from "../workspace/useAndroidWorkspaceNavigation";
8
+import { useWorkspaceBackNavigation } from "../workspace/useAndroidWorkspaceNavigation";
9
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
10
11
export function ThreadHeader(
@@ -19,7 +19,7 @@ export function ThreadHeader(
19
readonly onOpenFilesInspector: () => void;
20
},
21
) {
22
- const returnToList = useWorkspaceListNavigation("threads");
22
+ const goBack = useWorkspaceBackNavigation("threads");
23
const { layout, panes, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
24
const { onOpenTerminal, onMergeBack } = props.gitControls;
25
const native = useThreadHeaderOptions(props);
@@ -97,7 +97,7 @@ export function ThreadHeader(
97
/>
98
) : null
99
}
100
- onBack={layout.usesSplitView ? undefined : returnToList}
100
+ onBack={layout.usesSplitView ? undefined : goBack}
101
actions={androidHeaderActions}
102
hideBottomBorder
103
/>
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+3
-3
@@ -92,7 +92,7 @@ import { useThreadPromptLink } from "../prompt-links/useThreadPromptLink";
92
import { ThreadHeader } from "./ThreadHeader";
93
import {
94
useAndroidWorkspaceBack,
95
- useWorkspaceListNavigation,
95
+ useWorkspaceBackNavigation,
96
} from "../workspace/useAndroidWorkspaceNavigation";
97
98
interface ThreadInspectorSelection {
@@ -119,7 +119,7 @@ function ThreadPane(props: { readonly children: ReactNode }) {
119
}
120
121
function ThreadRouteFallbackLayout(props: { readonly children: ReactNode }) {
122
- const returnToList = useWorkspaceListNavigation("threads");
122
+ const goBack = useWorkspaceBackNavigation("threads");
123
const { layout } = useAdaptiveWorkspaceLayout();
124
const { themeVariables } = useAppearancePreferences();
125
if (Platform.OS !== "android") return props.children;
@@ -129,7 +129,7 @@ function ThreadRouteFallbackLayout(props: { readonly children: ReactNode }) {
129
<AppBar
130
title="Thread"
131
options={{ contentStyle: { backgroundColor: themeVariables["--color-header"] } }}
132
- onBack={layout.usesSplitView ? undefined : returnToList}
132
+ onBack={layout.usesSplitView ? undefined : goBack}
133
hideBottomBorder
134
/>
135
<ThreadPane>{props.children}</ThreadPane>
apps/mobile/src/features/workspace/useAndroidWorkspaceNavigation.ts
+19
-5
@@ -1,7 +1,10 @@
1
import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
2
import { useCallback } from "react";
3
import { BackHandler, Keyboard, Platform } from "react-native";
4
-import { resetAndroidWorkspace } from "../../lib/android-workspace-navigation";
4
+import {
5
+ resetAndroidWorkspace,
6
+ returnToAndroidWorkspaceList,
7
+} from "../../lib/android-workspace-navigation";
8
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
9
import type { WorkspaceTab } from "./workspace-tabs-state";
10
@@ -17,20 +20,31 @@ export function useWorkspaceListNavigation(tab: WorkspaceTab) {
20
}, [navigation, dispatch, tab]);
21
}
22
20
-export function useAndroidWorkspaceBack(tab: WorkspaceTab) {
23
+export function useWorkspaceBackNavigation(tab: WorkspaceTab) {
24
+ const navigation = useNavigation();
25
const dispatch = useWorkspaceTabs()?.dispatch;
26
const returnToList = useWorkspaceListNavigation(tab);
27
+ return useCallback(() => {
28
+ if (Platform.OS === "android") {
29
+ returnToAndroidWorkspaceList(navigation, () => dispatch?.({ type: "select", tab }));
30
+ } else returnToList();
31
+ }, [navigation, dispatch, tab, returnToList]);
32
+}
33
+
34
+export function useAndroidWorkspaceBack(tab: WorkspaceTab) {
35
+ const dispatch = useWorkspaceTabs()?.dispatch;
36
+ const goBack = useWorkspaceBackNavigation(tab);
37
useFocusEffect(
38
useCallback(() => {
39
if (Platform.OS !== "android") return;
40
dispatch?.({ type: "select", tab });
41
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
42
if (Keyboard.isVisible()) Keyboard.dismiss();
29
- else returnToList();
43
+ else goBack();
44
return true;
45
});
46
return () => subscription.remove();
33
- }, [returnToList, dispatch, tab]),
47
+ }, [goBack, dispatch, tab]),
48
);
35
- return returnToList;
49
+ return goBack;
50
}
apps/mobile/src/lib/android-workspace-navigation.test.ts
+75
@@ -7,7 +7,9 @@ import {
7
} from "../features/workspace/android-workspace-tabs";
8
import {
9
androidWorkspaceNavigationState,
10
+ parentThreadIsBelow,
11
resetAndroidWorkspace,
12
+ returnToAndroidWorkspaceList,
13
type AndroidWorkspaceDestination,
14
type AndroidWorkspaceResetAction,
15
} from "./android-workspace-navigation";
@@ -183,6 +185,79 @@ describe("Android workspace navigation", () => {
185
expect(state.routes[1]?.key).not.toBe(previous.routes[1]?.key);
186
});
187
188
+ it("returns to a distinct previous thread, otherwise to the workspace list", () => {
189
+ const parent = select(router.getInitialState(options), thread);
190
+ let state = apply(
191
+ parent,
192
+ StackActions.push("Thread", { ...thread.params, threadId: "child-a" }),
193
+ );
194
+ let listSelected = false;
195
+ const navigation = {
196
+ dispatch: (action: AndroidWorkspaceResetAction) => {
197
+ state = apply(state, action);
198
+ },
199
+ getParent: () => undefined,
200
+ getState: () => state,
201
+ goBack: () => {
202
+ state = apply(state, StackActions.pop());
203
+ },
204
+ };
205
+ const back = () =>
206
+ returnToAndroidWorkspaceList(navigation, () => {
207
+ listSelected = true;
208
+ });
209
+
210
+ back();
211
+ expect(state.routes).toEqual(parent.routes);
212
+ expect(state.index).toBe(parent.index);
213
+ expect(listSelected).toBe(false);
214
+
215
+ back();
216
+ expect(state.routes).toEqual([parent.routes[0]]);
217
+ expect(state.index).toBe(0);
218
+ expect(listSelected).toBe(true);
219
+
220
+ state = apply(
221
+ parent,
222
+ StackActions.push("Thread", { ...thread.params, environmentId: "environment-b" }),
223
+ );
224
+ listSelected = false;
225
+ back();
226
+ expect(state.routes).toEqual(parent.routes);
227
+ expect(state.index).toBe(parent.index);
228
+ expect(listSelected).toBe(false);
229
+
230
+ // Confirming a Git action from the inline inspector can duplicate the current thread.
231
+ state = apply(parent, StackActions.push("Thread", thread.params));
232
+ back();
233
+ expect({ routes: names(state), index: state.index, listSelected }).toEqual({
234
+ routes: ["Home"],
235
+ index: 0,
236
+ listSelected: true,
237
+ });
238
+ });
239
+
240
+ it("recognizes a parent only when its environment and thread are immediately below", () => {
241
+ const parent = select(router.getInitialState(options), thread);
242
+ const child = apply(
243
+ parent,
244
+ StackActions.push("Thread", { ...thread.params, threadId: "child-a" }),
245
+ );
246
+
247
+ expect(parentThreadIsBelow(child, thread.params)).toBe(true);
248
+ expect(parentThreadIsBelow(child, { ...thread.params, environmentId: "environment-b" })).toBe(
249
+ false,
250
+ );
251
+ expect(parentThreadIsBelow(child, { ...thread.params, threadId: "other" })).toBe(false);
252
+ expect(parentThreadIsBelow(parent, thread.params)).toBe(false);
253
+ expect(
254
+ parentThreadIsBelow(
255
+ apply(child, StackActions.push("Thread", { ...thread.params, threadId: "grandchild-a" })),
256
+ thread.params,
257
+ ),
258
+ ).toBe(false);
259
+ });
260
+
261
it("drops stale detail history on a tab switch while retaining Home", () => {
262
const previous = legacyHistory();
263
const state = select(previous);
apps/mobile/src/lib/android-workspace-navigation.ts
+34
@@ -16,6 +16,17 @@ interface WorkspaceNavigation {
16
readonly getRootState?: () => NavigationState | undefined;
17
}
18
19
+function androidWorkspaceBackReturnsToThread(state: NavigationState) {
20
+ const current = state.routes[state.index];
21
+ const params = current?.params as ReactNavigation.RootParamList["Thread"] | undefined;
22
+ return (
23
+ current?.name === "Thread" &&
24
+ state.routes[state.index - 1]?.name === "Thread" &&
25
+ params !== undefined &&
26
+ !parentThreadIsBelow(state, params)
27
+ );
28
+}
29
+
30
export function androidWorkspaceNavigationState(
31
state: NavigationState,
32
destination?: AndroidWorkspaceDestination,
@@ -67,6 +78,29 @@ export function resetAndroidWorkspace(
78
});
79
}
80
81
+export function parentThreadIsBelow(
82
+ state: NavigationState,
83
+ parent: ReactNavigation.RootParamList["Thread"],
84
+) {
85
+ const previous = state.routes[state.index - 1];
86
+ const params = previous?.params as ReactNavigation.RootParamList["Thread"] | undefined;
87
+ return (
88
+ previous?.name === "Thread" &&
89
+ params?.environmentId === parent.environmentId &&
90
+ params.threadId === parent.threadId
91
+ );
92
+}
93
+
94
+export function returnToAndroidWorkspaceList(
95
+ navigation: WorkspaceNavigation & { readonly goBack: () => void },
96
+ selectTab: () => void,
97
+) {
98
+ const state = navigation.getState();
99
+ if (state && androidWorkspaceBackReturnsToThread(state)) return navigation.goBack();
100
+ selectTab();
101
+ resetAndroidWorkspace(navigation);
102
+}
103
+
104
// In the split view these destinations swap the detail pane beside the sidebar instead of
105
// stacking over Home, so the default slide-in would show a layer that is not there.
106
export function androidWorkspaceDestinationAnimation(routeName: string, usesSplitView: boolean) {