fix: resolve working directory from primary mount on HostBackend#392
Open
RayCharlizard wants to merge 1 commit intoaaddrick:mainfrom
Open
fix: resolve working directory from primary mount on HostBackend#392RayCharlizard wants to merge 1 commit intoaaddrick:mainfrom
RayCharlizard wants to merge 1 commit intoaaddrick:mainfrom
Conversation
The Electron app sends `cwd=/sessions/{name}` (a session-root guest
path) for every Cowork session. `resolveWorkDir()` attempts to
translate this via `translateGuestPath()`, but that function's regex
requires `/sessions/{name}/mnt/{mount}/...` — the session root has no
`/mnt/` component, so translation always fails and CWD falls back to
`os.homedir()`.
BwrapBackend avoids this because it overrides `spawn()` and derives CWD
from the primary user mount (first non-dotfile, non-uploads key in
`mountMap`). HostBackend goes through `resolveWorkDir()` which lacked
this fallback.
Add the same primary-mount derivation to `resolveWorkDir()`: when the
CWD is a session-root guest path that `translateGuestPath()` cannot
resolve, find the primary user mount from `mountMap` and use its host
path. Falls back to homedir only when no user mount exists.
Verified with a Node.js test harness simulating the exact spawn
parameters from live session logs — the fix produces the correct
project directory while all edge cases (no user mount, empty mountMap,
host paths, sharedCwdPath precedence) behave correctly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveWorkDir()falls back toos.homedir()for every Cowork session because the Electron app sendscwd=/sessions/{name}(a session-root guest path) andtranslateGuestPath()requires/sessions/{name}/mnt/{mount}/...— the session root never matches.~instead of the user's project directory, breaking file access and context loading.Root Cause
translateGuestPath()uses a regex that requires a/mnt/{mount}component in the path. Session-root paths like/sessions/bold-sharp-clarkedon't have one, so translation always fails. BwrapBackend avoids this by overridingspawn()with its own CWD derivation from the primary user mount. HostBackend goes throughresolveWorkDir()which lacked equivalent logic.Related: #389 (fixed a similar guest-path translation gap for
CLAUDE_COWORK_MEMORY_PATH_OVERRIDE).The Fix
When
translateGuestPath()can't resolve a session-root CWD, derive the working directory from the primary user mount (first non-dotfile, non-uploads key inmountMap) — the same heuristic BwrapBackend uses. Falls back to homedir only when no user mount exists.Verification
Tested with a Node.js harness simulating exact spawn parameters from live session logs:
~/(bug)/home/user/project/(correct)~/~/(correct fallback)Test plan
~/🤖 Generated with Claude Code