-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathinstall-mac.sh
More file actions
executable file
·141 lines (122 loc) · 3.73 KB
/
install-mac.sh
File metadata and controls
executable file
·141 lines (122 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
set -euo pipefail
# Claude Code Cache Fix Installer (macOS)
# Patches cli.js to fix prompt caching bugs that drain Max plan usage.
# Safe to run multiple times. Stock 'claude' is never touched.
#
# Uses patches/apply-patches.py which has regex + semantic fallbacks
# for reliable patching across different minified code versions.
VERSION="2.1.81"
BASE="$HOME/cc-cache-fix"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PATCH_SCRIPT="$SCRIPT_DIR/patches/apply-patches.py"
echo "========================================"
echo " Claude Code Cache Fix Installer"
echo " Target: v${VERSION}"
echo "========================================"
echo ""
# Check for Node.js
if ! command -v node &>/dev/null; then
echo "[!] Node.js not found."
if command -v brew &>/dev/null; then
echo "[*] Installing via Homebrew..."
brew install node
else
echo " Install Node.js first: https://nodejs.org or 'brew install node'"
exit 1
fi
fi
echo "[*] Node.js: $(node --version)"
# Check for npm
if ! command -v npm &>/dev/null; then
echo "[!] npm not found. Install Node.js properly."
exit 1
fi
# Check for python3
if ! command -v python3 &>/dev/null; then
echo "[!] python3 not found. Install Python 3 first."
exit 1
fi
# Check for patch script
if [ ! -f "$PATCH_SCRIPT" ]; then
echo "[!] Patch script not found at: $PATCH_SCRIPT"
echo " Run this script from the repo root."
exit 1
fi
# Check for python3
if ! command -v python3 &>/dev/null; then
echo "[!] python3 not found. Install Python 3 first."
exit 1
fi
# Create project dir
mkdir -p "$BASE"
cd "$BASE"
# Install npm package
CLI="$BASE/node_modules/@anthropic-ai/claude-code/cli.js"
if [ ! -f "$CLI" ]; then
echo "[*] Installing @anthropic-ai/claude-code@${VERSION}..."
npm install "@anthropic-ai/claude-code@${VERSION}"
else
echo "[*] cli.js already installed"
fi
# Backup
if [ ! -f "$CLI.orig" ]; then
echo "[*] Backing up cli.js"
cp "$CLI" "$CLI.orig"
else
echo "[*] Backup exists"
fi
# Restore from backup (idempotent)
echo "[*] Restoring from backup..."
cp "$CLI.orig" "$CLI"
# Apply patches using apply-patches.py (has regex + semantic fallbacks)
echo "[*] Applying patches..."
python3 "$PATCH_SCRIPT" "$CLI"
# Verify it runs
PATCHED_VERSION=$(node "$CLI" --version 2>/dev/null || echo "FAILED")
echo "[*] Patched version: $PATCHED_VERSION"
if [[ "$PATCHED_VERSION" != *"$VERSION"* ]]; then
echo "[!] Version check failed. Restoring backup."
cp "$CLI.orig" "$CLI"
exit 1
fi
# Create wrapper
mkdir -p "$HOME/.local/bin"
WRAPPER="$HOME/.local/bin/claude-patched"
if [ -L "$WRAPPER" ] || [ -f "$WRAPPER" ]; then
rm -f "$WRAPPER"
fi
cat > "$WRAPPER" << WRAPPER_EOF
#!/usr/bin/env bash
exec node "$BASE/node_modules/@anthropic-ai/claude-code/cli.js" "\$@"
WRAPPER_EOF
chmod +x "$WRAPPER"
echo "[*] Created ~/.local/bin/claude-patched"
# Ensure PATH includes ~/.local/bin
SHELL_RC=""
if [ -f "$HOME/.zshrc" ]; then
SHELL_RC="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
SHELL_RC="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_RC="$HOME/.bash_profile"
fi
if [ -n "$SHELL_RC" ]; then
if ! grep -q '.local/bin' "$SHELL_RC" 2>/dev/null; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
echo "[*] Added ~/.local/bin to PATH in $(basename "$SHELL_RC")"
fi
fi
echo ""
echo "========================================"
echo " Done!"
echo ""
echo " Open a new terminal and run:"
echo " claude-patched"
echo ""
echo " All flags work as normal:"
echo " claude-patched --dangerously-skip-permissions"
echo " claude-patched --resume <session-id>"
echo ""
echo " Stock 'claude' command is untouched."
echo "========================================"