@@ -35,7 +35,7 @@ install_native() {
3535 # Patch installer to add --force flag if needed (handles network timeouts)
3636 if [ " $use_force " = " force" ]; then
3737 echo " [claude] Using --force to bypass network checks..." >&2
38- sed -i ' s/\$binary_path" install/\$binary_path" install --force/' " $installer_script "
38+ sed -i ' s/" \$binary_path" install/" \$binary_path" install --force/' " $installer_script "
3939 fi
4040
4141 # Run installer with optional version
@@ -50,23 +50,14 @@ install_native() {
5050 return 0
5151 fi
5252
53- # If failed without force, retry with force and explicit version
54- if [ " $use_force " != " force" ]; then
55- echo " [claude] Installer failed, retrying with --force..." >&2
56- local github_version
57- github_version=$( get_latest_version)
58- if [ -n " $github_version " ]; then
59- echo " [claude] Using version from GitHub: $github_version " >&2
60- # Patch to add --force
61- sed -i ' s/\$binary_path" install/\$binary_path" install --force/' " $installer_script "
62- if bash " $installer_script " " $github_version " ; then
63- rm -f " $installer_script "
64- return 0
65- fi
66- fi
53+ # If failed, try direct binary download as final fallback
54+ echo " [claude] Native installer failed, trying direct download..." >&2
55+ rm -f " $installer_script "
56+
57+ if install_direct; then
58+ return 0
6759 fi
6860
69- rm -f " $installer_script "
7061 return 1
7162 fi
7263
@@ -109,6 +100,70 @@ get_latest_version() {
109100 " https://github.com/anthropics/claude-code/releases/latest" 2> /dev/null | awk -F' /' ' {print $NF}' | sed ' s/^v//'
110101}
111102
103+ # Direct binary download (fallback when installer has network issues)
104+ install_direct () {
105+ local version=" ${1:- } "
106+ if [ -z " $version " ]; then
107+ version=$( get_latest_version)
108+ fi
109+
110+ if [ -z " $version " ]; then
111+ echo " [claude] Could not determine version" >&2
112+ return 1
113+ fi
114+
115+ echo " [claude] Direct binary download (bypassing installer)..." >&2
116+
117+ local GCS_BUCKET=" https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases"
118+
119+ # Detect platform
120+ local os arch platform
121+ case " $( uname -s) " in
122+ Darwin) os=" darwin" ;;
123+ Linux) os=" linux" ;;
124+ * ) echo " [claude] Unsupported OS" >&2 ; return 1 ;;
125+ esac
126+
127+ case " $( uname -m) " in
128+ x86_64|amd64) arch=" x64" ;;
129+ arm64|aarch64) arch=" arm64" ;;
130+ * ) echo " [claude] Unsupported architecture: $( uname -m) " >&2 ; return 1 ;;
131+ esac
132+
133+ # Check for musl on Linux
134+ if [ " $os " = " linux" ]; then
135+ if [ -f /lib/libc.musl-x86_64.so.1 ] || [ -f /lib/libc.musl-aarch64.so.1 ] || ldd /bin/ls 2>&1 | grep -q musl; then
136+ platform=" linux-${arch} -musl"
137+ else
138+ platform=" linux-${arch} "
139+ fi
140+ else
141+ platform=" ${os} -${arch} "
142+ fi
143+
144+ echo " [claude] Downloading v${version} for ${platform} ..." >&2
145+
146+ # Download to ~/.local/bin
147+ mkdir -p ~ /.local/bin
148+ if ! curl -fsSL " $GCS_BUCKET /$version /$platform /claude" -o ~ /.local/bin/claude; then
149+ echo " [claude] Download failed" >&2
150+ return 1
151+ fi
152+
153+ chmod +x ~ /.local/bin/claude
154+
155+ # Verify it works
156+ if ~ /.local/bin/claude --version > /dev/null 2>&1 ; then
157+ echo " [claude] Installed to ~/.local/bin/claude" >&2
158+ echo " [claude] Make sure ~/.local/bin is in your PATH" >&2
159+ return 0
160+ else
161+ echo " [claude] Binary verification failed" >&2
162+ rm -f ~ /.local/bin/claude
163+ return 1
164+ fi
165+ }
166+
112167# Compare versions (returns 0 if v1 < v2)
113168version_lt () {
114169 [ " $( printf ' %s\n%s' " $1 " " $2 " | sort -V | head -1) " = " $1 " ] && [ " $1 " != " $2 " ]
0 commit comments