Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

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

Lucas Pimentel596983854afd
diff --git a/.claude-plugin/hooks/hooks.json b/.claude-plugin/hooks/hooks.json
index 38d33dfe7..34aa705f9 100644
--- a/.claude-plugin/hooks/hooks.json
+++ b/.claude-plugin/hooks/hooks.json
@@ -5,7 +5,7 @@
"hooks": [
{
"type": "command",
- "command": "wt config state marker set πŸ€– || true"
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/wt.sh\" config state marker set πŸ€– || true"
}
]
}
@@ -16,7 +16,7 @@
"hooks": [
{
"type": "command",
- "command": "wt config state marker set πŸ’¬ || true"
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/wt.sh\" config state marker set πŸ’¬ || true"
}
]
}
@@ -27,7 +27,7 @@
"hooks": [
{
"type": "command",
- "command": "wt config state marker clear || true"
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/wt.sh\" config state marker clear || true"
}
]
}
@@ -37,7 +37,7 @@
"hooks": [
{
"type": "command",
- "command": "jq -r '.name' | xargs -I{} wt switch --create {} --no-cd --format=json | jq -r '.path'"
+ "command": "jq -r '.name' | xargs -I{} bash \"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/wt.sh\" switch --create {} --no-cd --format=json | jq -r '.path'"
}
]
}
@@ -47,7 +47,7 @@
"hooks": [
{
"type": "command",
- "command": "jq -r '.worktree_path' | xargs wt remove -D --foreground"
+ "command": "jq -r '.worktree_path' | xargs bash \"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/wt.sh\" remove -D --foreground"
}
]
}
diff --git a/.claude-plugin/hooks/wt.sh b/.claude-plugin/hooks/wt.sh
new file mode 100755
index 000000000..a7a4a72e1
--- /dev/null
+++ b/.claude-plugin/hooks/wt.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+# Cross-platform wrapper for the worktrunk CLI.
+# If WORKTRUNK_BIN is set, uses that path exclusively.
+# Otherwise, on Windows (MSYS/Cygwin), prefers git-wt.exe over wt and
+# rejects wt if it resolves to Windows Terminal (.../WindowsApps/wt.exe).
+# On other platforms, uses wt directly.
+# Usage: wt.sh [args...]
+
+if [[ -n "$WORKTRUNK_BIN" ]]; then
+ if ! command -v "$WORKTRUNK_BIN" >/dev/null 2>&1; then
+ echo "worktrunk: WORKTRUNK_BIN is set to '$WORKTRUNK_BIN' but it was not found" >&2
+ exit 1
+ fi
+ WT="$WORKTRUNK_BIN"
+elif [[ "$(uname -o 2>/dev/null)" =~ ^(Msys|Cygwin)$ ]]; then
+ # check for bash on Windows (on Windows, Claude Code defaults to Git Bash)
+ if command -v git-wt.exe >/dev/null 2>&1; then
+ # prefer git-wt over wt if available
+ WT=git-wt.exe
+ elif command -v wt >/dev/null 2>&1; then
+ # reject wt if it's the Windows Terminal alias
+ if [[ "$(command -v wt)" == *WindowsApps* ]]; then
+ echo "worktrunk: 'wt' resolves to Windows Terminal; install worktrunk as git-wt.exe or remove the Windows Terminal alias. See https://worktrunk.dev/worktrunk/#install" >&2
+ exit 1
+ fi
+
+ WT=wt
+ fi
+else
+ # non-Windows, always use wt
+ WT=wt
+fi
+
+if [[ -z "$WT" ]] || ! command -v "$WT" >/dev/null 2>&1; then
+ echo "worktrunk: could not find 'wt' in PATH" >&2
+ exit 1
+fi
+
+"$WT" "$@"