Opencode bash tool spawn user commands using /bin/sh what is not bash :-) #2301

Closed
opened 2026-02-16 17:35:02 -05:00 by yindo · 3 comments
Owner

Originally created by @istarkov on GitHub (Oct 27, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

The issue seems like is in the following lines

https://github.com/sst/opencode/blob/dev/packages/opencode/src/tool/bash.ts#L149-L154

Here - shell: true

**shell **- If true, runs command inside of a shell. Uses '/bin/sh' on Unix, and process.env.ComSpec on Windows. A different shell can be specified as a string.

I'm expecting from bash tools to execute at least bash, or default process.env.SHELL but sh feels pretty outdated for me.

Something like this feels more suitable (or check bash existance and use it if it exists in the PATH)

const defaultShell = process.platform === "win32"
  ? true // process.env.ComSpec on Windows
  : process.env.SHELL ?? true // $SHELL - *default shell for new sessions* if set, otherwise /bun/sh

const proc = spawn(params.command, {
  // use the user's login shell (or sensible fallback) rather than the system /bin/sh default
  shell: defaultShell,
  cwd: Instance.directory,
  stdio: ["ignore", "pipe", "pipe"],
  detached: process.platform !== "win32",
})

OpenCode version

0.15.18

Steps to reproduce

In opencode write following prompt


Run following bash command

pid=$$
echo "$(ps -p "$pid" -o comm=)"

The result is

/bin/sh on linux


Screenshot and/or share link

Share links doesn't work for me for unknown reason

Operating System

MacOs

Terminal

ITERM 2

Originally created by @istarkov on GitHub (Oct 27, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description The issue seems like is in the following lines https://github.com/sst/opencode/blob/dev/packages/opencode/src/tool/bash.ts#L149-L154 Here - `shell: true` > **shell **- If true, runs command inside of a shell. Uses '/bin/sh' on Unix, and process.env.ComSpec on Windows. A different shell can be specified as a string. I'm expecting from bash tools to execute at least bash, or default `process.env.SHELL` but `sh` feels pretty outdated for me. Something like this feels more suitable (or check bash existance and use it if it exists in the PATH) ```ts const defaultShell = process.platform === "win32" ? true // process.env.ComSpec on Windows : process.env.SHELL ?? true // $SHELL - *default shell for new sessions* if set, otherwise /bun/sh const proc = spawn(params.command, { // use the user's login shell (or sensible fallback) rather than the system /bin/sh default shell: defaultShell, cwd: Instance.directory, stdio: ["ignore", "pipe", "pipe"], detached: process.platform !== "win32", }) ``` ### OpenCode version 0.15.18 ### Steps to reproduce In opencode write following prompt --- Run following bash command ``` pid=$$ echo "$(ps -p "$pid" -o comm=)" ``` The result is `/bin/sh` on linux --- ### Screenshot and/or share link Share links doesn't work for me for unknown reason ### Operating System MacOs ### Terminal ITERM 2
yindo added the bug label 2026-02-16 17:35:02 -05:00
yindo closed this issue 2026-02-16 17:35:02 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 27, 2025):

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

  • #2202: PATH is not inherited from invoking shell - addresses the same underlying problem where OpenCode uses /bin/sh instead of respecting the user's shell environment
  • #3228: [Feature] Allow the user to run their favorite shell in opencode - broader feature request that would solve this issue by allowing shell configuration

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

@github-actions[bot] commented on GitHub (Oct 27, 2025): This issue might be a duplicate of existing issues. Please check: - #2202: PATH is not inherited from invoking shell - addresses the same underlying problem where OpenCode uses /bin/sh instead of respecting the user's shell environment - #3228: [Feature] Allow the user to run their favorite shell in opencode - broader feature request that would solve this issue by allowing shell configuration Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 27, 2025):

yeah this is good point

@rekram1-node commented on GitHub (Oct 27, 2025): yeah this is good point
Author
Owner

@SamSpiri commented on GitHub (Nov 18, 2025):

A tool is called literally "bash". When AI is calling it with bash code it often fails, because it prepares bash code, but it is being executed with sh.

@SamSpiri commented on GitHub (Nov 18, 2025): A tool is called literally "bash". When AI is calling it with bash code it often fails, because it prepares bash code, but it is being executed with sh.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2301