opencode icon indicating copy to clipboard operation
opencode copied to clipboard

PATH is not inherited from invoking shell

Open aspiers opened this issue 4 months ago • 5 comments

For example:

$ which node
/home/adam/.nvm/versions/node/v20.19.3/bin/node
$ bun dev  # run opencode

Now if I type !which node into the opencode prompt, I get /usr/bin/node.

aspiers avatar Aug 23 '25 14:08 aspiers

This issue might be a duplicate of existing issues. Please check:

  • #197: Similar issue where opencode doesn't inherit the shell environment from node version managers (Volta in that case vs NVM in this case)

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Aug 23 '25 14:08 github-actions[bot]

Checked - not a duplicate.

aspiers avatar Aug 23 '25 16:08 aspiers

I am also facing this now. I have Volta installed and other manager tool (mise) and in the terminal where I launch opencode, I see that in the $PATH mise is listed before volta, but when I am inside opencode I see that a new entry for volta was added in the beggining of the PATH. Where and why it is adding this ? How can I make it does not add ?

trystan2k avatar Nov 27 '25 15:11 trystan2k

I assume there must be some sort of bug here: https://github.com/sst/opencode/blob/733e5cd876bb0a025bacbbd1aab7f8abf4e957f1/packages/opencode/src/session/prompt.ts#L1221

rekram1-node avatar Dec 02 '25 20:12 rekram1-node

I looked at that code and was surprised to see it source-ing shell startup files like .zshenv, .zshrc, .bashrc in a non-standard way:

  1. Loading .zshenv should be superfluous for zsh, because it will automatically source this anyway.
  2. .zshrc and .bashrc are intended for use in interactive shells only.
  3. Why is it using -l? These are not login shells.

The second point might actually explain the root cause in my case, although I'm not sure of that yet. We already know from #2033 that bun can do strange things with its environment.

aspiers avatar Dec 12 '25 18:12 aspiers