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

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

fix(web): terminal OSC 8 file URIs open the file they name (#36025)

Julius Marminge committed Nov 12, 2026 at 22:10 UTC 1acee5b8bef71e2a5b32e0e7bd8ffba5f4240fff
3 files changed +38 -5
apps/web/src/components/ThreadTerminalDrawer.tsx
+4 -5
@@ -57,8 +57,7 @@ import {
57 } from "~/terminal/ghostty/surface";
58 import { type GhosttyColor, type GhosttyTheme } from "~/terminal/ghostty/core";
59 import { useOpenInPreferredEditor } from "../editorPreferences";
60 -import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
61 -import { isTerminalUrl } from "../terminal-links";
60 +import { isTerminalUrl, resolveTerminalLinkTarget } from "../terminal-links";
61 import {
62 isDiffToggleShortcut,
63 isTerminalClearShortcut,
@@ -526,7 +525,7 @@ function TerminalSessionViewport({
525 linkPath !== null && canOpenHostEditor && canReadFilesystem
526 ? getFileMetadataQueryAtom(
527 environmentId,
529 - resolvePathLinkTarget(linkPath, cwd),
528 + resolveTerminalLinkTarget(linkPath, cwd),
529 cwd,
530 metadataThreadRef,
531 )
@@ -547,7 +546,7 @@ function TerminalSessionViewport({
546 return false;
547 const query = getFileMetadataQueryAtom(
548 environmentId,
550 - resolvePathLinkTarget(text, cwd),
549 + resolveTerminalLinkTarget(text, cwd),
550 cwd,
551 metadataThreadRef,
552 );
@@ -1011,7 +1010,7 @@ function TerminalSessionViewport({
1010 );
1011 return;
1012 }
1014 - const target = resolvePathLinkTarget(text, cwd);
1013 + const target = resolveTerminalLinkTarget(text, cwd);
1014 void (async () => {
1015 const result = await openTerminalPath(target);
1016 if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
apps/web/src/terminal-links.test.ts
+14
@@ -5,6 +5,7 @@ import {
5 collectWrappedTerminalLinkLine,
6 extractTerminalLinks,
7 isTerminalUrl,
8 + resolveTerminalLinkTarget,
9 type TerminalBufferLineLike,
10 } from "./terminal-links";
11
@@ -297,4 +298,17 @@ describe("resolvePathLinkTarget", () => {
298 "/Users/julius/project/main.c:10:5",
299 );
300 });
301 +
302 + // regression: #36005 OSC 8 file URIs were joined onto the cwd as relative paths
303 + it("does not resolve an OSC 8 file URI target against the cwd", () => {
304 + expect(resolveTerminalLinkTarget("file:///var/tmp/report.txt", "/workspace/project")).toBe(
305 + "/var/tmp/report.txt",
306 + );
307 + expect(
308 + resolveTerminalLinkTarget("file://remote.invalid/var/tmp/report.txt", "/workspace/project"),
309 + ).not.toMatch(/^\/workspace\/project\//);
310 + expect(resolvePathLinkTarget("file:notes.md", "/workspace/project")).toBe(
311 + "/workspace/project/file:notes.md",
312 + );
313 + });
314 });
apps/web/src/terminal-links.ts
+20
@@ -1,3 +1,11 @@
1 +import {
2 + formatFilePathPosition,
3 + parseFileUrlHref,
4 + resolvePathLinkTarget,
5 + splitFilePathPosition,
6 +} from "@t3tools/shared/fileLinks";
7 +import { safeDecodeURIComponent } from "@t3tools/shared/markdownLinks";
8 +import { stripSlashPrefixedWindowsDrive } from "@t3tools/shared/path";
9 import { isMacPlatform } from "./lib/utils";
10
11 export type TerminalLinkKind = "url" | "path";
@@ -150,6 +158,18 @@ export function isTerminalUrl(value: string): boolean {
158 return /^https?:\/\//iu.test(value);
159 }
160
161 +/** Explicit OSC 8 targets may be `file://` URIs; everything else is a path relative to `cwd`. */
162 +export function resolveTerminalLinkTarget(text: string, cwd: string): string {
163 + const fileUrl = /^file:\/\//iu.test(text) ? parseFileUrlHref(text) : null;
164 + if (!fileUrl) return resolvePathLinkTarget(text, cwd);
165 + return formatFilePathPosition(
166 + splitFilePathPosition(
167 + stripSlashPrefixedWindowsDrive(safeDecodeURIComponent(fileUrl.path)),
168 + fileUrl.hash,
169 + ),
170 + );
171 +}
172 +
173 export function collectWrappedTerminalLinkLine(
174 bufferLineNumber: number,
175 getLine: (bufferLineIndex: number) => TerminalBufferLineLike | null | undefined,