Skip to content

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

@istarkov

Description

@istarkov

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions