The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
feat(web): drop folders on the sidebar to add them as projects (#35202)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Nov 12, 2026 at 03:38 UTC
f419698aeaf78fb0c3299b4599f118d2d66ef694
5 files changed
+246
-86
apps/web/src/components/Sidebar.tsx
+3
-2
@@ -101,6 +101,7 @@ import { isMacPlatform } from "~/lib/utils";
101
import { readLocalApi } from "../localApi";
102
import { configuredHostedAppUrl } from "../hostedPairing";
103
import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
104
+import { SidebarFolderDrop } from "./sidebar/SidebarFolderDrop";
105
import {
106
pickableProjectGroups,
107
selectProjectGroupingSettings,
@@ -2968,7 +2969,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2969
: undefined);
2970
const newThreadInProjectShortcutLabel = shortcutLabelForCommand(keybindings, "chat.newLocal");
2971
return (
2971
- <>
2972
+ <SidebarFolderDrop>
2973
<SidebarChromeHeader isElectron={isElectron} />
2974
<SidebarContent
2975
ref={sidebarContentRef}
@@ -3654,6 +3655,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
3655
</SidebarGroup>
3656
</SidebarContent>
3657
<SidebarChromeFooter />
3657
- </>
3658
+ </SidebarFolderDrop>
3659
);
3660
}
apps/web/src/components/desktop/DesktopAppActivationCoordinator.tsx
+4
-84
@@ -1,96 +1,16 @@
1
-import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
1
import type { DesktopAppActivationRequest } from "@t3tools/contracts";
2
import { useEffect, useEffectEvent, useRef } from "react";
3
5
-import { handleDesktopAppActivationRequest } from "../../desktopAppActivation";
6
-import { useNewThreadHandler } from "../../hooks/useHandleNewThread";
7
-import {
8
- findProjectByPath,
9
- inferProjectTitleFromPath,
10
-} from "@t3tools/client-runtime/state/projects";
11
-import { newProjectId } from "../../lib/utils";
12
-import { readProjects, waitForProject } from "../../state/entities";
13
-import { usePrimaryEnvironment } from "../../state/environments";
14
-import { projectEnvironment } from "../../state/projects";
15
-import { useEnvironmentShellHasSnapshot } from "../../state/shell";
16
-import { useAtomCommand } from "../../state/use-atom-command";
17
-import { useOrchestrationCommand } from "../../state/use-orchestration-command";
18
-import { reportProjectFailure } from "../../hooks/useProjectGroupUpdate";
4
+import { useOpenLocalWorkspace } from "../../hooks/useOpenLocalWorkspace";
5
6
export function DesktopAppActivationCoordinator() {
21
- const primaryEnvironment = usePrimaryEnvironment();
22
- const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
23
- const updateProject = useOrchestrationCommand(projectEnvironment.update, {
24
- label: "project unarchive",
25
- });
26
- const openThread = useNewThreadHandler();
7
+ const openLocalWorkspace = useOpenLocalWorkspace();
8
const queueRef = useRef(Promise.resolve());
9
const activation = window.desktopBridge?.appActivation;
29
- const shellHasSnapshot = useEnvironmentShellHasSnapshot(
30
- primaryEnvironment?.environmentId ?? null,
31
- );
32
- const ready =
33
- activation !== undefined &&
34
- primaryEnvironment?.connection.phase === "connected" &&
35
- primaryEnvironment.serverConfig !== null &&
36
- shellHasSnapshot;
10
+ const ready = activation !== undefined && openLocalWorkspace.ready;
11
12
const processRequest = useEffectEvent(async (request: DesktopAppActivationRequest) =>
39
- handleDesktopAppActivationRequest(request, {
40
- getTarget: () => {
41
- if (
42
- primaryEnvironment?.connection.phase !== "connected" ||
43
- primaryEnvironment.serverConfig === null
44
- ) {
45
- return null;
46
- }
47
- return {
48
- environmentId: primaryEnvironment.environmentId,
49
- platform: primaryEnvironment.serverConfig.environment.platform.os,
50
- };
51
- },
52
- findProject: (environmentId, workspaceRoot) =>
53
- findProjectByPath(
54
- readProjects().filter((project) => project.environmentId === environmentId),
55
- workspaceRoot,
56
- ) ?? null,
57
- createProject: async (environmentId, workspaceRoot) => {
58
- const projectId = newProjectId();
59
- const result = await createProject({
60
- environmentId,
61
- input: {
62
- projectId,
63
- title: inferProjectTitleFromPath(workspaceRoot),
64
- workspaceRoot,
65
- createWorkspaceRootIfMissing: false,
66
- defaultModelSelection: null,
67
- },
68
- });
69
- if (result._tag === "Failure") {
70
- const error = squashAtomCommandFailure(result);
71
- throw error instanceof Error ? error : new Error("T3 Code could not add the project.");
72
- }
73
- return projectId;
74
- },
75
- waitForProject: async (projectRef) => {
76
- await waitForProject(projectRef);
77
- },
78
- openThread: (projectRef) => {
79
- const project = readProjects().find(
80
- (candidate) =>
81
- candidate.environmentId === projectRef.environmentId &&
82
- candidate.id === projectRef.projectId,
83
- );
84
- // Opening an archived project's folder again brings the project back.
85
- if (project?.archivedAt != null) {
86
- void updateProject({
87
- environmentId: projectRef.environmentId,
88
- input: { projectId: projectRef.projectId, archived: false },
89
- }).then((result) => reportProjectFailure("Failed to unarchive project", result));
90
- }
91
- return openThread(projectRef);
92
- },
93
- }),
13
+ openLocalWorkspace.open(request),
14
);
15
16
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to desktop activation requests over the bridge and marks the renderer ready
apps/web/src/components/sidebar/SidebarFolderDrop.tsx
new
+134
@@ -0,0 +1,134 @@
1
+import {
2
+ DESKTOP_APP_ACTIVATION_PROTOCOL_VERSION,
3
+ DesktopAppActivationPlatform,
4
+} from "@t3tools/contracts";
5
+import * as Schema from "effect/Schema";
6
+import { FolderPlusIcon } from "lucide-react";
7
+import { useState, type DragEvent, type ReactNode } from "react";
8
+
9
+import { useOpenLocalWorkspace } from "../../hooks/useOpenLocalWorkspace";
10
+import { randomUUID } from "../../lib/utils";
11
+import { resolveDroppedFolderPath } from "../chat/folderDrop";
12
+import { splitTransferredFiles } from "../chat/workspaceFileDrop";
13
+import { setFileDragActive } from "../Sidebar.logic";
14
+import { toastManager } from "../ui/toast";
15
+import { stackedThreadToast } from "../ui/toastHelpers";
16
+
17
+const isActivationPlatform = Schema.is(DesktopAppActivationPlatform);
18
+
19
+function isFileDrag(event: DragEvent) {
20
+ return event.dataTransfer.types.includes("Files");
21
+}
22
+
23
+/**
24
+ * Folders dropped from the OS file manager open as projects, like `t3 <dir>`.
25
+ * Thread rows take file drops for themselves by calling preventDefault first;
26
+ * this zone then stays hidden and only picks up folders from the drop.
27
+ * Browsers expose no absolute paths, so only the desktop app can add them.
28
+ */
29
+export function SidebarFolderDrop(props: { children: ReactNode }) {
30
+ const [isActive, setIsActive] = useState(false);
31
+ const openLocalWorkspace = useOpenLocalWorkspace();
32
+ const bridge = window.desktopBridge;
33
+ const setActive = (active: boolean) => setFileDragActive(setIsActive, active);
34
+
35
+ const addFolders = async (folders: File[]) => {
36
+ if (bridge === undefined) {
37
+ toastManager.add(
38
+ stackedThreadToast({
39
+ type: "info",
40
+ title: "Dropping folders needs the desktop app",
41
+ description: "Browsers do not share folder paths. Use Add project to choose a folder.",
42
+ }),
43
+ );
44
+ return;
45
+ }
46
+ const platform = bridge.getClientPlatform();
47
+ if (!openLocalWorkspace.ready || !isActivationPlatform(platform)) {
48
+ toastManager.add(
49
+ stackedThreadToast({
50
+ type: "error",
51
+ title: "This computer's server is not connected yet",
52
+ description: "Try again when it connects.",
53
+ }),
54
+ );
55
+ return;
56
+ }
57
+ // One at a time, so the last folder is the one left open.
58
+ for (const folder of folders) {
59
+ const workspaceRoot = resolveDroppedFolderPath(folder, bridge.getPathForFile);
60
+ const response =
61
+ workspaceRoot === null
62
+ ? null
63
+ : await openLocalWorkspace.open({
64
+ version: DESKTOP_APP_ACTIVATION_PROTOCOL_VERSION,
65
+ requestId: randomUUID(),
66
+ type: "open-workspace",
67
+ workspaceRoot,
68
+ platform,
69
+ });
70
+ if (response?.ok) continue;
71
+ toastManager.add(
72
+ stackedThreadToast({
73
+ type: "error",
74
+ title: `Could not add "${folder.name}"`,
75
+ description: response?.message ?? "T3 Code could not read the folder's path.",
76
+ }),
77
+ );
78
+ }
79
+ };
80
+
81
+ const onDragOver = (event: DragEvent) => {
82
+ if (!isFileDrag(event)) return;
83
+ if (event.defaultPrevented) {
84
+ setActive(false);
85
+ return;
86
+ }
87
+ event.preventDefault();
88
+ event.dataTransfer.dropEffect = "copy";
89
+ setActive(true);
90
+ };
91
+
92
+ return (
93
+ <div
94
+ className="relative flex min-h-0 flex-1 flex-col"
95
+ onDragEnter={onDragOver}
96
+ onDragOver={onDragOver}
97
+ onDragLeave={(event) => {
98
+ if (!isFileDrag(event)) return;
99
+ if (event.currentTarget.contains(event.relatedTarget as Node | null)) return;
100
+ setActive(false);
101
+ }}
102
+ onDrop={(event) => {
103
+ if (!isFileDrag(event)) return;
104
+ const claimedByRow = event.defaultPrevented;
105
+ event.preventDefault();
106
+ setActive(false);
107
+ const { files, folders } = splitTransferredFiles(event.dataTransfer);
108
+ if (folders.length > 0) void addFolders(folders);
109
+ if (files.length > 0 && !claimedByRow) {
110
+ toastManager.add(
111
+ stackedThreadToast({
112
+ type: "info",
113
+ title: "Only folders can be added as projects",
114
+ description: "Drop files on a thread to attach them.",
115
+ }),
116
+ );
117
+ }
118
+ }}
119
+ >
120
+ {props.children}
121
+ {isActive ? (
122
+ <div
123
+ aria-hidden
124
+ className="pointer-events-none absolute inset-1.5 z-30 flex flex-col items-center justify-center gap-2 rounded-lg px-4 text-center bg-sidebar/90 text-sm text-sidebar-foreground ring-1 ring-inset ring-primary/70"
125
+ >
126
+ <FolderPlusIcon className="size-5 text-sidebar-muted-foreground" />
127
+ {bridge === undefined
128
+ ? "Dropping folders needs the desktop app"
129
+ : "Drop folders to add projects"}
130
+ </div>
131
+ ) : null}
132
+ </div>
133
+ );
134
+}
apps/web/src/hooks/useOpenLocalWorkspace.ts
new
+98
@@ -0,0 +1,98 @@
1
+import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
2
+import {
3
+ findProjectByPath,
4
+ inferProjectTitleFromPath,
5
+} from "@t3tools/client-runtime/state/projects";
6
+import type { DesktopAppActivationRequest } from "@t3tools/contracts";
7
+
8
+import { handleDesktopAppActivationRequest } from "../desktopAppActivation";
9
+import { newProjectId } from "../lib/utils";
10
+import { readProjects, waitForProject } from "../state/entities";
11
+import { usePrimaryEnvironment } from "../state/environments";
12
+import { projectEnvironment } from "../state/projects";
13
+import { useEnvironmentShellHasSnapshot } from "../state/shell";
14
+import { useAtomCommand } from "../state/use-atom-command";
15
+import { useOrchestrationCommand } from "../state/use-orchestration-command";
16
+import { reportProjectFailure } from "./useProjectGroupUpdate";
17
+import { useNewThreadHandler } from "./useHandleNewThread";
18
+
19
+/**
20
+ * Opens a folder on this computer as a project in the primary environment: an
21
+ * existing project opens (and unarchives), a new one is added. Used by `t3 <dir>`
22
+ * activations and folders dropped on the sidebar. `ready` is false until the
23
+ * primary environment's projects have loaded, so a known folder is not added twice.
24
+ */
25
+export function useOpenLocalWorkspace() {
26
+ const primaryEnvironment = usePrimaryEnvironment();
27
+ const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
28
+ const updateProject = useOrchestrationCommand(projectEnvironment.update, {
29
+ label: "project unarchive",
30
+ });
31
+ const openThread = useNewThreadHandler();
32
+ const shellHasSnapshot = useEnvironmentShellHasSnapshot(
33
+ primaryEnvironment?.environmentId ?? null,
34
+ );
35
+ const ready =
36
+ primaryEnvironment?.connection.phase === "connected" &&
37
+ primaryEnvironment.serverConfig !== null &&
38
+ shellHasSnapshot;
39
+
40
+ const open = (request: DesktopAppActivationRequest) =>
41
+ handleDesktopAppActivationRequest(request, {
42
+ getTarget: () => {
43
+ if (
44
+ primaryEnvironment?.connection.phase !== "connected" ||
45
+ primaryEnvironment.serverConfig === null
46
+ ) {
47
+ return null;
48
+ }
49
+ return {
50
+ environmentId: primaryEnvironment.environmentId,
51
+ platform: primaryEnvironment.serverConfig.environment.platform.os,
52
+ };
53
+ },
54
+ findProject: (environmentId, workspaceRoot) =>
55
+ findProjectByPath(
56
+ readProjects().filter((project) => project.environmentId === environmentId),
57
+ workspaceRoot,
58
+ ) ?? null,
59
+ createProject: async (environmentId, workspaceRoot) => {
60
+ const projectId = newProjectId();
61
+ const result = await createProject({
62
+ environmentId,
63
+ input: {
64
+ projectId,
65
+ title: inferProjectTitleFromPath(workspaceRoot),
66
+ workspaceRoot,
67
+ createWorkspaceRootIfMissing: false,
68
+ defaultModelSelection: null,
69
+ },
70
+ });
71
+ if (result._tag === "Failure") {
72
+ const error = squashAtomCommandFailure(result);
73
+ throw error instanceof Error ? error : new Error("T3 Code could not add the project.");
74
+ }
75
+ return projectId;
76
+ },
77
+ waitForProject: async (projectRef) => {
78
+ await waitForProject(projectRef);
79
+ },
80
+ openThread: (projectRef) => {
81
+ const project = readProjects().find(
82
+ (candidate) =>
83
+ candidate.environmentId === projectRef.environmentId &&
84
+ candidate.id === projectRef.projectId,
85
+ );
86
+ // Opening an archived project's folder again brings the project back.
87
+ if (project?.archivedAt != null) {
88
+ void updateProject({
89
+ environmentId: projectRef.environmentId,
90
+ input: { projectId: projectRef.projectId, archived: false },
91
+ }).then((result) => reportProjectFailure("Failed to unarchive project", result));
92
+ }
93
+ return openThread(projectRef);
94
+ },
95
+ });
96
+
97
+ return { ready, open };
98
+}
docs/user/install.md
+7
@@ -159,6 +159,13 @@ Pass a path, such as `t3 app ../my-project`, to open another directory. It requi
159
the desktop app, so a standalone server or an SSH session is not enough. If the
160
command cannot reach the app, start or update the desktop app and try again.
161
162
+### Drop a folder on the sidebar
163
+
164
+Drag one or more folders from Finder, Explorer, or your file manager onto the
165
+sidebar. Each one opens as a project on this computer, the same as `t3 app`.
166
+Files dropped on a thread still attach to that thread. Browsers do not share
167
+folder paths, so in the web app use **Add project** instead.
168
+
169
## Mobile app
170
171
Install T3 Code from the