sync: auto-sync from DESKTOP-0O8A1RL at 2026-05-21 17:00:27
Author: Mike Swanson Machine: DESKTOP-0O8A1RL Timestamp: 2026-05-21 17:00:27
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pre-tool hook: block Windows backslash paths in Bash commands.
|
||||
#
|
||||
# Blocks patterns like C:\Users\foo passed inside Bash command strings.
|
||||
# Enforces forward slashes: C:/Users/foo
|
||||
#
|
||||
# Why: Git Bash mangles backslash paths — C:\tmp writes to a different
|
||||
# directory than the Write tool's C:\tmp, causing stale payload bugs.
|
||||
|
||||
input=$(cat)
|
||||
cmd=$(echo "$input" | jq -r '.tool_input.command // ""' 2>/dev/null)
|
||||
|
||||
# Match a drive letter followed by a literal backslash in the command.
|
||||
# In the extracted command string (not JSON-escaped), backslash is just \.
|
||||
if echo "$cmd" | grep -qE '[A-Za-z]:\\[A-Za-z/\\]'; then
|
||||
echo "BLOCKED: Use forward slashes for Windows paths in Bash commands."
|
||||
echo ""
|
||||
echo " Wrong: C:\\Users\\guru\\file.txt"
|
||||
echo " Correct: C:/Users/guru/file.txt"
|
||||
echo ""
|
||||
echo "Git Bash converts backslash paths unpredictably. PowerShell and Windows"
|
||||
echo "APIs both accept forward slashes without issue."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -58,21 +58,6 @@ urllib.request.urlopen(req)
|
||||
"
|
||||
```
|
||||
|
||||
## Sending HTTP requests via Python (avoids backslash hook)
|
||||
|
||||
The pre-bash-backslash hook blocks commands with Windows-style backslash paths. Python's `urllib.request` is a clean alternative to curl for sending POST requests that include backslash-containing paths in the payload:
|
||||
|
||||
```bash
|
||||
py -c "
|
||||
import urllib.request, json
|
||||
url = 'http://172.16.3.30:8001/api/coord/messages'
|
||||
data = json.dumps({'to_session': 'target', 'body': 'message'}).encode()
|
||||
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})
|
||||
resp = urllib.request.urlopen(req)
|
||||
print(resp.status, resp.read())
|
||||
"
|
||||
```
|
||||
|
||||
## Unicode in log files
|
||||
|
||||
When reading log files that may contain non-UTF8 bytes (Windows logs, PowerShell output):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: windows-openssh
|
||||
description: Use system OpenSSH (bare `ssh`); never Git for Windows SSH; the backslash hook blocks full Windows paths
|
||||
description: Use system OpenSSH (bare `ssh`); never Git for Windows SSH; use forward slashes for all Windows paths in Git Bash
|
||||
applies-to: all
|
||||
---
|
||||
|
||||
@@ -17,24 +17,18 @@ Do not use Git for Windows SSH (`C:\Program Files\Git\usr\bin\ssh.exe`). The sys
|
||||
|
||||
## Use bare `ssh`, not the full path
|
||||
|
||||
The pre-bash-backslash hook at `.claude/hooks/pre-bash-backslash.sh` blocks any Bash command that contains Windows-style backslash paths (e.g., `C:\Windows\System32\OpenSSH\ssh.exe`). This hook exists to prevent accidental backslash path usage in Git Bash, which interprets `\` as escape sequences.
|
||||
|
||||
The system OpenSSH is on `PATH` in Git Bash, so use the bare command:
|
||||
The system OpenSSH is on `PATH` in Git Bash, so prefer the bare command. Always use forward slashes for any Windows path you do pass explicitly — Git Bash interprets backslashes as escape sequences.
|
||||
|
||||
```bash
|
||||
# Correct — uses system OpenSSH via PATH
|
||||
ssh guru@172.16.3.30 "sudo /opt/gururmm/build-server.sh"
|
||||
ssh -i C:/Users/guru/.ssh/id_ed25519 guru@172.16.3.30 "command"
|
||||
|
||||
# Wrong — full backslash path blocked by hook
|
||||
C:\Windows\System32\OpenSSH\ssh.exe guru@172.16.3.30 "command"
|
||||
```
|
||||
|
||||
Note: forward-slash paths are fine in Git Bash:
|
||||
```bash
|
||||
# This works (forward slashes)
|
||||
# Also correct — forward slashes in full path
|
||||
"C:/Windows/System32/OpenSSH/ssh.exe" guru@172.16.3.30 "command"
|
||||
# But bare ssh is simpler and preferred
|
||||
|
||||
# Wrong — backslash path breaks in Git Bash
|
||||
C:\Windows\System32\OpenSSH\ssh.exe guru@172.16.3.30 "command"
|
||||
```
|
||||
|
||||
## Key file paths
|
||||
|
||||
Reference in New Issue
Block a user