Skip to content

Conversation

@istarkov
Copy link
Contributor

@istarkov istarkov commented Oct 28, 2025

For spawn:

  • Nothing changes for windows users.
  • Uses $SHELL env variable - default shell for new sessions if set, othewise fallback on previous /bin/sh behaviour

Fixes #3479

@istarkov istarkov changed the title feat: Use default shell on Unix environments fix: Use default shell on Unix environments Oct 28, 2025
@istarkov istarkov changed the title fix: Use default shell on Unix environments fix: Use default shell to execute bash commands on Unix environments Oct 28, 2025
@veracioux
Copy link
Contributor

veracioux commented Oct 28, 2025

@istarkov @rekram1-node I feel like we should update the system prompt or tool description to tell the LLM what shell will be used. Especially for windows. The tool is called bash after all.

@istarkov
Copy link
Contributor Author

istarkov commented Oct 28, 2025

@istarkov @rekram1-node I feel like we should update the system prompt or tool description to tell the LLM what shell will be used. Especially for windows. The tool is called bash after all.

Probably here

` Platform: ${process.platform}`,

const shellName = (process.env.SHELL || process.env.COMSPEC || (process.platform === 'win32' ? 'cmd.exe' : 'sh'))
  .split(/[\\/]/).pop();
...

Platform: ${process.platform}, Shell: ${shellName}

But I would not touch this until real windows users have reproducible issues, as probably Platform is enough

@rekram1-node
Copy link
Collaborator

Yeah I need to setup a windows environment to test this more and I need to analyze how other tools do it.

the tool name being bash yeah it is confusing for the llm almost certainly

I think we can addresss that separately tho I want to do more investigation before just changing prompts

@istarkov
Copy link
Contributor Author

I have feeling that at the end it will be running bash in some container env. For reasons like prevent any operation out of project folder etc.

@rekram1-node
Copy link
Collaborator

rekram1-node commented Oct 28, 2025

@istarkov for those who use things like nunshell or fish, I wonder if this change could actually make their experience worse

We could just also try a check if they have bash installed and use that, but i suppose using the users shell offers some benefits and then it does come back to tool descriptions & names

This looks good, I will merge soon just wanna think more about how we can best serve everyone

@rekram1-node
Copy link
Collaborator

Given the tool is called bash, almost all unix users have bash, and a lot of windows users have git bash, and the prompts are all about bash, should we just do shell: "bash" if bash is installed? I feel like that's the safest bet here

@istarkov
Copy link
Contributor Author

istarkov commented Oct 31, 2025

I have few reasons why current approach is better:

    1. Default bash on mac is outdated and usually need to be changed with GNU bash
      Default shell on mac - zsh is modern and more compatible with GNU bash vs the default mac bash.
    1. As a developer I usually check issues with my current terminal and shell, and this is tool for developers ;-)

macOS /bin/bash (3.2) 2007 (18+ years old) ;-)

@rekram1-node
Copy link
Collaborator

i tend to agree, im just cautious, lemme test something with fish and nushell

@keathmilligan
Copy link
Contributor

I suggest it respect SHELL on Windows as well to enable compatibility with Git Bash / MINGW. As it is on Windows, it uses cmd.exe even if you launch from bash. SHELL won't typically be set in cmd/powershell sessions. Or alternatively, make it configurable.

@rekram1-node
Copy link
Collaborator

/oc use $SHELL if it is set, otherwise use shell: true remove the windows check

@opencode-agent
Copy link
Contributor

opencode-agent bot commented Nov 21, 2025

Perfect! I've successfully implemented the requested changes:

  1. Removed the Windows check - The conditional logic based on process.platform === "win32" has been removed
  2. Use $SHELL if set - Now uses process.env.SHELL as the first preference
  3. Otherwise use shell: true - Falls back to true (default shell behavior) when $SHELL is not set

The change simplifies the shell configuration to a single line: shell: process.env.SHELL ?? true, which will:

  • Use the user's default shell from the $SHELL environment variable if it's set
  • Fall back to Node.js's default shell behavior (shell: true) if $SHELL is not set

This approach works consistently across all platforms (Windows, macOS, Linux) and respects the user's preferred shell when available.

New%20session%20-%202025-11-21T20%3A31%3A28.724Z
opencode session  |  github run

@rekram1-node rekram1-node changed the title fix: Use default shell to execute bash commands on Unix environments fix: make bash tool respect $SHELL Nov 21, 2025
@rekram1-node rekram1-node merged commit b5d0c56 into sst:dev Nov 21, 2025
3 checks passed
@veracioux
Copy link
Contributor

Will the LLM know which shell the bash tool will use?

@rekram1-node
Copy link
Collaborator

nope, but i looked at some other tools and im gonna pass over this and change some things.

I wonder if we should rename the tool to something else tho (thats a later thing tho)

@Ninja3047
Copy link
Contributor

Ninja3047 commented Nov 21, 2025

This seems like a downgrade for non bash shell users
Maybe it would be better to look for $BASH_SHELL that the user can set or something and then have some logic on MacOS/Windows to look for brew's bash and git bash.
Claude code handles this on windows by requesting the user set a different environment variable to the location of git bash so it doesn't interfere with the user's current shell

@rekram1-node
Copy link
Collaborator

yeah im doing a pass to fix this I didn't want it to be released already lol

@rekram1-node
Copy link
Collaborator

@Ninja3047 i was thinking something like this, seems to be similar to how the other coding agents do it:

  const shell = iife(() => {
    const s = process.env.SHELL
    if (s) {
      if (!new Set(["/bin/fish", "/bin/nu", "/usr/bin/fish", "/usr/bin/nu"]).has(s)) {
        return s
      }
    }

    if (process.platform === "darwin") {
      return "/bin/zsh"
    }

    if (process.platform === "win32") {
      return "C:\\Windows\\System32\\cmd.exe"
    }

    return true
  })

@Ninja3047
Copy link
Contributor

Windows should probably default to something more bash compatible since the agent will likely be very confused.

Claude code for example expects you to have git bash and will not work with cmd.exe so checking default git bash install locations might be a better default.

@rekram1-node
Copy link
Collaborator

Yeah good point, tho I noticed the other tools let u use powershell and stuff so maybe we should just rename the tool or something.

This is a good fix for now tho Ill make it do that

@veracioux
Copy link
Contributor

veracioux commented Nov 21, 2025

@Ninja3047 IMO I don't see any reason to restrict the user not to be able to use whatever shell the user has available. @rekram1-node I agree that renaming the tool might be a good idea but in any case I think the agent should be informed beforehand what shell the tool is gonna invoke in the end.

I'm talking as a fish user myself.


Nevermind this makes no sense :D - Aiden's proposed fix is good.

@Ninja3047
Copy link
Contributor

Yes but that would require a new prompt and/or tool at least
The bash tool should use bash or something bash compatible (if the user wants to set BASH_SHELL to something that isn't bash, I guess they are free to do so at the risk of higher rates of tool calls potentially failing.
Older or smaller models will probably find it difficult to get the syntax for fish correct especially since it's changed a few times over the past couple years so the prompt should probably have some guide to the version of fish being used.

@rekram1-node
Copy link
Collaborator

I think we do a follow up for that...

Im just gonna do this for now:
adf7df0

Preserves old behavior if u use random shells

@rekram1-node
Copy link
Collaborator

But I did like what you said about git bash, this does some stuff but maybe we need to search install locations too to be safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants