The best way to control Claude Code, Codex and more from any computer or phone
fix(clients): copy filesystem paths with native separators (#19201)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
TONY JOSEPH SEBASTIAN committed
Oct 20, 2026 at 02:08 UTC
f57cfe1175371ac6750311ca08a46db0b3f740bd
14 files changed
+239
-22
apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
+9
-1
@@ -1,3 +1,5 @@
1
+import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2
+import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
3
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
4
import { environmentSession } from "../../state/session";
5
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -783,7 +785,13 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
785
title: "Copy path",
786
icon: "doc.on.doc",
787
inline: false,
786
- onPress: () => copyTextWithHaptic(relativePath),
788
+ onPress: () =>
789
+ copyTextWithHaptic(
790
+ formatFilePathForClipboard(
791
+ relativePath,
792
+ resolvePathLinkTarget(relativePath, cwd ?? ""),
793
+ ),
794
+ ),
795
} as const,
796
]),
797
fileData?.contents != null
apps/mobile/src/features/threads/ThreadFeed.tsx
+6
-6
@@ -230,7 +230,7 @@ import {
230
} from "../files/filePath";
231
import { waitForThreadShellReady } from "./threadForkNavigation";
232
import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge";
233
-import { fileChipMenu, resolveFileChipTarget, type FileChipAction } from "./fileChipMenu";
233
+import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
234
import { useFileChipShare } from "./useFileChipShare";
235
import {
236
MarkdownImageAvailableWidthContext,
@@ -1869,13 +1869,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
1869
onFileContextMenuAction: (href, actionId) => {
1870
const target = resolveFileChipTarget(href, props.workspaceRoot);
1871
if (!target) return;
1872
- switch (actionId as FileChipAction) {
1872
+ switch (actionId) {
1873
case "copy-full-path":
1874
- if (target.fullPath) copyTextWithHaptic(target.fullPath);
1875
- return;
1876
- case "copy-relative-path":
1877
- if (target.relativePath) copyTextWithHaptic(target.relativePath);
1874
+ case "copy-relative-path": {
1875
+ const clipboardPath = fileChipClipboardPath(target, actionId);
1876
+ if (clipboardPath !== undefined) copyTextWithHaptic(clipboardPath);
1877
return;
1878
+ }
1879
case "open-file":
1880
onMarkdownLinkPress(href);
1881
return;
apps/mobile/src/features/threads/fileChipMenu.test.ts
+17
-1
@@ -1,7 +1,23 @@
1
import { ThreadId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
4
-import { fileChipMenu, fileChipShareSource, resolveFileChipTarget } from "./fileChipMenu";
4
+import {
5
+ fileChipClipboardPath,
6
+ fileChipMenu,
7
+ fileChipShareSource,
8
+ resolveFileChipTarget,
9
+} from "./fileChipMenu";
10
+
11
+it("copies native paths from a relative file chip in a Windows workspace", () => {
12
+ const target = resolveFileChipTarget("reports/Device Users.csv", "C:/repo");
13
+ if (!target) throw new Error("File-chip target unavailable");
14
+ expect(fileChipClipboardPath(target, "copy-full-path")).toBe(
15
+ String.raw`C:\repo\reports\Device Users.csv`,
16
+ );
17
+ expect(fileChipClipboardPath(target, "copy-relative-path")).toBe(
18
+ String.raw`reports\Device Users.csv`,
19
+ );
20
+});
21
22
describe("resolveFileChipTarget", () => {
23
it("resolves a workspace-relative link to both paths", () => {
apps/mobile/src/features/threads/fileChipMenu.ts
+9
-2
@@ -1,3 +1,4 @@
1
+import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2
import { fileBasename } from "@t3tools/shared/path";
3
import type { ThreadId } from "@t3tools/contracts";
4
import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks";
@@ -10,13 +11,19 @@ import {
11
resolveWorkspaceRelativeFilePath,
12
} from "../files/filePath";
13
13
-export type FileChipAction = "copy-full-path" | "copy-relative-path" | "open-file" | "save";
14
-
14
export interface FileChipTarget {
15
readonly fullPath?: string;
16
readonly relativePath?: string;
17
}
18
19
+export function fileChipClipboardPath(
20
+ target: FileChipTarget,
21
+ action: "copy-full-path" | "copy-relative-path",
22
+): string | undefined {
23
+ const path = action === "copy-full-path" ? target.fullPath : target.relativePath;
24
+ return path === undefined ? undefined : formatFilePathForClipboard(path, target.fullPath);
25
+}
26
+
27
export function resolveFileChipTarget(
28
href: string,
29
workspaceRoot: string | null | undefined,
apps/mobile/src/lib/mediaActions.test.ts
+51
@@ -5,6 +5,7 @@ import {
5
type AuthSessionState,
6
} from "@t3tools/contracts";
7
import { AsyncResult } from "effect/reactivity";
8
+import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
9
import { beforeEach, expect, it, vi } from "vite-plus/test";
10
11
const state = vi.hoisted(() => ({
@@ -96,6 +97,56 @@ beforeEach(() => {
97
state.copy.mockReset();
98
});
99
100
+it.each([
101
+ [
102
+ "C:/repo/assets/shot.png",
103
+ "C:/repo",
104
+ String.raw`C:\repo\assets\shot.png`,
105
+ String.raw`assets\shot.png`,
106
+ ],
107
+ [
108
+ String.raw`\\server\share\repo/assets/clip.mp4`,
109
+ String.raw`\\server\share\repo`,
110
+ String.raw`\\server\share\repo\assets\clip.mp4`,
111
+ String.raw`assets\clip.mp4`,
112
+ ],
113
+] as const)("copies full and relative media paths for %s", (path, root, full, relative) => {
114
+ const media = useMediaActions({
115
+ environmentId,
116
+ threadId,
117
+ resource: { _tag: "media-file", threadId, path },
118
+ reference: mediaFileReference(path, root),
119
+ name: path.split(/[\\/]/).at(-1)!,
120
+ mimeType: path.endsWith(".mp4") ? "video/mp4" : "image/png",
121
+ });
122
+ for (const [actionId, expected] of [
123
+ ["copy-full-path", full],
124
+ ["copy-relative-path", relative],
125
+ ] as const) {
126
+ const action = media.actions.find(({ id }) => id === actionId);
127
+ if (!action) throw new Error(`Missing media action: ${actionId}`);
128
+ action.run();
129
+ expect(state.copy).toHaveBeenLastCalledWith(expected);
130
+ }
131
+ expect(state.refresh).not.toHaveBeenCalled();
132
+ expect(state.download).not.toHaveBeenCalled();
133
+});
134
+
135
+it("preserves media URLs when copying", () => {
136
+ const url = "https://cdn.test/assets/media?path=C:/repo/media";
137
+ const media = useMediaActions({
138
+ uri: url,
139
+ name: "media",
140
+ mimeType: "video/mp4",
141
+ reference: { kind: "url", url },
142
+ });
143
+ const action = media.actions.find(({ id }) => id === "copy-url");
144
+ if (!action) throw new Error("Copy URL action missing");
145
+ action.run();
146
+ expect(state.copy).toHaveBeenCalledWith(url);
147
+ expect(state.refresh).not.toHaveBeenCalled();
148
+});
149
+
150
it.each(["workspace-file", "media-file"] as const)(
151
"waits for the %s grant before enabling host menu actions",
152
(_tag) => {
apps/mobile/src/state/mediaActions.ts
+8
-4
@@ -2,7 +2,10 @@ import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime
2
import * as Dialog from "../components/ui/Dialog";
3
import type { MediaActionsSource } from "../lib/mediaActionsSource";
4
import { useNavigation } from "@react-navigation/native";
5
-import type { MediaActionId } from "@t3tools/client-runtime/media-actions";
5
+import {
6
+ formatFilePathForClipboard,
7
+ type MediaActionId,
8
+} from "@t3tools/client-runtime/media-actions";
9
import {
10
AuthFilesystemReadScope,
11
type EnvironmentId,
@@ -108,16 +111,17 @@ export function useMediaActions(source: MediaActionsSource | undefined, onOpenFi
111
{
112
id: "copy-full-path" as const,
113
title: "Copy full path",
111
- run: () => copyTextWithHaptic(reference.path),
114
+ run: () => copyTextWithHaptic(formatFilePathForClipboard(reference.path)),
115
},
116
]
117
: []),
115
- ...(relativePath
118
+ ...(relativePath && reference?.kind === "file"
119
? [
120
{
121
id: "copy-relative-path" as const,
122
title: "Copy relative path",
120
- run: () => copyTextWithHaptic(relativePath),
123
+ run: () =>
124
+ copyTextWithHaptic(formatFilePathForClipboard(relativePath, reference.path)),
125
},
126
]
127
: []),
apps/web/src/components/BranchToolbar.panel.browser.test.tsx
+1
@@ -132,6 +132,7 @@ it.each([
132
["local", null, "/tmp/project"],
133
["worktree", null, null],
134
["worktree", "/tmp/worktree", "/tmp/worktree"],
135
+ ["worktree", "C:/repo/worktree", String.raw`C:\repo\worktree`],
136
] as const)(
137
"copies only an existing workspace path with mode %s and worktree %s",
138
async (envMode, worktreePath, copiedPath) => {
apps/web/src/components/BranchToolbar.tsx
+4
-2
@@ -1,4 +1,5 @@
1
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
2
+import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
3
import { readLocalApi } from "../localApi";
4
import { stackedThreadToast, toastManager } from "./ui/toast";
5
import { ComposerContextLabel } from "./ComposerContextLabel";
@@ -118,13 +119,14 @@ function showWorkspaceContextMenu(event: ReactMouseEvent, workspacePath: string)
119
})
120
.then((action) => {
121
if (action !== "copy-path") return;
121
- void writeTextToClipboard(workspacePath, "workspace path").then(
122
+ const clipboardPath = formatFilePathForClipboard(workspacePath);
123
+ void writeTextToClipboard(clipboardPath, "workspace path").then(
124
(didCopy) => {
125
if (didCopy) {
126
toastManager.add({
127
type: "success",
128
title: "Path copied",
127
- description: workspacePath,
129
+ description: clipboardPath,
130
});
131
}
132
},
apps/web/src/components/ChatMarkdown.browser.test.tsx
+56
@@ -11,6 +11,8 @@ import "../index.css";
11
import { useTheme } from "../hooks/useTheme";
12
import { applyThemeColorPreview, getStandardThemeColors } from "../themePalette";
13
14
+import { readLocalApi } from "../localApi";
15
+import { toastManager } from "./ui/toast";
16
import { filesystemEnvironment } from "../state/filesystem";
17
import { useRightPanelStore } from "../rightPanelStore";
18
import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
@@ -1262,6 +1264,60 @@ describe("ChatMarkdown thread find", () => {
1264
);
1265
});
1266
1267
+it.each([
1268
+ {
1269
+ name: "Windows drive paths on a Mac client",
1270
+ platform: "MacIntel",
1271
+ cwd: "C:/repo",
1272
+ href: "C:/repo/reports/Device Users.csv:12:3",
1273
+ full: String.raw`C:\repo\reports\Device Users.csv:12:3`,
1274
+ relative: String.raw`reports\Device Users.csv:12:3`,
1275
+ },
1276
+ {
1277
+ name: "UNC paths on a Mac client",
1278
+ platform: "MacIntel",
1279
+ cwd: String.raw`\\server\share\repo`,
1280
+ href: "file://server/share/repo/reports/report.csv",
1281
+ full: String.raw`\\server\share\repo\reports\report.csv`,
1282
+ relative: String.raw`reports\report.csv`,
1283
+ },
1284
+ {
1285
+ name: "POSIX paths on a Windows client",
1286
+ platform: "Win32",
1287
+ cwd: "/home/repo",
1288
+ href: "/home/repo/reports/report.csv",
1289
+ full: "/home/repo/reports/report.csv",
1290
+ relative: "reports/report.csv",
1291
+ },
1292
+])("copies $name and shows the copied text", async ({ platform, cwd, href, full, relative }) => {
1293
+ vi.spyOn(navigator, "platform", "get").mockReturnValue(platform);
1294
+ vi.stubGlobal("ClipboardItem", undefined);
1295
+ const writeText = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
1296
+ const toast = vi.spyOn(toastManager, "add");
1297
+ const api = readLocalApi();
1298
+ if (!api) throw new Error("Local API unavailable");
1299
+ const choose = vi.spyOn(api.contextMenu, "show");
1300
+ const container = await renderText(`[File](<${href}>)`, {
1301
+ cwd,
1302
+ environmentId: EnvironmentId.make("env-file-copy"),
1303
+ });
1304
+ const link = container.querySelector(".chat-markdown-file-link");
1305
+ if (!link) throw new Error("File link unavailable");
1306
+ for (const [action, expected] of [
1307
+ ["copy-full", full],
1308
+ ["copy-relative", relative],
1309
+ ] as const) {
1310
+ choose.mockResolvedValue(action);
1311
+ await act(async () => {
1312
+ link.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
1313
+ });
1314
+ expect(writeText).toHaveBeenLastCalledWith(expected);
1315
+ expect(toast).toHaveBeenLastCalledWith(
1316
+ expect.objectContaining({ type: "success", description: expected }),
1317
+ );
1318
+ }
1319
+});
1320
+
1321
describe("ChatMarkdown math", () => {
1322
const renderMath = async (
1323
text: string,
apps/web/src/components/ChatMarkdown.tsx
+2
-1
@@ -1,3 +1,4 @@
1
+import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2
import { MarkdownFindContext, findRevealRef } from "./chat/markdownFindContext";
3
import {
4
buildFileLinkParentSuffixByPath,
@@ -2119,7 +2120,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
2120
return;
2121
}
2122
2122
- const value = resolveValue();
2123
+ const value = resolveValue().then((text) => formatFilePathForClipboard(text, targetPath));
2124
// Start the write before workspace lookup finishes so Safari retains the user gesture.
2125
const write =
2126
typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined"
apps/web/src/components/ChatView.tsx
+8
-2
@@ -1,3 +1,5 @@
1
+import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2
+import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
3
import { ThreadFind, ThreadFindCanvas, type ThreadFindControls } from "./chat/ThreadFindProvider";
4
import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
5
import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
@@ -3993,12 +3995,16 @@ export default function ChatView(props: ChatViewProps) {
3995
return;
3996
}
3997
3996
- void navigator.clipboard.writeText(relativePath).then(
3998
+ const clipboardPath = formatFilePathForClipboard(
3999
+ relativePath,
4000
+ resolvePathLinkTarget(relativePath, gitCwd ?? activeProjectCwd ?? ""),
4001
+ );
4002
+ void navigator.clipboard.writeText(clipboardPath).then(
4003
() => {
4004
toastManager.add({
4005
type: "success",
4006
title: "Path copied",
4001
- description: relativePath,
4007
+ description: clipboardPath,
4008
});
4009
},
4010
(error) => {
apps/web/src/components/media/MediaActions.test.tsx
+54
-1
@@ -5,6 +5,7 @@ import {
5
type AuthSessionState,
6
} from "@t3tools/contracts";
7
import { AsyncResult } from "effect/reactivity";
8
+import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
9
import { createElement, isValidElement, type ReactNode } from "react";
10
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
11
@@ -24,6 +25,7 @@ const state = vi.hoisted(() => ({
25
showMenu: vi.fn(),
26
openFile: vi.fn(),
27
clipboard: vi.fn(),
28
+ copyText: vi.fn(),
29
menuFinished: null as (() => void) | null,
30
}));
31
@@ -33,7 +35,7 @@ vi.mock("react", async (importOriginal) => ({
35
useRef: <A,>(current: A) => ({ current }),
36
useState: <A,>(initial: A) => [initial, () => {}],
37
}));
36
-vi.mock("../../hooks/useCopyToClipboard", () => ({ writeTextToClipboard: vi.fn() }));
38
+vi.mock("../../hooks/useCopyToClipboard", () => ({ writeTextToClipboard: state.copyText }));
39
vi.mock("../../localApi", () => ({
40
readLocalApi: () => ({ contextMenu: { show: state.showMenu } }),
41
}));
@@ -128,6 +130,7 @@ beforeEach(() => {
130
state.png.mockReset().mockResolvedValue(new Blob(["png"], { type: "image/png" }));
131
state.showMenu.mockReset().mockResolvedValue(null);
132
state.openFile.mockReset();
133
+ state.copyText.mockReset().mockResolvedValue(true);
134
state.menuFinished = null;
135
class TestClipboardItem {
136
constructor(readonly items: Record<string, Promise<Blob>>) {}
@@ -141,6 +144,56 @@ beforeEach(() => {
144
145
afterEach(() => vi.unstubAllGlobals());
146
147
+it.each([
148
+ [
149
+ "image",
150
+ "C:/repo/assets/shot.png",
151
+ "C:/repo",
152
+ String.raw`C:\repo\assets\shot.png`,
153
+ String.raw`assets\shot.png`,
154
+ ],
155
+ [
156
+ "video",
157
+ String.raw`\\server\share\repo/assets/clip.mp4`,
158
+ String.raw`\\server\share\repo`,
159
+ String.raw`\\server\share\repo\assets\clip.mp4`,
160
+ String.raw`assets\clip.mp4`,
161
+ ],
162
+] as const)(
163
+ "copies full and relative paths for %s %s",
164
+ async (kind, path, root, full, relative) => {
165
+ const source: MediaActionSource = {
166
+ ...hostSource(),
167
+ kind,
168
+ reference: mediaFileReference(path, root),
169
+ };
170
+ for (const [action, expected] of [
171
+ ["copy-full-path", full],
172
+ ["copy-relative-path", relative],
173
+ ] as const) {
174
+ const completed = deferred<void>();
175
+ state.menuFinished = () => completed.resolve();
176
+ state.showMenu.mockResolvedValue(action);
177
+ openMenu(source);
178
+ await completed.promise;
179
+ expect(state.copyText).toHaveBeenLastCalledWith(expected, "file path");
180
+ }
181
+ expect(state.mint).not.toHaveBeenCalled();
182
+ expect(state.download).not.toHaveBeenCalled();
183
+ },
184
+);
185
+
186
+it("preserves media URLs when copying", async () => {
187
+ const url = "https://cdn.test/assets/clip.mp4?path=C:/repo/media";
188
+ const completed = deferred<void>();
189
+ state.menuFinished = () => completed.resolve();
190
+ state.showMenu.mockResolvedValue("copy-url");
191
+ openMenu({ ...hostSource(), kind: "video", src: url, reference: { kind: "url", url } });
192
+ await completed.promise;
193
+ expect(state.copyText).toHaveBeenCalledWith(url, "URL");
194
+ expect(state.mint).not.toHaveBeenCalled();
195
+});
196
+
197
it.each(["workspace-file", "media-file"] as const)(
198
"waits for the %s grant before enabling host menu actions",
199
(_tag) => {
apps/web/src/components/media/MediaActions.tsx
+7
-2
@@ -1,4 +1,7 @@
1
-import type { MediaActionId } from "@t3tools/client-runtime/media-actions";
1
+import {
2
+ formatFilePathForClipboard,
3
+ type MediaActionId,
4
+} from "@t3tools/client-runtime/media-actions";
5
import {
6
mediaReferenceFileName,
7
type MediaReference,
@@ -166,7 +169,9 @@ export function MediaActions({
169
? reference.url
170
: undefined;
171
if (text !== undefined) {
169
- await writeTextToClipboard(text, reference?.kind === "file" ? "file path" : "URL");
172
+ const clipboardText =
173
+ reference?.kind === "file" ? formatFilePathForClipboard(text, reference.path) : text;
174
+ await writeTextToClipboard(clipboardText, reference?.kind === "file" ? "file path" : "URL");
175
toastManager.add({
176
type: "success",
177
title: action === "copy-url" ? "URL copied" : "Path copied",
packages/client-runtime/src/mediaActions.ts
+7
@@ -1,3 +1,10 @@
1
+import { isWindowsAbsolutePath } from "@t3tools/shared/path";
2
+
3
+// The file host can use a different path style from the client.
4
+export function formatFilePathForClipboard(path: string, hostPath = path): string {
5
+ return isWindowsAbsolutePath(hostPath) ? path.replaceAll("/", "\\") : path;
6
+}
7
+
8
export type MediaActionId =
9
| "copy-full-path"
10
| "copy-relative-path"