From e39044e2fb616d45a06e5e092dc122931eb45558 Mon Sep 17 00:00:00 2001 From: Divit Kashyap <162712154+divitkashyap@users.noreply.github.com> Date: Sun, 24 May 2026 13:32:53 +0100 Subject: [PATCH] fix(shell): ensure standard PATH directories on macOS On macOS, the shell tool may launch with an incomplete PATH that does not include /opt/homebrew/bin, causing common commands like git and gh to fail with 'env: sh: No such file or directory'. Prepend the standard macOS PATH directories (/opt/homebrew/bin, /usr/local/bin, /usr/bin, /bin) to the shell environment when they are missing, matching what a user's interactive shell would see. Refs #17792 --- packages/opencode/src/tool/shell.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/tool/shell.ts b/packages/opencode/src/tool/shell.ts index b6a95b5c0970..4b94a5ca10ca 100644 --- a/packages/opencode/src/tool/shell.ts +++ b/packages/opencode/src/tool/shell.ts @@ -415,10 +415,20 @@ export const ShellTool = Tool.define( { cwd, sessionID: ctx.sessionID, callID: ctx.callID }, { env: {} }, ) - return { + const env: NodeJS.ProcessEnv = { ...process.env, ...extra.env, } + if (process.platform === "darwin") { + const standardPaths = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"] + const currentPath = env.PATH ?? "" + const existingPaths = currentPath.split(path.delimiter) + const missingPaths = standardPaths.filter((p) => !existingPaths.includes(p)) + if (missingPaths.length > 0) { + env.PATH = [...missingPaths, ...(currentPath ? currentPath.split(path.delimiter) : [])].join(path.delimiter) + } + } + return env }) const run = Effect.fn("ShellTool.run")(function* (