Fixing Claude Code in Git Bash
Claude Code fails in Git Bash with path errors like:
Error: /usr/bin/bash: line 1: C:UsersDavid.WeiAppDataLocalTemp/claude-shell-snapshot-6ea5: No such file or directory
Root cause: os.tmpdir()
returns Windows paths, Git Bash expects Unix paths.
Solution: Patch the CLI directly with sed.
# Create ~/bin/c
#!/bin/bash
REAL_CLAUDE=$(which claude)
basedir=$(dirname "$REAL_CLAUDE")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=`cygpath -w "$basedir"`
fi
;;
esac
CLAUDE_DIR="$basedir/node_modules/@anthropic-ai/claude-code"
CLI_FILE="$CLAUDE_DIR/cli.js"
BACKUP_FILE="$CLI_FILE.original"
# Backup once
if [ ! -f "$BACKUP_FILE" ]; then
cp "$CLI_FILE" "$BACKUP_FILE"
fi
# Patch and run
cp "$BACKUP_FILE" "$CLI_FILE"
sed -i 's/\b\w\+\.tmpdir()/\"\/tmp\"/g' "$CLI_FILE"
cd "$CLAUDE_DIR"
exec node "cli.js" "$@"
chmod +x ~/bin/c
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
Now works:
c doctor
c --version
The regex catches minified variable names. Patches fresh every run, so updates don't break it.