Skip to content

fix: handle root cwd when launched from GUI without terminal#4

Draft
thdxr wants to merge 1 commit intopithings:mainfrom
thdxr:fix-root-cwd
Draft

fix: handle root cwd when launched from GUI without terminal#4
thdxr wants to merge 1 commit intopithings:mainfrom
thdxr:fix-root-cwd

Conversation

@thdxr
Copy link
Copy Markdown

@thdxr thdxr commented Apr 15, 2026

Problem

When apps are launched from macOS Finder, Windows Explorer, or other GUI environments without a terminal, process.cwd() returns the root directory:

  • Unix: /
  • Windows: C:\, D:\, etc.

The default preopens: { ".": process.cwd() } then maps . to root, which:

  1. Is rarely the intended search directory for GUI apps
  2. Can cause permission/sandbox issues when reading from root
  3. Breaks apps bundled in Tauri/Electron when launched from Finder/Explorer

Solution

  • Added isRootPath() helper using path.parse() to detect root directories on both Unix and Windows
  • When cwd is root, getDefaultPreopens() returns {} instead of mapping . to root
  • This forces users to provide explicit absolute paths in GUI environments

Changes

  • lib/index.mjs: +24 lines (isRootPath + getDefaultPreopens helpers)
  • test/ripgrep.test.mjs: +24 lines (regression test for root cwd scenario)
  • README.md: Updated documentation with GUI environment note

Testing

All 28 tests pass, including the new regression test that simulates the root cwd scenario.

Checklist

  • Added regression test
  • Updated documentation
  • All tests pass
  • Code formatted with oxfmt

When apps are launched from macOS Finder, Windows Explorer, or other
GUI environments without a terminal, process.cwd() returns the root
directory ('/' on Unix, 'C:\' on Windows). This caused issues because:

1. The default preopens mapped '.' to root, which is rarely the intended
   search directory in GUI apps
2. Reading from root in sandboxed environments can fail or cause
   permission issues

The fix adds isRootPath() helper using path.parse() to detect root
directories on both Unix ('/') and Windows ('C:\', 'D:\', etc.).
When cwd is root, getDefaultPreopens() returns {} instead of mapping
'.' to root. This forces users to provide explicit absolute paths
when running in these environments.

Changes:
- lib/index.mjs: Add isRootPath() and getDefaultPreopens() helpers
- test/ripgrep.test.mjs: Add regression test for root cwd scenario
- README.md: Document the behavior and workaround for GUI environments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant