@devries-cameron20 / t3code-1 / commits / a81961d756
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): copy file paths relative to the thread workspace (#21497)

Co-authored-by: Westline Marketing <westlinemarketing@gmail.com>

Julius Marminge committed Oct 19, 2026 at 16:21 UTC a81961d75681b681530b64be4ffe0efce4876204
2 files changed +81 -12
apps/web/src/components/ChatMarkdown.logic.test.ts
+52
@@ -1,8 +1,11 @@
1 import { EnvironmentId } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3
4 +import { resolveMarkdownFileLinkMeta } from "../markdown-links";
5 +
6 import {
7 canUseMarkdownFileShellActions,
8 + markdownFileCopyMenuItems,
9 shouldUseMarkdownFileBrowserPrimaryAction,
10 } from "./ChatMarkdown";
11
@@ -53,3 +56,52 @@ describe("shouldUseMarkdownFileBrowserPrimaryAction", () => {
56 ).toBe(true);
57 });
58 });
59 +
60 +describe("markdownFileCopyMenuItems", () => {
61 + it.each([
62 + {
63 + name: "project file",
64 + href: "/Users/jordan/project/src/main.ts",
65 + cwd: "/Users/jordan/project",
66 + relative: "src/main.ts",
67 + full: "/Users/jordan/project/src/main.ts",
68 + },
69 + {
70 + name: "worktree file with a line and column",
71 + href: "src/main.ts:12:3",
72 + cwd: "/Users/jordan/project/.claude/worktrees/topic",
73 + relative: "src/main.ts:12:3",
74 + full: "/Users/jordan/project/.claude/worktrees/topic/src/main.ts:12:3",
75 + },
76 + {
77 + name: "main checkout file outside the thread worktree",
78 + href: "/Users/jordan/project/src/main.ts",
79 + cwd: "/Users/jordan/project/.claude/worktrees/topic",
80 + relative: null,
81 + full: "/Users/jordan/project/src/main.ts",
82 + },
83 + ])("offers accurate clipboard values for $name", ({ href, cwd, relative, full }) => {
84 + const meta = resolveMarkdownFileLinkMeta(href, cwd);
85 + expect(meta).not.toBeNull();
86 + if (!meta) throw new Error(`Expected a file link for ${href}`);
87 +
88 + expect(markdownFileCopyMenuItems(meta)).toEqual([
89 + ...(relative === null
90 + ? []
91 + : [
92 + {
93 + id: "copy-relative",
94 + label: "Copy relative path",
95 + value: relative,
96 + title: "Relative path",
97 + },
98 + ]),
99 + {
100 + id: "copy-full",
101 + label: "Copy full path",
102 + value: full,
103 + title: "Full path",
104 + },
105 + ]);
106 + });
107 +});
apps/web/src/components/ChatMarkdown.tsx
+29 -12
@@ -3,6 +3,7 @@ import {
3 buildFileLinkParentSuffixByPath,
4 fileLinkLabel,
5 resolvePathLinkTarget,
6 + splitFilePathPosition,
7 } from "@t3tools/shared/fileLinks";
8 import {
9 isWindowsDrivePathHref,
@@ -277,6 +278,25 @@ function hasMarkdownFilePrimaryAction(input: {
278 );
279 }
280
281 +export function markdownFileCopyMenuItems({
282 + targetPath,
283 + workspaceRelativePath,
284 +}: Pick<MarkdownFileLinkMeta, "targetPath" | "workspaceRelativePath">) {
285 + const items = [
286 + { id: "copy-full", label: "Copy full path", value: targetPath, title: "Full path" },
287 + ];
288 + if (workspaceRelativePath !== null) {
289 + const position = targetPath.slice(splitFilePathPosition(targetPath).path.length);
290 + items.unshift({
291 + id: "copy-relative",
292 + label: "Copy relative path",
293 + value: `${workspaceRelativePath}${position}`,
294 + title: "Relative path",
295 + });
296 + }
297 + return items;
298 +}
299 +
300 export function shouldUseMarkdownFileBrowserPrimaryAction(input: {
301 iconPath: string;
302 canOpenInEditor: boolean;
@@ -1213,7 +1233,7 @@ interface MarkdownFileLinkProps {
1233 href: string;
1234 targetPath: string;
1235 iconPath: string;
1216 - displayPath: string;
1236 + workspaceRelativePath: string | null;
1237 panelPath: string | null;
1238 line?: number | undefined;
1239 label: string;
@@ -1950,7 +1970,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
1970 href,
1971 targetPath,
1972 iconPath,
1953 - displayPath,
1973 + workspaceRelativePath,
1974 panelPath,
1975 line,
1976 label,
@@ -2132,6 +2152,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
2152 if (!api) return;
2153
2154 try {
2155 + const copyItems = markdownFileCopyMenuItems({ targetPath, workspaceRelativePath });
2156 const clicked = await api.contextMenu.show(
2157 [
2158 ...(onOpenMedia ? ([{ id: "preview-media", label: "Preview media" }] as const) : []),
@@ -2140,8 +2161,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
2161 ? ([{ id: "open-in-browser", label: "Open in integrated browser" }] as const)
2162 : []),
2163 ...(onReveal && revealLabel ? ([{ id: "reveal", label: revealLabel }] as const) : []),
2143 - { id: "copy-relative", label: "Copy relative path" },
2144 - { id: "copy-full", label: "Copy full path" },
2164 + ...copyItems.map(({ id, label }) => ({ id, label })),
2165 ] as const,
2166 position,
2167 );
@@ -2162,12 +2182,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
2182 handleRevealInFileManager();
2183 return;
2184 }
2165 - if (clicked === "copy-relative") {
2166 - handleCopy(displayPath, "Relative path");
2167 - return;
2168 - }
2169 - if (clicked === "copy-full") {
2170 - handleCopy(targetPath, "Full path");
2185 + const copyItem = copyItems.find(({ id }) => id === clicked);
2186 + if (copyItem) {
2187 + handleCopy(copyItem.value, copyItem.title);
2188 }
2189 } catch (cause) {
2190 reportMarkdownActionFailure(
@@ -2277,7 +2294,7 @@ function areMarkdownFileLinkPropsEqual(
2294 previous.targetPath === next.targetPath &&
2295 previous.iconPath === next.iconPath &&
2296 previous.environmentId === next.environmentId &&
2280 - previous.displayPath === next.displayPath &&
2297 + previous.workspaceRelativePath === next.workspaceRelativePath &&
2298 previous.panelPath === next.panelPath &&
2299 previous.line === next.line &&
2300 previous.label === next.label &&
@@ -2708,7 +2725,7 @@ function useChatMarkdownState({
2725 href={fileLinkMeta.targetPath}
2726 targetPath={fileLinkMeta.targetPath}
2727 iconPath={fileLinkMeta.filePath}
2711 - displayPath={fileLinkMeta.displayPath}
2728 + workspaceRelativePath={fileLinkMeta.workspaceRelativePath}
2729 panelPath={panelPath}
2730 line={fileLinkMeta.line}
2731 label={fileLinkLabel(