{"record":{"id":"c34575435e55105d","repo":"ultraworkers/claw-code","slug":"powershell-executable-not-found-expected-pwsh-o","errorCode":null,"errorMessage":"PowerShell executable not found (expected `pwsh` or `powershell` in PATH)","messagePattern":"PowerShell executable not found \\(expected `pwsh` or `powershell` in PATH\\)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust/crates/tools/src/lib.rs","lineNumber":6586,"sourceCode":"    if let Some(output) = workspace_test_branch_preflight(&input.command) {\n        return Ok(output);\n    }\n    let shell = detect_powershell_shell()?;\n    execute_shell_command(\n        shell,\n        &input.command,\n        input.timeout,\n        input.run_in_background,\n    )\n}\n\nfn detect_powershell_shell() -> std::io::Result<&'static str> {\n    if command_exists(\"pwsh\") {\n        Ok(\"pwsh\")\n    } else if command_exists(\"powershell\") {\n        Ok(\"powershell\")\n    } else {\n        Err(std::io::Error::new(\n            std::io::ErrorKind::NotFound,\n            \"PowerShell executable not found (expected `pwsh` or `powershell` in PATH)\",\n        ))\n    }\n}\n\nfn command_exists(command: &str) -> bool {\n    std::process::Command::new(\"sh\")\n        .arg(\"-lc\")\n        .arg(format!(\"command -v {command} >/dev/null 2>&1\"))\n        .status()\n        .is_ok_and(|status| status.success())\n}\n\n#[allow(clippy::too_many_lines)]\nfn execute_shell_command(\n    shell: &str,\n    command: &str,","sourceCodeStart":6568,"sourceCodeEnd":6604,"githubUrl":"https://github.com/ultraworkers/claw-code/blob/08106b0c3771ef5b4a5aa176acccd460e88b7325/rust/crates/tools/src/lib.rs#L6568-L6604","documentation":"Returned by detect_powershell_shell in the tools crate when neither pwsh nor powershell can be found. Note the implementation probes via command_exists(), which runs `sh -lc 'command -v <name> >/dev/null 2>&1'` — so detection requires a POSIX sh, and it only sees executables on the PATH that sh inherits. The error is io::Error with ErrorKind::NotFound.","triggerScenarios":"Invoking the PowerShell-capable shell tool (the Bash-tool family entry point at tools/lib.rs:6580 that dispatches to detect_powershell_shell) on a Linux box with no PowerShell installed, or anywhere PATH does not contain pwsh/powershell (container images, minimal CI runners, nix shells without the powershell package). Also on Windows hosts lacking a POSIX sh, since the probe itself runs through `sh -lc`.","commonSituations":"Debian/Ubuntu/Alpine containers without powershell installed; macOS without brew install powershell; CI runners where PowerShell is present but not on the PATH that sh -l resolves (login-shell PATH rewriting); asking the agent to run a PowerShell command by mistake on a Linux host.","solutions":["Install PowerShell and verify the probe can see it: pwsh --version, or command -v pwsh inside `sh -l` (login shell) since that is exactly how detection runs","Fix PATH so the login shell resolves pwsh: export PATH=\"$PATH:/usr/bin\" with a symlink, or add the install dir to /etc/profile.d if sh -l strips it","Don't request PowerShell on hosts without it — use the default bash/sh shell tool instead","For Windows targets, install PowerShell 7 (pwsh) so the fallback to powershell.exe is unnecessary"],"exampleFix":"# before\nclaw> run in powershell: Get-Location   # -> NotFound: PowerShell executable not found\n\n# after (Ubuntu)\nsudo apt-get install -y powershell     # or: brew install powershell on macOS\nsh -lc 'command -v pwsh'               # verify the exact probe detection uses\nclaw> run in powershell: Get-Location","handlingStrategy":"fallback","validationCode":"fn powershell_available() -> bool {\n    // mirrors detect_powershell_shell's probe exactly: sh -lc 'command -v ...'\n    [\"pwsh\", \"powershell\"].iter().any(|cmd| {\n        std::process::Command::new(\"sh\")\n            .arg(\"-lc\")\n            .arg(format!(\"command -v {cmd} >/dev/null 2>&1\"))\n            .status()\n            .is_ok_and(|s| s.success())\n    })\n}\n\nif !powershell_available() { /* route to bash/sh tool instead */ }","typeGuard":"fn detect_shell() -> &'static str {\n    if powershell_available() { \"pwsh\" } else { \"bash\" }\n}","tryCatchPattern":"match detect_powershell_shell() {\n    Ok(shell) => run_in_shell(shell, command),\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        // fall back to the POSIX shell tool; PowerShell is simply absent\n        run_in_shell(\"bash\", command)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Verify with the exact probe the tool uses: sh -lc 'command -v pwsh' — a plain `pwsh` in your interactive shell can succeed while the login-shell PATH differs","Install PowerShell on hosts that must run PS commands (apt/brew install powershell) and ensure it lands on the login-shell PATH","Default agent prompts to bash/sh unless the task genuinely needs PowerShell"],"tags":["powershell","shell-tool","path","not-found","rust"],"backgroundTag":"executable-not-found-in-path","analyzedSha":"08106b0c3771ef5b4a5aa176acccd460e88b7325","analyzedAt":"2026-08-18T00:29:38.590Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}