@devries-cameron20 / t3code-1 / commits / 834f0e3a1b
Fork 0

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

fix(markdown): Windows paths in messages keep their backslashes (#21069)

Co-authored-by: OhadC <4123639+OhadC@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Dara Adedeji committed Oct 18, 2026 at 16:12 UTC 834f0e3a1b3dd0aebda73f8e623addbf62f697f6
3 files changed +60 -7
apps/web/src/components/chat/MessagesTimeline.tsx
+6 -1
@@ -1,6 +1,9 @@
1 import { ThreadFindTimelineContext } from "./ThreadFindProvider";
2 import { shallow } from "zustand/vanilla/shallow";
3 -import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
3 +import {
4 + remarkKeepWindowsPaths,
5 + shouldPreserveAssistantLineBreaks,
6 +} from "@t3tools/shared/markdownPipeline";
7 import { MarkdownFindContext, findRevealRef } from "./markdownFindContext";
8 import { useChatCanvas } from "./ChatCanvasContext";
9 import { WorkLogBlock, WorkLogButton, WorkLogDetails, WorkLogList, WorkLogRow } from "./WorkLog";
@@ -3850,6 +3853,7 @@ function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "
3853 <ReactMarkdown
3854 remarkPlugins={[
3855 remarkGfm,
3856 + remarkKeepWindowsPaths,
3857 [remarkThoughtPreview, row.active ? "Thinking" : "Thought"],
3858 ]}
3859 >
@@ -5480,6 +5484,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
5484 <ReactMarkdown
5485 remarkPlugins={[
5486 remarkGfm,
5487 + remarkKeepWindowsPaths,
5488 [
5489 remarkThoughtPreview,
5490 workEntry.toolLifecycleStatus === "inProgress" ? "Thinking" : "Thought",
packages/shared/src/markdownPipeline.test.ts
+28
@@ -27,3 +27,31 @@ it("preserves in-app thread links through the shared Markdown sanitizer", () =>
27 });
28 expect(JSON.stringify(tree)).not.toContain("javascript:");
29 });
30 +
31 +it("keeps backslashes that CommonMark would read as escapes in prose Windows paths", () => {
32 + const processor = unified()
33 + .use(remarkParse)
34 + .use(CHAT_MARKDOWN_REMARK_PLUGINS)
35 + .use(remarkRehype, { allowDangerousHtml: true })
36 + .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
37 + type Node = { type: string; value?: string; tagName?: string; children?: Node[] };
38 + const text = (node: Node): string =>
39 + node.type === "text"
40 + ? (node.value ?? "")
41 + : node.tagName === "code"
42 + ? `<code>${(node.children ?? []).map(text).join("")}</code>`
43 + : (node.children ?? []).map(text).join("");
44 + const render = (markdown: string) => text(processor.runSync(processor.parse(markdown)) as Node);
45 +
46 + expect(
47 + render(String.raw`Saved to C:\Users\me\.t3\_build and (C:\.scratch) and C:/work\.config.`),
48 + ).toBe(String.raw`Saved to C:\Users\me\.t3\_build and (C:\.scratch) and C:/work\.config.`);
49 + // Paths render as written, so one an agent already escaped keeps its doubled backslashes.
50 + expect(render(String.raw`Escaped C:\\Users\\me`)).toBe(String.raw`Escaped C:\\Users\\me`);
51 + expect(render(String.raw`See C:\x and \*this\* and Note:\*that\*.`)).toBe(
52 + String.raw`See C:\x and *this* and Note:*that*.`,
53 + );
54 + expect(render(String.raw`${"`"}C:\me\.t3${"`"} and C:\me\.t3`)).toBe(
55 + String.raw`<code>C:\me\.t3</code> and C:\me\.t3`,
56 + );
57 +});
packages/shared/src/markdownPipeline.ts
+26 -6
@@ -158,7 +158,7 @@ const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
158
159 export const CHAT_MARKDOWN_REMARK_PLUGINS: PluggableList = [
160 remarkGfm,
161 - remarkKeepWindowsPathDestinations,
161 + remarkKeepWindowsPaths,
162 remarkGithubAlerts,
163 remarkNormalizeListItemIndentation,
164 remarkCodexDirectives,
@@ -168,7 +168,7 @@ export const CHAT_MARKDOWN_REMARK_PLUGINS: PluggableList = [
168
169 export const CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS: PluggableList = [
170 remarkGfm,
171 - remarkKeepWindowsPathDestinations,
171 + remarkKeepWindowsPaths,
172 remarkGithubAlerts,
173 remarkNormalizeListItemIndentation,
174 remarkCodexDirectives,
@@ -255,17 +255,37 @@ function keepWindowsPathDestination(this: DestinationCompileContext, token: unkn
255 node.url = isWindowsAbsolutePath(authored) && !authored.includes("&") ? authored : decoded;
256 }
257
258 +// A drive path that has not reached whitespace yet: `C:`, `C:\Users\me`, `C:/work`.
259 +const UNFINISHED_DRIVE_PATH = /(?:^|\W)[A-Za-z]:(?:[\\/]\S*)?$/;
260 +
261 +interface EscapeCompileContext {
262 + readonly stack: ReadonlyArray<{
263 + readonly type: string;
264 + children?: Array<{ type: string; value?: string }>;
265 + }>;
266 +}
267 +
268 +function keepWindowsPathEscape(this: EscapeCompileContext) {
269 + const text = this.stack.at(-1)?.children?.at(-1);
270 + if (text?.type !== "text" || text.value === undefined) return;
271 + const before = text.value.slice(0, -1);
272 + if (UNFINISHED_DRIVE_PATH.test(before)) text.value = `${before}\\${text.value.slice(-1)}`;
273 +}
274 +
275 /**
259 - * CommonMark reads the `\.` in `C:\me\.t3\shot.png` as an escape, even in a link
260 - * destination. Every backslash in a Windows path is a separator, so link, image, and
261 - * definition destinations that are Windows paths keep the text as written.
276 + * CommonMark reads the `\.` in `C:\me\.t3\shot.png` as an escape. Every backslash in a
277 + * Windows path is a separator, so link, image, and definition destinations that are
278 + * Windows paths keep the text as written, and so do escapes inside drive paths in prose.
279 + * Prose paths end at whitespace: past that, nothing tells a path from a sentence, and
280 + * `C:\x and \*this\*` must still read `*this*`.
281 */
263 -function remarkKeepWindowsPathDestinations(this: Processor) {
282 +export function remarkKeepWindowsPaths(this: Processor) {
283 const data = this.data();
284 (data.fromMarkdownExtensions ??= []).push({
285 exit: {
286 resourceDestinationString: keepWindowsPathDestination,
287 definitionDestinationString: keepWindowsPathDestination,
288 + characterEscape: keepWindowsPathEscape,
289 },
290 });
291 }