GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(cli): trust $PWD only when it matches the process cwd by b-g-d · Pull Request #59368 · anomalyco/opencode

Conversation

@b-g-d

@b-g-d b-g-d commented Oct 26, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #56386

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The CLI resolved its root as process.env.PWD ?? process.cwd(). Shells set PWD on cd and child processes inherit it unchanged, so anything that spawns the CLI with a different working directory — systemd WorkingDirectory, subprocess(cwd=...), an editor integration — leaves a stale PWD behind and the session attaches to the wrong project.

I hit this from a test harness: the agent edited files in the parent repo instead of the checkout I pointed it at, reported success, and the next run then passed against the already-modified files.

PWD is preferred here for a reason — process.cwd() resolves symlinks, so cd /tmp/x on macOS would otherwise display /private/tmp/x. This keeps that behaviour and only falls back to cwd when PWD no longer refers to the directory the process is actually in. Same three call sites as #27583, which dropped PWD entirely and was auto-closed for inactivity.

How did you verify your code works?

bun test test/working-directory.test.ts from packages/cli — four cases: PWD unset, PWD reaching cwd through a symlink, stale PWD inherited from a parent, and a deleted PWD. Two of the four fail against the old one-liner, so the test is a real regression guard. bun run typecheck:tsc is clean.

I did not run the issue's end-to-end repro against a source build: bun run build requires bun >= 1.4.4 and I'm on 1.3.5. The underlying bug was reproduced with the shipped binary.

Screenshots / recordings

N/A — headless CLI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@b-g-d @claude
fix(cli): trust $PWD only when it matches the process cwd
3a44201
The CLI resolved its root as `process.env.PWD ?? process.cwd()`. PWD is a
shell convention — shells set it on cd, and child processes inherit it
verbatim — so any caller that spawns opencode with a different working
directory (systemd WorkingDirectory, subprocess(cwd=...), an editor
integration, a test harness) leaves a stale PWD behind and the session
attaches to the parent's project instead.

PWD is preferred here for a reason: process.cwd() resolves symlinks, so
`cd /tmp/project` on macOS would otherwise display /private/tmp/project.
This keeps that behaviour and only ignores PWD when it no longer refers
to the directory the process is actually in.

Fixes anomalyco#56386

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@opencode-agent opencode-agent Bot closed this Oct 26, 2026
@opencode-agent

opencode-agent Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for the clear write-up and the regression test! I think this duplicates #56389, which also closes #56386 by changing the same three places (mini.ts, run/run.ts, run/v1.ts) so a stale inherited PWD no longer sets the root. That PR is still active and someone else has already confirmed it works.

One real difference in your version is that it keeps $PWD when it resolves to the same directory as process.cwd(). That preserves the symlinked path the user typed (e.g. /tmp/x vs /private/tmp/x on macOS), which #56389 loses by always using process.cwd(). If you think that matters, please raise it on #56389, for example by suggesting your workingDirectory() helper and its symlink test cases there.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 5, 2026
cli: run resolves the workspace from $PWD instead of the process cwd (still on 2.0.32) #56386
Open
fix(cli): use process cwd for run root #56389
Closed
@opencodejr opencodejr Bot mentioned this pull request Nov 9, 2026
opencode run ignores the caller's cwd and executes in the active TUI session's project directory; no way to set a directory for run #62814
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

cli: run resolves the workspace from $PWD instead of the process cwd (still on 2.0.32)

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@b-g-d
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.