Skip to content

fix: use cross-platform wrapper for wt CLI in Claude Code integration#1754

Draft
lucaspimentel wants to merge 13 commits intomax-sixty:mainfrom
lucaspimentel:main
Draft

fix: use cross-platform wrapper for wt CLI in Claude Code integration#1754
lucaspimentel wants to merge 13 commits intomax-sixty:mainfrom
lucaspimentel:main

Conversation

@lucaspimentel
Copy link
Copy Markdown

@lucaspimentel lucaspimentel commented Mar 26, 2026

Summary

Currently, Worktrunk's Claude Code hook keeps opening Windows Terminal windows because it calls wt, which is an alias ~/AppData/Local/Microsoft/WindowsApps/wt.exe by default.

Windows users have three workarounds:

  • install Worktrunk as git-wt.exe
  • install Worktrunk as wt.exe and disable the Windows Terminal alias to avoid conflicts
  • install Worktrunk as wt.exe and re-order the paths in PATH so Worktrunk is found first

Changes

  • Add a wt.sh wrapper script that tries to find the correct Worktrunk binary.
  • Update hooks.json to use wt.sh.
  • Bump the plugin version.

Manual tests

Windows

  • Worktrunk installed as git-wt.exe, Windows Terminal alias enabled
  • Worktrunk installed as git-wt.exe, Windows Terminal alias disabled
  • Worktrunk installed as wt.exe, Windows Terminal alias enabled
  • Worktrunk installed as wt.exe, Windows Terminal alias disabled
  • Worktrunk not installed, Windows Terminal alias enabled
  • Worktrunk not installed, Windows Terminal alias disabled

WSL (Windows Subsystem for Linux)

In WSL, users can install the Linux version of Worktree as wt, but wt can still map to Windows Terminal if Worktree is not installed.

  • Worktrunk installed as wt in WSL, Windows Terminal alias enabled
  • Worktrunk installed as wt in WSL, Windows Terminal alias disabled
  • Worktrunk not installed, Windows Terminal alias enabled
  • Worktrunk not installed, Windows Terminal alias disabled

On Windows the binary is git-wt.exe, not wt. Add a wt.sh wrapper
script that detects the platform and calls the correct binary, then
update hooks.json to use it via ${CLAUDE_PLUGIN_ROOT}.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
@lucaspimentel lucaspimentel changed the title fix: use cross-platform wrapper for wt CLI in plugin hooks fix: use cross-platform wrapper for wt CLI in Claude Code integration Mar 26, 2026
@max-sixty
Copy link
Copy Markdown
Owner

thanks!

can we have it fall back to wt if git-wt doesn't exist? some people deactivate wt in windows

(unless there's some non-convoluted way to detect that wt is Windows Terminal — that would be ideal — @worktrunk-bot research any ideas!)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9be3764104

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@worktrunk-bot
Copy link
Copy Markdown
Collaborator

A few options for detecting Windows Terminal's wt:

  1. Path check — Windows Terminal lives at */WindowsApps/wt.exe. On MSYS/Cygwin, command -v wt or which wt would resolve to that path. If it contains WindowsApps, it's Windows Terminal.

  2. Try git-wt first, fall back to wt — simplest approach that covers both cases (Windows with git-wt installed, and Windows where someone disabled the WT alias):

case "$(uname -o 2>/dev/null)" in
    Msys|Cygwin)
        if command -v git-wt.exe >/dev/null 2>&1; then
            WT=git-wt.exe
        else
            WT=wt
        fi
        ;;
    *) WT=wt ;;
esac
  1. Hybrid — try git-wt first, fall back to wt only if it doesn't resolve to WindowsApps:
case "$(uname -o 2>/dev/null)" in
    Msys|Cygwin)
        if command -v git-wt.exe >/dev/null 2>&1; then
            WT=git-wt.exe
        elif command -v wt >/dev/null 2>&1 && ! command -v wt 2>/dev/null | grep -qi WindowsApps; then
            WT=wt
        else
            echo "worktrunk not found — install with: cargo install worktrunk --features git-wt" >&2
            exit 1
        fi
        ;;
    *) WT=wt ;;
esac

Option 2 seems like the right balance — simple, handles the "deactivated wt" case, and the worst that happens if someone only has Windows Terminal's wt is a confusing error (new terminal window opens) which is the same behavior they'd get without the wrapper. Option 3 adds detection but more complexity for an edge case.

@lucaspimentel what do you think — want to go with option 2 (fallback) or 3 (with WindowsApps detection)?

@lucaspimentel
Copy link
Copy Markdown
Author

@worktrunk-bot can we combine both checks? "if (is windows) AND (git-wt.exe exists), then use git-wt.exe, else use wt"

On Windows, try git-wt.exe first and fall back to wt if it doesn't
exist. This handles users who have deactivated the wt alias.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@worktrunk-bot
Copy link
Copy Markdown
Collaborator

Done — pushed a commit that does exactly that: on Windows, tries git-wt.exe first via command -v, falls back to wt if it's not found. Non-Windows platforms still use wt as before.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
Check that `wt` doesn't resolve to the WindowsApps directory before
using it as a fallback, since that path is the Windows Terminal alias.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@worktrunk-bot worktrunk-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WindowsApps detection on line 11 works, but the ${WT:=wt} default on line 16 undoes it: when git-wt.exe is absent and wt is Windows Terminal, neither branch sets WT, so the default still invokes Windows Terminal — the exact bug this PR fixes.

Co-authored-by: worktrunk-bot <w@worktrunk.dev>
Copy link
Copy Markdown
Collaborator

@worktrunk-bot worktrunk-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows Terminal detection logic looks good now. One bug: the final invocation line is duplicated, so every hook command will execute twice.

@max-sixty
Copy link
Copy Markdown
Owner

@lucaspimentel would you mind running this for a day or so to confirm it behaves well? It's difficult to test this stuff...

@lucaspimentel
Copy link
Copy Markdown
Author

lucaspimentel commented Mar 26, 2026

@max-sixty definitely. I opened the PR too quickly (edit: the fix wasn't as simple as I originally thought) 😅 I'll convert it to a draft while I keep testing. worktrunk-bot and I keep finding edge cases.

@lucaspimentel lucaspimentel marked this pull request as draft March 26, 2026 20:16
Remove OS-specific branching — git-wt.exe check is harmless on
non-Windows. Add missing PATH validation and distinct error for
Windows Terminal alias vs not-found cases.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
@max-sixty
Copy link
Copy Markdown
Owner

thank you v much @lucaspimentel !

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
The UserPromptSubmit hook runs on every prompt, including outside git
repos. Guard against missing git and non-repo directories to prevent
"fatal: not a git repository" stderr noise in Claude Code.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
Comment on lines +10 to +12
if ! command -v git >/dev/null 2>&1 || ! git rev-parse --git-dir >/dev/null 2>&1; then
exit 0
fi
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw if wt can handle it, then I think it's better that we put the logic in the binary than a bash file...

lucaspimentel and others added 2 commits March 27, 2026 15:45
When set, use WORKTRUNK_BIN exclusively to find the worktrunk binary
instead of searching PATH. Fail with a clear error if not found.

🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

3 participants