[PR #6763] fix(windows): path handling fixes for Windows #12091

Open
opened 2026-02-16 18:17:01 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6763

State: open
Merged: No


fixes #10360
fixes #10872
fixes #11042
fixes #11043
fixes #11044
fixes #11045
fixes #10871
fixes #8924
fixes #8567
fixes #7279
fixes #6020

fixes ALL test cases in the test suite running on win32 system

(most likely plus a series of more issues)

partly fixes #9077
possibly fixes #10798
possibly fixes #10716
possibly fixes #10642

Summary

This fix solves a whole series of bugs, resulting from filepath issues with backslashes occuring on Windows.

Solution: normalize all internal paths to forward slashes using centralized Filesystem wrappers

Why this works: all win32 shells work with forward slash paths, this is de-facto industry standard (git, vscode, cmake, ... all use this pattern)

Observed issues

git rev-parse --show-toplevel returns E:/x/y forward slash format → worktree/directory mismatch
path.resolve(), path.relative(), realpathSync.native(), realpath (bash) break with git bash paths (various issues)
/d/x within C drive (/c/) results in things like C:\d\x
relative paths not working like expected using cross-drive
contains logic not working → issues with permission system and external_directory
/tmp inside git bash is something else outside of it
tools break using backslash paths (some backslashes get "eaten")
escaping hell for agents → requires double/quadruple escaping
observed in all win32 native shells (git bash, cmd, powershell/pwsh)
few issues in app/desktop (wrong filepath splits/usage)
bun hard crashing with segfault when spawn() is used with non-existing directory

Tested with fix

local test suite succeeds now with 100% (bun test in packages/opencode)
all possible path variants (C:\a\b, C:/a/b, /c/a/b, /cygdrive/c/a/b) are normalized into C:/a/b format
full functionality of all tools (ENOENT errors gone, permissions, relative paths, external directory, LSP)
worktree/sandbox handling correct
tested TUI and desktop
bun spawns via bash/pty not segfaulting

How to reproduce/test

  • test suite
  • running prompts with various problematic/mixed filepaths (see attached md example)

Notes

A few more places would require normalization - but they're unused/dead code (should be removed):

  • packages/ui/src/context/sync.tsx line 16 absolute()
  • packages/ui/src/context/local.tsx line 392, 420, 455, 546 - file tree operations (no file tree used)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6763 **State:** open **Merged:** No --- fixes #10360 fixes #10872 fixes #11042 fixes #11043 fixes #11044 fixes #11045 fixes #10871 fixes #8924 fixes #8567 fixes #7279 fixes #6020 fixes ALL test cases in the test suite running on win32 system (most likely plus a series of more issues) partly fixes #9077 possibly fixes #10798 possibly fixes #10716 possibly fixes #10642 ## Summary This fix solves a whole series of bugs, resulting from filepath issues with backslashes occuring on Windows. → **Solution: normalize all internal paths to forward slashes using centralized `Filesystem` wrappers** **Why this works:** all win32 shells work with forward slash paths, this is de-facto industry standard (git, vscode, cmake, ... all use this pattern) ## Observed issues ❌ `git rev-parse --show-toplevel` returns `E:/x/y` forward slash format → worktree/directory mismatch ❌ `path.resolve()`, `path.relative()`, `realpathSync.native()`, `realpath` (bash) break with git bash paths (various issues) ❌ `/d/x` within C drive (`/c/`) results in things like `C:\d\x` ❌ relative paths not working like expected using cross-drive ❌ `contains` logic not working → issues with permission system and external_directory ❌ `/tmp` inside git bash is something else outside of it ❌ tools break using backslash paths (some backslashes get "eaten") ❌ escaping hell for agents → requires double/quadruple escaping ❌ observed in all win32 native shells (git bash, cmd, powershell/pwsh) ❌ few issues in app/desktop (wrong filepath splits/usage) ❌ bun hard crashing with segfault when `spawn()` is used with non-existing directory ## Tested with fix ✅ local test suite succeeds now with 100% (`bun test` in `packages/opencode`) ✅ all possible path variants (`C:\a\b`, `C:/a/b`, `/c/a/b`, `/cygdrive/c/a/b`) are normalized into `C:/a/b` format ✅ full functionality of all tools (`ENOENT` errors gone, permissions, relative paths, external directory, LSP) ✅ worktree/sandbox handling correct ✅ tested TUI and desktop ✅ bun spawns via bash/pty not segfaulting ## How to reproduce/test - test suite - running prompts with various problematic/mixed filepaths (see attached md example) ## Notes A few more places would require normalization - but they're unused/dead code (should be removed): - `packages/ui/src/context/sync.tsx` line 16 `absolute()` - `packages/ui/src/context/local.tsx` line 392, 420, 455, 546 - file tree operations (no file tree used)
yindo added the pull-request label 2026-02-16 18:17:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12091