Skip to content

fix(hooks): warn when the platform has no sh instead of failing silently - #29

Merged
epodivilov merged 1 commit into
mainfrom
fix/hooks-windows-warning
Jul 22, 2026
Merged

fix(hooks): warn when the platform has no sh instead of failing silently#29
epodivilov merged 1 commit into
mainfrom
fix/hooks-windows-warning

Conversation

@epodivilov

Copy link
Copy Markdown
Owner

Problem

Hook commands are executed as sh -c "<command>". Native Windows has no sh, so Bun.spawn threw, the adapter mapped it to a generic UNKNOWN error, and every configured hook surfaced as Hook failed: "..." - Failed to execute command — once per hook, with no hint about the cause. Windows is a supported target (wt-windows-x64.exe, PowerShell installer), so a documented feature quietly did nothing there.

Change

  • BunShellAdapter resolves sh on PATH once per instance and returns a dedicated SHELL_UNAVAILABLE error when it is missing; the resolved absolute path is used for spawning.
  • Hook call sites (runHooks use case, wt create, wt remove single and parallel paths) recognise that code, emit a single warning naming how many hooks were skipped, and stop attempting the remaining commands.
  • Warnings go through the existing notification/ui.warn channel; the spinner now stops with "Hooks skipped" instead of "Hooks completed".

User-visible on a shell-less platform:

Skipped 2 hook(s): no POSIX shell on PATH — commands are shell strings run via `sh -c`, which native Windows does not provide (run wt from Git Bash or WSL)

Behaviour where sh exists (Linux, macOS, Git Bash, WSL) is unchanged.

Docs

New "Hook Execution Model" section in the README hooks area: hooks are shell strings by design, run through sh -c in the worktree, taken from repo config at the same trust level as package.json scripts — not escaped or sandboxed. It also records the known limitation: native cmd.exe / PowerShell hook execution is not supported and not planned.

Tests

pnpm typecheck && pnpm lint && pnpm test — 520 tests pass. New coverage: adapter detection (missing sh, lookup memoised, success/non-zero exit paths) and the runHooks skip path, including a shell that becomes unavailable mid-run.

@epodivilov
epodivilov marked this pull request as ready for review July 21, 2026 22:04
Hook commands run via `sh -c`, which native Windows does not provide, so
every configured hook failed with an opaque "Failed to execute command".

The shell adapter now resolves `sh` on PATH and returns a dedicated
SHELL_UNAVAILABLE error. Hook call sites report it once, name how many
hooks were skipped, and stop retrying commands that cannot run.

Document the hook execution model in the README, including native
Windows (cmd.exe / PowerShell) as a known limitation.
@epodivilov
epodivilov force-pushed the fix/hooks-windows-warning branch from 666463e to 108c8bd Compare July 21, 2026 22:07
@epodivilov
epodivilov merged commit 04a886d into main Jul 22, 2026
1 check passed
@epodivilov
epodivilov deleted the fix/hooks-windows-warning branch July 22, 2026 07:18
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.

1 participant