forked from nicedreamzapp/claude-code-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·190 lines (166 loc) · 7.62 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·190 lines (166 loc) · 7.62 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# Claude Code Local — One-command setup
# Apple Silicon only. Installs MLX, downloads a model from the lineup,
# and creates a desktop launcher that runs Claude Code 100% on-device.
#
# Usage: bash setup.sh
set -e
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Claude Code Local — Setup ║"
echo "║ Pick your fighter. Run AI on your Mac. ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
# ── System detection ──────────────────────────────────────────
MEM_GB=$(sysctl -n hw.memsize 2>/dev/null | awk '{print int($1/1073741824)}')
CHIP=$(sysctl -n machdep.cpu.brand_string 2>/dev/null || echo 'Apple Silicon')
echo "Detected: $CHIP"
echo "Memory: ${MEM_GB} GB"
echo ""
if [[ $(uname -m) != "arm64" ]]; then
echo "ERROR: This requires Apple Silicon (M1 or later)."
exit 1
fi
# ── Homebrew ──────────────────────────────────────────────────
if ! command -v brew &>/dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# ── Python 3.12 + MLX ─────────────────────────────────────────
if ! command -v python3.12 &>/dev/null; then
echo "Installing Python 3.12 (required for MLX)..."
brew install python@3.12
fi
MLX_VENV="$HOME/.local/mlx-server"
if [ ! -d "$MLX_VENV" ]; then
echo "Creating MLX virtualenv at $MLX_VENV..."
python3.12 -m venv "$MLX_VENV"
fi
echo "Installing mlx-lm into virtualenv..."
"$MLX_VENV/bin/pip" install --quiet --upgrade pip
"$MLX_VENV/bin/pip" install --quiet --upgrade mlx-lm
# ── Pick a model from the lineup ──────────────────────────────
echo ""
echo "Selecting a model from the lineup for your ${MEM_GB} GB Mac..."
if [ "$MEM_GB" -ge 96 ]; then
MODEL_ID="mlx-community/Qwen3.5-122B-A10B-4bit"
MODEL_LABEL="Qwen 3.5 122B (THE BEAST — 65 tok/s)"
MODEL_TIER="🔵 max"
elif [ "$MEM_GB" -ge 64 ]; then
MODEL_ID="divinetribe/gemma-4-31b-it-abliterated-4bit-mlx"
MODEL_LABEL="Gemma 4 31B Abliterated (THE QUICK ONE — ~15 tok/s)"
MODEL_TIER="🟢 fast"
elif [ "$MEM_GB" -ge 32 ]; then
MODEL_ID="divinetribe/gemma-4-31b-it-abliterated-4bit-mlx"
MODEL_LABEL="Gemma 4 31B Abliterated (tight fit, may swap)"
MODEL_TIER="🟡 squeeze"
else
MODEL_ID="mlx-community/Qwen3.5-4B-4bit"
MODEL_LABEL="Qwen 3.5 4B (lightweight, browser-agent friendly)"
MODEL_TIER="🟠 small"
fi
echo "Selected: $MODEL_TIER $MODEL_LABEL"
echo "Model ID: $MODEL_ID"
echo ""
# ── Download model ────────────────────────────────────────────
echo "Downloading $MODEL_ID (one time, can be 18-75 GB)..."
"$MLX_VENV/bin/python3" - <<PY
from mlx_lm.utils import load
load("$MODEL_ID")
print("Done.")
PY
# ── Install MLX server ────────────────────────────────────────
# We install it as a symlink into this repo, not a copy. That way if you edit
# proxy/server.py in the repo (to fix a bug, add a feature, pull a PR), the
# change takes effect on the running server after the next restart — with no
# risk of the running copy silently drifting from the version in git.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SERVER_DIR="$HOME/.local/mlx-native-server"
mkdir -p "$SERVER_DIR"
ln -sf "$SCRIPT_DIR/proxy/server.py" "$SERVER_DIR/server.py"
echo "MLX server installed (symlink) → $SERVER_DIR/server.py -> $SCRIPT_DIR/proxy/server.py"
# ── Create desktop launcher ───────────────────────────────────
CLAUDE_BIN=$(which claude 2>/dev/null || echo "$HOME/.local/bin/claude")
if [ ! -f "$CLAUDE_BIN" ]; then
echo ""
echo "WARNING: Claude Code not found. Install it with:"
echo " npm install -g @anthropic-ai/claude-code"
echo ""
CLAUDE_BIN="\$HOME/.local/bin/claude"
fi
LAUNCHER="$HOME/Desktop/Claude Local.command"
cat > "$LAUNCHER" <<LAUNCH
#!/bin/bash
# Claude Code — Local AI ($MODEL_LABEL)
CLAUDE_BIN="$CLAUDE_BIN"
MLX_PYTHON="$MLX_VENV/bin/python3"
MLX_SERVER="$SERVER_DIR/server.py"
if ! lsof -i :4000 >/dev/null 2>&1; then
MLX_MODEL="$MODEL_ID" "\$MLX_PYTHON" "\$MLX_SERVER" >/tmp/mlx-server.log 2>&1 &
echo " Loading $MODEL_LABEL on MLX..."
while ! curl -s http://localhost:4000/health 2>/dev/null | grep -q "ok"; do
sleep 2
done
fi
clear
echo ""
echo " → Claude Code with LOCAL AI"
echo " → $MODEL_LABEL"
echo " → 100% on-device, no cloud, no API fees"
echo ""
ANTHROPIC_BASE_URL=http://localhost:4000 \\
ANTHROPIC_API_KEY=sk-local \\
exec "\$CLAUDE_BIN" --model claude-sonnet-4-6
LAUNCH
chmod +x "$LAUNCHER"
# ── Optional: iMessage / Screen-to-Phone tools ────────────────
echo ""
echo "Checking for optional iMessage phone-control tools..."
CLAUDE_DIR="$HOME/.claude"
mkdir -p "$CLAUDE_DIR"
PHONE_SCRIPTS=(
"scripts/imessage-send.sh"
"scripts/imessage-send-image.sh"
"scripts/imessage-send-video.sh"
"scripts/imessage-toggle.sh"
"scripts/imessage-receive.sh"
)
MISSING=0
for s in "${PHONE_SCRIPTS[@]}"; do
if [ -f "$SCRIPT_DIR/$s" ]; then
cp "$SCRIPT_DIR/$s" "$CLAUDE_DIR/$(basename $s)"
chmod +x "$CLAUDE_DIR/$(basename $s)"
else
MISSING=1
fi
done
if [ "$MISSING" -eq 0 ]; then
echo " ✅ Phone tools installed to ~/.claude/"
if [ -f "$SCRIPT_DIR/config.example.sh" ] && [ ! -f "$SCRIPT_DIR/config.sh" ]; then
cp "$SCRIPT_DIR/config.example.sh" "$SCRIPT_DIR/config.sh"
echo " → Edit config.sh with your iPhone number + Apple ID"
fi
cp "$SCRIPT_DIR/config.sh" "$CLAUDE_DIR/screen-to-phone-config.sh" 2>/dev/null || true
else
echo " ℹ️ Phone scripts not bundled — clone them separately if you want phone control:"
echo " https://github.com/nicedreamzapp/claude-screen-to-phone"
fi
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Setup complete! ║"
echo "╠══════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ Model: $MODEL_ID"
echo "║ Server: $SERVER_DIR/server.py"
echo "║ Launcher: ~/Desktop/Claude Local.command"
echo "║ ║"
echo "║ Double-click 'Claude Local' on your Desktop ║"
echo "║ to start coding with local AI. ║"
echo "║ ║"
echo "║ Want a different fighter? See launchers/ for ║"
echo "║ Gemma 4 Code, Llama 70B, Browser Agent, ║"
echo "║ and Narrative Gemma launchers. ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""