Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·220 lines (195 loc) · 9.08 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·220 lines (195 loc) · 9.08 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/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
# Passed a Claude Code smoke test on an M5 Max, 2026-09-19 (wrote hello.py, ran it, 38 s).
MODEL_ID="lmstudio-community/Qwen3.8-27B-MLX-8bit"
MODEL_LABEL="Qwen 3.8 27B, 8-bit (~29 GB)"
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, 4-bit (~18 GB)"
MODEL_TIER="🟢 fast"
elif [ "$MEM_GB" -ge 32 ]; then
MODEL_ID="divinetribe/gemma-4-12B-it-abliterated-4bit-mlx-text"
MODEL_LABEL="Gemma 4 12B Abliterated, 4-bit (~11 GB)"
MODEL_TIER="🟢 fast"
elif [ "$MEM_GB" -ge 16 ]; then
MODEL_ID="divinetribe/Hermes-4-14B-abliterated-4bit-mlx"
MODEL_LABEL="Hermes 4 14B Abliterated, 4-bit (~8 GB)"
MODEL_TIER="🟡 laptop"
else
# Loads and chats, but in a Claude Code smoke test (2026-09-19) it claimed to run a
# file it never wrote. Small Macs get it anyway; tool use will be unreliable.
MODEL_ID="mlx-community/gemma-4-e4b-it-4bit"
MODEL_LABEL="Gemma 4 E4B, 4-bit (~5 GB, may struggle with tool calls)"
MODEL_TIER="🟠 small"
fi
echo "Selected: $MODEL_TIER $MODEL_LABEL"
echo "Model ID: $MODEL_ID"
echo ""
# ── Download model ────────────────────────────────────────────
echo "Downloading $MODEL_ID (one time, 5-30 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"
# ── "keep going": continue a Claude conversation on a free or local model ──
mkdir -p "$HOME/.local/bin"
ln -sf "$SCRIPT_DIR/bin/keepgoing" "$HOME/.local/bin/keepgoing"
ZSHRC="$HOME/.zshrc"
KEEP_LINE="source \"$SCRIPT_DIR/scripts/keepgoing-shell.sh\""
if ! grep -qF "$KEEP_LINE" "$ZSHRC" 2>/dev/null; then
printf '\n# Claude Code Local: type "keep going" when Claude runs out of credits\n%s\n' "$KEEP_LINE" >> "$ZSHRC"
fi
echo "keep going installed → ~/.local/bin/keepgoing (open a new terminal to use it)"
# Optional: run keep going by itself when Claude hits a usage limit. setup.sh never edits
# ~/.claude/settings.json, so it only prints the snippet (docs/AUTO-HANDOFF.md explains it).
echo ""
echo "Want keep going to start by itself when you hit a Claude usage limit? Add this to"
echo "~/.claude/settings.json (merge it into an existing \"hooks\" block if you have one):"
cat <<HOOK
"hooks": {
"StopFailure": [
{ "matcher": "rate_limit",
"hooks": [ { "type": "command", "command": "python3 $SCRIPT_DIR/scripts/limit-handoff.py" } ] }
]
}
HOOK
# ── 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 model? See launchers/ for ║"
echo "║ Gemma 4 Code, Qwen 3.8 Code, Browser Agent, ║"
echo "║ and Narrative Gemma launchers. ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""