Skip to content

Commit 9ab3b02

Browse files
fix(hooks): expand tilde in cd path before directory check
[ -d "~/path" ] doesn't expand tilde inside quotes, causing cross-repo commits using ~/path syntax to silently drop TARGET_DIR and fall back to the starter kit CWD (main), triggering a false branch block. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a364e88 commit 9ab3b02

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

.claude/hooks/check-branch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ fi
3535
# Extract the first cd target from commands like "cd /path && git ..."
3636
if [ -z "$TARGET_DIR" ] && echo "$COMMAND" | grep -qE '^cd\s+[^ ]+'; then
3737
CD_DIR=$(echo "$COMMAND" | sed -nE 's/^cd\s+([^ &;]+).*/\1/p' | head -1)
38+
# Expand leading tilde — [ -d "~/path" ] doesn't expand tilde inside quotes
39+
CD_DIR="${CD_DIR/#\~/$HOME}"
3840
if [ -n "$CD_DIR" ] && [ -d "$CD_DIR" ]; then
3941
TARGET_DIR="$CD_DIR"
4042
fi

0 commit comments

Comments
 (0)