Skip to content

fix(windows): path handling fixes for Windows - #6763

Closed
pschiel wants to merge 2 commits into
anomalyco:devfrom
pschiel:windows-posix-paths
Closed

fix(windows): path handling fixes for Windows#6763
pschiel wants to merge 2 commits into
anomalyco:devfrom
pschiel:windows-posix-paths

Conversation

@pschiel

@pschielpschiel commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

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)

@pschiel
pschielforce-pushed the windows-posix-paths branch 2 times, most recently from 032638f to 61531f5CompareJanuary 9, 2026 20:17
@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title (feat) support MSYS forward slashes with experimental flag doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@pschiel
pschielforce-pushed the windows-posix-paths branch 3 times, most recently from adf2edd to 9b205c2CompareJanuary 11, 2026 04:37
@pschielpschiel changed the title (feat) support MSYS forward slashes with experimental flagfeat: support MSYS forward slashes with experimental flagJan 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@Hona
Hona self-requested a review January 11, 2026 20:25
@Hona

Hona commented Jan 11, 2026

Copy link
Copy Markdown
Member

This sounds perfect @pschiel

If you can get it ready and finish the cleanup you said I can test and approve.

Btw don't put it behind an experimental flag. We'll ship once it's working.

@pschiel
pschielforce-pushed the windows-posix-paths branch 4 times, most recently from 767f78b to ba251fbCompareJanuary 15, 2026 21:49
@pschielpschiel changed the title feat: support MSYS forward slashes with experimental flagfix(windows): comprehensive path handling fixes for MSYS/Git Bash compatibilityJan 15, 2026
@pschielpschiel changed the title fix(windows): comprehensive path handling fixes for MSYS/Git Bash compatibilityfix(windows): path handling fixes for MSYS/Git Bash compatibilityJan 16, 2026
@@ -1 +1 @@
../../ui/src/custom-elements.d.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi this is a symlink.
on windows its disabled by default

enable it with

git config core.symlinks true

then recheckout all the files with

git checkout -- .

obviously that would reset any changes so stash/commit first.
that will fix the typecheck too

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was intentional, as this requires admin permissions on windows.

thoughts: changing symlink into export statement in 2 files is worth it for that (the other ~70 symlinks are fonts/images and not affected by TS parsing)

@neriousyneriousyJan 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this would've worked keeping as a simlink

/// <reference path="../../ui/src/custom-elements.d.ts" />

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neriousy I went by this https://typescript-eslint.io/rules/triple-slash-reference/ which mentions triple slash being discouraged in modern ES6, and a rule for it.

please feel free to change, it was just so typecheck and tests run without errors, in a win32 environment

@pschiel
pschielforce-pushed the windows-posix-paths branch 5 times, most recently from 62152d4 to 30a54ceCompareJanuary 17, 2026 20:51
@pschiel
pschiel marked this pull request as ready for review January 17, 2026 21:19
@pschielpschiel changed the title fix(windows): path handling fixes for MSYS/Git Bash compatibilityfix(windows): path handling fixes for WindowsJan 17, 2026
@pschiel

Copy link
Copy Markdown
ContributorAuthor

Can't reproduce that unicode fail. Ran tests on git bash, powershell and in a Debian container, all passed 🤔

@Hona

Hona commented Jan 28, 2026

Copy link
Copy Markdown
Member

Yup definitely get the whole need for bash compatible paths at all times, give me a sec to investigate impl details and options

@pschiel

Copy link
Copy Markdown
ContributorAuthor

added fixes to avoid bun hard crashing (segfaulting) when invalid cwd is passed

@pschiel

pschiel commented Feb 2, 2026

Copy link
Copy Markdown
ContributorAuthor

issues with added prompt test: BunProc.install() hangs in Windows and runs into the timeout -> added Mock in test
d997822382d0b66059c0b0f4bfb56cac331fd775

@edemaine

Copy link
Copy Markdown
Contributor

Just bumped into this and hope it can be finalized! I made some similar changes in #13671 and #13659 but happy to see you got all the way to 0 errors. I think most of #13659 is still relevant for Cygwin support, but I can review it once this gets merged. Anyway, let me know if I can help.

@pschielpschiel closed this Feb 22, 2026
@pschiel

Copy link
Copy Markdown
ContributorAuthor

Just bumped into this and hope it can be finalized! I made some similar changes in #13671 and #13659 but happy to see you got all the way to 0 errors. I think most of #13659 is still relevant for Cygwin support, but I can review it once this gets merged. Anyway, let me know if I can help.

they apparently prefer their own thing, closing this one - getting no replies since december. despite all the things clearly broken.
dropped using opencode due to this, someone else needs to continue - patch shows what needs to be fixed and how.

@tppawelgrzesik

Copy link
Copy Markdown

@Hona@adamdotdevin@neriousy so is this being worked on elsewhere?

I saw some PRs merged regarding Windows path handling but as of Windows App/Web 1.2.20 change detection / review is still completely broken, eg. always stays empty.

@Hona

Hona commented Mar 6, 2026

Copy link
Copy Markdown
Member

Yes it's nots far off

@tppawelgrzesik

Copy link
Copy Markdown

@Hona alright thanks. I really hope this comes sometime soon.

As of today it's still not working properly.

image

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment