codemax-pro 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -16
- package/index.js +481 -363
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# ⚡ codemax-pro
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The official one-command setup tool for **CodeMax** (`api.codemax.pro`).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Configures **Claude Code CLI**, the **VS Code extension**, and the **Claude Desktop app** in a few seconds.
|
|
6
6
|
|
|
7
|
-
## 🚀 Quick
|
|
8
|
-
|
|
9
|
-
Run this single command in your terminal:
|
|
7
|
+
## 🚀 Quick start
|
|
10
8
|
|
|
11
9
|
```bash
|
|
12
10
|
npx codemax-pro
|
|
@@ -18,25 +16,76 @@ Or pass your API key directly:
|
|
|
18
16
|
npx codemax-pro sk-cp-your-key-here
|
|
19
17
|
```
|
|
20
18
|
|
|
19
|
+
Re-run it any time to update your key.
|
|
20
|
+
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
## 🛠️ What it
|
|
23
|
+
## 🛠️ What it configures
|
|
24
24
|
|
|
25
|
-
1. **Validates your
|
|
26
|
-
2. **
|
|
27
|
-
3. **
|
|
28
|
-
4. **Installs Claude Code CLI
|
|
29
|
-
5.
|
|
25
|
+
1. **Validates your API key** against `api.codemax.pro` before changing anything
|
|
26
|
+
2. **Claude Code CLI + VS Code extension** — `~/.claude/settings.json`
|
|
27
|
+
3. **Claude Desktop** — third-party inference, provider `gateway`
|
|
28
|
+
4. **Installs Claude Code CLI** if it is missing (`@anthropic-ai/claude-code`)
|
|
29
|
+
5. Clears stale settings left by older versions
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
## 🖥️ About the Claude Desktop app
|
|
34
|
+
|
|
35
|
+
The desktop app is not the CLI. It does not read `~/.claude/settings.json`, and setting
|
|
36
|
+
`ANTHROPIC_BASE_URL` as an environment variable has no effect on it — it is its own application and
|
|
37
|
+
talks to whichever inference endpoint it is configured with.
|
|
38
|
+
|
|
39
|
+
So this tool uses Anthropic's supported **third-party inference** mode, with the provider set to
|
|
40
|
+
`gateway` and pointed at `api.codemax.pro`. It writes to both places the app looks:
|
|
41
|
+
|
|
42
|
+
| Platform | Written to |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| Windows | `HKCU\SOFTWARE\Policies\Claude` **and** `%LOCALAPPDATA%\Claude-3p\configLibrary\` |
|
|
45
|
+
| macOS | `~/Library/Application Support/Claude-3p/configLibrary/` |
|
|
46
|
+
| Linux | `~/.config/Claude-3p/configLibrary/` |
|
|
47
|
+
|
|
48
|
+
Alongside the endpoint and key it sets the model list, the credential header, the sandbox egress
|
|
49
|
+
allowlist (so tools that fetch from the network keep working), and turns off the WebFetch domain
|
|
50
|
+
preflight — without that last one the app checks every fetched domain against a host this setup
|
|
51
|
+
never otherwise contacts, which fails on a restricted network.
|
|
52
|
+
|
|
53
|
+
> ### ⚠️ Quit the desktop app fully, then reopen it
|
|
54
|
+
> Its configuration is read **once, at launch**. Closing the window leaves the process running, so
|
|
55
|
+
> a reopened window keeps the old settings and it looks like setup did not work. Quit from the
|
|
56
|
+
> system tray (Windows) or the menu bar (macOS) first.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🌐 Models
|
|
61
|
+
|
|
62
|
+
| Model | Best for |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `claude-opus-5` | Complex architecture and hard coding problems |
|
|
65
|
+
| `claude-fable-5` | Extended reasoning, long-running work |
|
|
66
|
+
| `claude-sonnet-5` | Fast, capable general-purpose work |
|
|
67
|
+
| `claude-haiku-4-5` | Quick turnarounds and background tasks |
|
|
68
|
+
|
|
69
|
+
Legacy model names (`claude-opus-4-8`, `claude-sonnet-4-6`, `claude-3-5-sonnet` and friends) are
|
|
70
|
+
accepted too and map onto the current lineup.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🩹 Troubleshooting
|
|
75
|
+
|
|
76
|
+
**The desktop model picker is empty.** The app was not restarted, or a machine-wide policy is
|
|
77
|
+
overriding your user settings — on Windows, a policy under `HKLM\SOFTWARE\Policies\Claude` makes the
|
|
78
|
+
app ignore the per-user one entirely. The setup tool warns when it finds one.
|
|
79
|
+
|
|
80
|
+
**Requests fail with 401 in the desktop app.** Re-run `npx codemax-pro` with your key; the stored
|
|
81
|
+
credential may be from a rotated key.
|
|
82
|
+
|
|
83
|
+
**The CLI works but the desktop app does not.** They read completely different configuration. Check
|
|
84
|
+
the desktop app under **Help → Troubleshooting → Copy Managed Configuration Report**, which lists
|
|
85
|
+
which keys were detected and where they were read from, with secrets redacted.
|
|
38
86
|
|
|
39
87
|
---
|
|
40
88
|
|
|
41
89
|
## 📖 License
|
|
90
|
+
|
|
42
91
|
MIT © [CodeMax](https://codemax.pro)
|
package/index.js
CHANGED
|
@@ -1,363 +1,481 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { execSync } = require("child_process");
|
|
6
|
-
const readline = require("readline");
|
|
7
|
-
const crypto = require("crypto");
|
|
8
|
-
|
|
9
|
-
const API_ENDPOINT = "https://api.codemax.pro";
|
|
10
|
-
|
|
11
|
-
// ── Colors ──
|
|
12
|
-
const c = {
|
|
13
|
-
reset: "\x1b[0m",
|
|
14
|
-
bold: "\x1b[1m",
|
|
15
|
-
dim: "\x1b[2m",
|
|
16
|
-
cyan: "\x1b[36m",
|
|
17
|
-
green: "\x1b[32m",
|
|
18
|
-
yellow: "\x1b[33m",
|
|
19
|
-
red: "\x1b[31m",
|
|
20
|
-
gray: "\x1b[90m",
|
|
21
|
-
white: "\x1b[97m",
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const log = (msg) => console.log(msg);
|
|
25
|
-
const ok = (msg) => log(` ${c.green}✓ ${msg}${c.reset}`);
|
|
26
|
-
const warn = (msg) => log(` ${c.yellow}⚠ ${msg}${c.reset}`);
|
|
27
|
-
const fail = (msg) => log(` ${c.red}✗ ${msg}${c.reset}`);
|
|
28
|
-
const info = (msg) => log(` ${c.cyan}${msg}${c.reset}`);
|
|
29
|
-
const gray = (msg) => log(` ${c.gray}${msg}${c.reset}`);
|
|
30
|
-
|
|
31
|
-
function ask(question) {
|
|
32
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
33
|
-
return new Promise((resolve) => {
|
|
34
|
-
rl.question(question, (answer) => {
|
|
35
|
-
rl.close();
|
|
36
|
-
resolve(answer.trim());
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function readJson(filePath) {
|
|
42
|
-
try {
|
|
43
|
-
if (fs.existsSync(filePath)) {
|
|
44
|
-
const raw = fs.readFileSync(filePath, "utf8").trim();
|
|
45
|
-
if (!raw) return {};
|
|
46
|
-
return JSON.parse(raw);
|
|
47
|
-
}
|
|
48
|
-
} catch { }
|
|
49
|
-
return {};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function writeJson(filePath, data) {
|
|
53
|
-
const dir = path.dirname(filePath);
|
|
54
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
55
|
-
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function run(cmd) {
|
|
59
|
-
try {
|
|
60
|
-
return execSync(cmd, { encoding: "utf8", stdio: "pipe" }).trim();
|
|
61
|
-
} catch {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function which(cmd) {
|
|
67
|
-
try {
|
|
68
|
-
const r = execSync(process.platform === "win32" ? `where ${cmd}` : `which ${cmd}`, {
|
|
69
|
-
encoding: "utf8",
|
|
70
|
-
stdio: "pipe",
|
|
71
|
-
}).trim();
|
|
72
|
-
return r ? true : false;
|
|
73
|
-
} catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function validateKey(apiKey) {
|
|
79
|
-
const body = JSON.stringify({
|
|
80
|
-
model: "claude-haiku-4.5",
|
|
81
|
-
max_tokens: 10,
|
|
82
|
-
messages: [{ role: "user", content: "Hi" }],
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
const res = await fetch(`${API_ENDPOINT}/v1/messages`, {
|
|
87
|
-
method: "POST",
|
|
88
|
-
headers: {
|
|
89
|
-
"Content-Type": "application/json",
|
|
90
|
-
"x-api-key": apiKey,
|
|
91
|
-
"anthropic-version": "2023-06-01",
|
|
92
|
-
},
|
|
93
|
-
body,
|
|
94
|
-
signal: AbortSignal.timeout(30000),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (res.ok) return { valid: true };
|
|
98
|
-
if (res.status === 429) return { valid: true, rateLimit: true };
|
|
99
|
-
if (res.status === 401 || res.status === 403) return { valid: false, reason: "Invalid API key" };
|
|
100
|
-
if (res.status === 402) return { valid: false, reason: "No remaining balance" };
|
|
101
|
-
return { valid: false, reason: `Server returned ${res.status}` };
|
|
102
|
-
} catch (e) {
|
|
103
|
-
return { valid: false, reason: e.message, network: true };
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
const readline = require("readline");
|
|
7
|
+
const crypto = require("crypto");
|
|
8
|
+
|
|
9
|
+
const API_ENDPOINT = "https://api.codemax.pro";
|
|
10
|
+
|
|
11
|
+
// ── Colors ──
|
|
12
|
+
const c = {
|
|
13
|
+
reset: "\x1b[0m",
|
|
14
|
+
bold: "\x1b[1m",
|
|
15
|
+
dim: "\x1b[2m",
|
|
16
|
+
cyan: "\x1b[36m",
|
|
17
|
+
green: "\x1b[32m",
|
|
18
|
+
yellow: "\x1b[33m",
|
|
19
|
+
red: "\x1b[31m",
|
|
20
|
+
gray: "\x1b[90m",
|
|
21
|
+
white: "\x1b[97m",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const log = (msg) => console.log(msg);
|
|
25
|
+
const ok = (msg) => log(` ${c.green}✓ ${msg}${c.reset}`);
|
|
26
|
+
const warn = (msg) => log(` ${c.yellow}⚠ ${msg}${c.reset}`);
|
|
27
|
+
const fail = (msg) => log(` ${c.red}✗ ${msg}${c.reset}`);
|
|
28
|
+
const info = (msg) => log(` ${c.cyan}${msg}${c.reset}`);
|
|
29
|
+
const gray = (msg) => log(` ${c.gray}${msg}${c.reset}`);
|
|
30
|
+
|
|
31
|
+
function ask(question) {
|
|
32
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
rl.question(question, (answer) => {
|
|
35
|
+
rl.close();
|
|
36
|
+
resolve(answer.trim());
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readJson(filePath) {
|
|
42
|
+
try {
|
|
43
|
+
if (fs.existsSync(filePath)) {
|
|
44
|
+
const raw = fs.readFileSync(filePath, "utf8").trim();
|
|
45
|
+
if (!raw) return {};
|
|
46
|
+
return JSON.parse(raw);
|
|
47
|
+
}
|
|
48
|
+
} catch { }
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function writeJson(filePath, data) {
|
|
53
|
+
const dir = path.dirname(filePath);
|
|
54
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
55
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function run(cmd) {
|
|
59
|
+
try {
|
|
60
|
+
return execSync(cmd, { encoding: "utf8", stdio: "pipe" }).trim();
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function which(cmd) {
|
|
67
|
+
try {
|
|
68
|
+
const r = execSync(process.platform === "win32" ? `where ${cmd}` : `which ${cmd}`, {
|
|
69
|
+
encoding: "utf8",
|
|
70
|
+
stdio: "pipe",
|
|
71
|
+
}).trim();
|
|
72
|
+
return r ? true : false;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function validateKey(apiKey) {
|
|
79
|
+
const body = JSON.stringify({
|
|
80
|
+
model: "claude-haiku-4.5",
|
|
81
|
+
max_tokens: 10,
|
|
82
|
+
messages: [{ role: "user", content: "Hi" }],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const res = await fetch(`${API_ENDPOINT}/v1/messages`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: {
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
"x-api-key": apiKey,
|
|
91
|
+
"anthropic-version": "2023-06-01",
|
|
92
|
+
},
|
|
93
|
+
body,
|
|
94
|
+
signal: AbortSignal.timeout(30000),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (res.ok) return { valid: true };
|
|
98
|
+
if (res.status === 429) return { valid: true, rateLimit: true };
|
|
99
|
+
if (res.status === 401 || res.status === 403) return { valid: false, reason: "Invalid API key" };
|
|
100
|
+
if (res.status === 402) return { valid: false, reason: "No remaining balance" };
|
|
101
|
+
return { valid: false, reason: `Server returned ${res.status}` };
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return { valid: false, reason: e.message, network: true };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ── Claude Desktop, third-party inference ───────────────────────────────────
|
|
108
|
+
*
|
|
109
|
+
* Claude Desktop does NOT read ~/.claude/settings.json, and it does not shell out to the CLI —
|
|
110
|
+
* it is its own app and talks to its configured inference endpoint directly. Setting
|
|
111
|
+
* ANTHROPIC_BASE_URL for it, in any file or as an environment variable, does nothing. The
|
|
112
|
+
* supported route is Anthropic's documented "third-party inference" mode with `inferenceProvider`
|
|
113
|
+
* set to `gateway`, which is exactly what this API already is: the Messages API with streaming
|
|
114
|
+
* and tool use.
|
|
115
|
+
*
|
|
116
|
+
* Two surfaces carry that configuration, and this writes BOTH because they fail differently:
|
|
117
|
+
*
|
|
118
|
+
* 1. OS policy store — the documented, stable surface. On Windows that is the registry under
|
|
119
|
+
* HKCU\SOFTWARE\Policies\Claude with every value a REG_SZ, even booleans and JSON.
|
|
120
|
+
* 2. The app's own local config library. Undocumented in shape, but it is what the in-app
|
|
121
|
+
* "Apply locally" button writes, so it is what makes the setting visible in the UI.
|
|
122
|
+
*
|
|
123
|
+
* The policy store wins if the two ever disagree, which is the right way round.
|
|
124
|
+
*/
|
|
125
|
+
const DESKTOP_MODELS = [
|
|
126
|
+
{ name: "claude-opus-5" },
|
|
127
|
+
{ name: "claude-fable-5" },
|
|
128
|
+
{ name: "claude-sonnet-5" },
|
|
129
|
+
{ name: "claude-haiku-4-5-20251001" },
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
/* Hosts the agent's own web tools may reach from inside the sandbox. This is a separate, stricter
|
|
133
|
+
* boundary than the machine's firewall: an unlisted host is refused even when the machine can
|
|
134
|
+
* reach it. Web SEARCH does not need anything here — search runs server-side and arrives as part
|
|
135
|
+
* of the response — but WebFetch, npm, pip and git all run on the device and do. */
|
|
136
|
+
const EGRESS_HOSTS = [
|
|
137
|
+
"api.codemax.pro",
|
|
138
|
+
"github.com", "raw.githubusercontent.com", "objects.githubusercontent.com",
|
|
139
|
+
"gist.github.com", "codeload.github.com",
|
|
140
|
+
"registry.npmjs.org", "npmjs.com", "www.npmjs.com",
|
|
141
|
+
"pypi.org", "files.pythonhosted.org",
|
|
142
|
+
"crates.io", "static.crates.io",
|
|
143
|
+
"proxy.golang.org", "sum.golang.org",
|
|
144
|
+
"developer.mozilla.org", "stackoverflow.com", "api.stackexchange.com",
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
function desktopPolicyValues(apiKey) {
|
|
148
|
+
return {
|
|
149
|
+
inferenceProvider: "gateway",
|
|
150
|
+
inferenceGatewayBaseUrl: API_ENDPOINT,
|
|
151
|
+
inferenceGatewayApiKey: apiKey,
|
|
152
|
+
inferenceCredentialKind: "static",
|
|
153
|
+
// This API authenticates with the x-api-key header, as the Messages API does. The key
|
|
154
|
+
// defaults to "bearer", so leaving it out sends the credential in a header this endpoint
|
|
155
|
+
// does not read, and every request comes back 401.
|
|
156
|
+
inferenceGatewayAuthScheme: "x-api-key",
|
|
157
|
+
// Given explicitly rather than left to discovery. The picker's auto-discovery keeps only
|
|
158
|
+
// model IDs it recognises as Claude, so a gateway that renamed anything would show an
|
|
159
|
+
// empty picker with no error to explain it. Full IDs also let the app skip the
|
|
160
|
+
// /v1/models round trip at launch.
|
|
161
|
+
inferenceModels: JSON.stringify(DESKTOP_MODELS),
|
|
162
|
+
// Without this, WebFetch asks api.anthropic.com whether each domain is allowed before
|
|
163
|
+
// fetching it — a hard dependency on a host this deployment otherwise never touches, and
|
|
164
|
+
// one that fails closed on a restricted network.
|
|
165
|
+
skipWebFetchPreflight: "true",
|
|
166
|
+
coworkEgressAllowedHosts: JSON.stringify(EGRESS_HOSTS),
|
|
167
|
+
// Product analytics only. Off because leaving it on also adds api.anthropic.com to the
|
|
168
|
+
// sandbox allowlist so usage telemetry can be delivered from inside it. Crash reporting
|
|
169
|
+
// (disableEssentialTelemetry) is deliberately left ALONE — turning that off opts you into
|
|
170
|
+
// a manual support model where nobody can see failures on your machine.
|
|
171
|
+
disableNonessentialTelemetry: "true",
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* .reg escaping: backslashes and quotes are doubled/escaped, and the JSON values here contain
|
|
176
|
+
* plenty of both. Built as a file and imported rather than passed to `reg add`, because the
|
|
177
|
+
* command-line form loses quotes inside JSON to cmd's own parsing and silently stores a
|
|
178
|
+
* truncated value. */
|
|
179
|
+
function writeWindowsPolicy(values) {
|
|
180
|
+
const esc = (s) => String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
181
|
+
const lines = [
|
|
182
|
+
"Windows Registry Editor Version 5.00",
|
|
183
|
+
"",
|
|
184
|
+
"[HKEY_CURRENT_USER\\SOFTWARE\\Policies\\Claude]",
|
|
185
|
+
...Object.entries(values).map(([k, v]) => `"${k}"="${esc(v)}"`),
|
|
186
|
+
"",
|
|
187
|
+
];
|
|
188
|
+
const tmp = path.join(process.env.TEMP || process.env.TMP || ".", `codemax-3p-${Date.now()}.reg`);
|
|
189
|
+
// UTF-16LE with a BOM is what reg.exe expects for a v5 file; UTF-8 imports as mojibake.
|
|
190
|
+
fs.writeFileSync(tmp, "" + lines.join("\r\n"), "utf16le");
|
|
191
|
+
const imported = run(`reg import "${tmp}"`) !== null;
|
|
192
|
+
try { fs.unlinkSync(tmp); } catch { /* temp file, ignore */ }
|
|
193
|
+
return imported;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function machinePolicyPresent() {
|
|
197
|
+
// A machine policy makes the app ignore the per-user one ENTIRELY, so writing HKCU under it
|
|
198
|
+
// looks like it worked and changes nothing. Worth saying out loud rather than debugging later.
|
|
199
|
+
return run('reg query "HKLM\\SOFTWARE\\Policies\\Claude" /v inferenceProvider') !== null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function configureClaudeDesktop3P(home, apiKey) {
|
|
203
|
+
const isWin = process.platform === "win32";
|
|
204
|
+
const isMac = process.platform === "darwin";
|
|
205
|
+
const values = desktopPolicyValues(apiKey);
|
|
206
|
+
const written = [];
|
|
207
|
+
|
|
208
|
+
if (isWin) {
|
|
209
|
+
if (machinePolicyPresent()) {
|
|
210
|
+
warn("A machine-wide Claude policy exists (HKLM) — it overrides the per-user one.");
|
|
211
|
+
gray(" Ask whoever manages this device to apply the gateway settings there.");
|
|
212
|
+
}
|
|
213
|
+
if (writeWindowsPolicy(values)) written.push("HKCU\\SOFTWARE\\Policies\\Claude");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const baseDir = isWin
|
|
217
|
+
? path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "Claude-3p")
|
|
218
|
+
: isMac
|
|
219
|
+
? path.join(home, "Library", "Application Support", "Claude-3p")
|
|
220
|
+
: path.join(home, ".config", "Claude-3p");
|
|
221
|
+
|
|
222
|
+
const configLibDir = path.join(baseDir, "configLibrary");
|
|
223
|
+
if (!fs.existsSync(configLibDir)) fs.mkdirSync(configLibDir, { recursive: true });
|
|
224
|
+
|
|
225
|
+
const metaPath = path.join(configLibDir, "_meta.json");
|
|
226
|
+
const meta = readJson(metaPath);
|
|
227
|
+
if (!Array.isArray(meta.entries)) meta.entries = [];
|
|
228
|
+
|
|
229
|
+
let profileId = meta.appliedId;
|
|
230
|
+
if (!profileId || !fs.existsSync(path.join(configLibDir, `${profileId}.json`))) {
|
|
231
|
+
profileId = crypto.randomUUID ? crypto.randomUUID() : `codemax-${Date.now()}`;
|
|
232
|
+
meta.appliedId = profileId;
|
|
233
|
+
if (!meta.entries.some((e) => e && e.id === profileId)) {
|
|
234
|
+
meta.entries.push({ id: profileId, name: "CodeMax Gateway" });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// The local profile takes real types; only the OS policy store requires strings.
|
|
239
|
+
const profilePath = path.join(configLibDir, `${profileId}.json`);
|
|
240
|
+
writeJson(profilePath, {
|
|
241
|
+
...values,
|
|
242
|
+
inferenceModels: DESKTOP_MODELS,
|
|
243
|
+
coworkEgressAllowedHosts: EGRESS_HOSTS,
|
|
244
|
+
skipWebFetchPreflight: true,
|
|
245
|
+
disableNonessentialTelemetry: true,
|
|
246
|
+
});
|
|
247
|
+
writeJson(metaPath, meta);
|
|
248
|
+
written.push(profilePath);
|
|
249
|
+
|
|
250
|
+
const devSettingsPath = path.join(baseDir, "developer_settings.json");
|
|
251
|
+
const devSettings = readJson(devSettingsPath);
|
|
252
|
+
devSettings.allowDevTools = true;
|
|
253
|
+
writeJson(devSettingsPath, devSettings);
|
|
254
|
+
|
|
255
|
+
/* Previous versions also wrote an `env` block into claude_desktop_config.json. That file
|
|
256
|
+
* configures MCP servers; nothing in it selects an inference endpoint, so those keys sat
|
|
257
|
+
* there doing nothing while looking like the thing that made this work. Removed, and any
|
|
258
|
+
* leftovers are cleaned up below so a re-run does not leave the key lying in a file the app
|
|
259
|
+
* hands to MCP server processes. */
|
|
260
|
+
const desktopConfigPath = isWin
|
|
261
|
+
? path.join(process.env.APPDATA || path.join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json")
|
|
262
|
+
: isMac
|
|
263
|
+
? path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json")
|
|
264
|
+
: path.join(home, ".config", "Claude", "claude_desktop_config.json");
|
|
265
|
+
try {
|
|
266
|
+
if (fs.existsSync(desktopConfigPath)) {
|
|
267
|
+
const dc = readJson(desktopConfigPath);
|
|
268
|
+
if (dc.env) {
|
|
269
|
+
for (const k of ["ANTHROPIC_BASE_URL", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY"]) delete dc.env[k];
|
|
270
|
+
if (Object.keys(dc.env).length === 0) delete dc.env;
|
|
271
|
+
writeJson(desktopConfigPath, dc);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} catch { /* best effort */ }
|
|
275
|
+
|
|
276
|
+
return written;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function main() {
|
|
280
|
+
log("");
|
|
281
|
+
log(` ${c.cyan}╔══════════════════════════════════════════╗${c.reset}`);
|
|
282
|
+
log(` ${c.cyan}║ ${c.bold}CodeMax Setup${c.reset}${c.cyan} ║${c.reset}`);
|
|
283
|
+
log(` ${c.cyan}╚══════════════════════════════════════════╝${c.reset}`);
|
|
284
|
+
log("");
|
|
285
|
+
|
|
286
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
287
|
+
if (!home) {
|
|
288
|
+
fail("Cannot determine home directory");
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ── Get API Key ──
|
|
293
|
+
let apiKey = process.argv[2] || "";
|
|
294
|
+
if (!apiKey) {
|
|
295
|
+
log(` ${c.white}Enter your CodeMax API key${c.reset}`);
|
|
296
|
+
gray("Get it from your admin or codemax.pro");
|
|
297
|
+
log("");
|
|
298
|
+
apiKey = await ask(` ${c.white}API Key: ${c.reset}`);
|
|
299
|
+
log("");
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (!apiKey || apiKey.length < 5) {
|
|
303
|
+
fail("No valid API key provided. Exiting.");
|
|
304
|
+
process.exit(1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ── [1/5] Validate API Key ──
|
|
308
|
+
info("[1/5] Validating API key...");
|
|
309
|
+
const result = await validateKey(apiKey);
|
|
310
|
+
|
|
311
|
+
if (result.valid) {
|
|
312
|
+
if (result.rateLimit) {
|
|
313
|
+
warn("API key valid but rate-limited. Continuing setup...");
|
|
314
|
+
} else {
|
|
315
|
+
ok("API key is valid!");
|
|
316
|
+
ok("Connected to CodeMax");
|
|
317
|
+
}
|
|
318
|
+
} else if (result.network) {
|
|
319
|
+
warn(`Could not reach server: ${result.reason}`);
|
|
320
|
+
const cont = await ask(` ${c.yellow}Continue anyway? (y/n): ${c.reset}`);
|
|
321
|
+
if (cont.toLowerCase() !== "y") process.exit(1);
|
|
322
|
+
} else {
|
|
323
|
+
fail(result.reason);
|
|
324
|
+
gray("Make sure you're using a valid CodeMax API key (sk-cp-...)");
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
log("");
|
|
328
|
+
|
|
329
|
+
// ── [2/5] Check Node.js ──
|
|
330
|
+
info("[2/5] Checking Node.js...");
|
|
331
|
+
const nodeVer = run("node --version");
|
|
332
|
+
if (nodeVer) {
|
|
333
|
+
ok(`Node.js ${nodeVer} found`);
|
|
334
|
+
} else {
|
|
335
|
+
fail("Node.js not found. Install from https://nodejs.org");
|
|
336
|
+
process.exit(1);
|
|
337
|
+
}
|
|
338
|
+
log("");
|
|
339
|
+
|
|
340
|
+
// ── [3/5] Configure Claude Code CLI & VS Code settings ──
|
|
341
|
+
info("[3/5] Configuring Claude Code CLI & VS Code...");
|
|
342
|
+
const settingsPath = path.join(home, ".claude", "settings.json");
|
|
343
|
+
try {
|
|
344
|
+
const settings = readJson(settingsPath);
|
|
345
|
+
if (!settings.env) settings.env = {};
|
|
346
|
+
|
|
347
|
+
Object.assign(settings.env, {
|
|
348
|
+
ANTHROPIC_AUTH_TOKEN: apiKey,
|
|
349
|
+
ANTHROPIC_BASE_URL: API_ENDPOINT,
|
|
350
|
+
CLAUDE_CODE_OAUTH_TOKEN: apiKey,
|
|
351
|
+
CLAUDE_CODE_SUBSCRIPTION_TYPE: "max",
|
|
352
|
+
CLAUDE_CODE_REMOTE: "1",
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const removeVars = [
|
|
356
|
+
"ANTHROPIC_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL", "ANTHROPIC_DEFAULT_MODEL",
|
|
357
|
+
"ANTHROPIC_REASONING_MODEL",
|
|
358
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
359
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL",
|
|
360
|
+
];
|
|
361
|
+
for (const v of removeVars) delete settings.env[v];
|
|
362
|
+
delete settings.model;
|
|
363
|
+
|
|
364
|
+
writeJson(settingsPath, settings);
|
|
365
|
+
ok("Claude Code CLI & VS Code Extension configured");
|
|
366
|
+
} catch (e) {
|
|
367
|
+
fail(`Failed: ${e.message}`);
|
|
368
|
+
}
|
|
369
|
+
log("");
|
|
370
|
+
|
|
371
|
+
// ── [4/5] Configure Claude Desktop App (Third-Party Inference Gateway) ──
|
|
372
|
+
info("[4/5] Configuring Claude Desktop App (Inference Gateway)...");
|
|
373
|
+
try {
|
|
374
|
+
const written = configureClaudeDesktop3P(home, apiKey);
|
|
375
|
+
if (written.length) {
|
|
376
|
+
ok("Claude Desktop third-party inference configured");
|
|
377
|
+
for (const w of written) gray(` ${w}`);
|
|
378
|
+
} else {
|
|
379
|
+
warn("Claude Desktop config could not be written — is the app installed?");
|
|
380
|
+
}
|
|
381
|
+
} catch (e) {
|
|
382
|
+
warn(`Could not auto-configure Claude Desktop: ${e.message}`);
|
|
383
|
+
}
|
|
384
|
+
log("");
|
|
385
|
+
|
|
386
|
+
// ── Clean up any stale MCP config from prior installs ──
|
|
387
|
+
const claudeJsonPath = path.join(home, ".claude.json");
|
|
388
|
+
try {
|
|
389
|
+
const claudeJson = readJson(claudeJsonPath);
|
|
390
|
+
let mutated = false;
|
|
391
|
+
if (claudeJson.mcpServers && claudeJson.mcpServers.CodeMax) {
|
|
392
|
+
delete claudeJson.mcpServers.CodeMax;
|
|
393
|
+
mutated = true;
|
|
394
|
+
}
|
|
395
|
+
if (mutated) {
|
|
396
|
+
if (claudeJson.mcpServers && Object.keys(claudeJson.mcpServers).length === 0) {
|
|
397
|
+
delete claudeJson.mcpServers;
|
|
398
|
+
}
|
|
399
|
+
claudeJson.hasCompletedOnboarding = true;
|
|
400
|
+
writeJson(claudeJsonPath, claudeJson);
|
|
401
|
+
} else if (!fs.existsSync(claudeJsonPath)) {
|
|
402
|
+
writeJson(claudeJsonPath, { hasCompletedOnboarding: true });
|
|
403
|
+
}
|
|
404
|
+
} catch { /* non-critical */ }
|
|
405
|
+
|
|
406
|
+
// ── Clear stale env vars (Windows only) ──
|
|
407
|
+
if (process.platform === "win32") {
|
|
408
|
+
const staleVars = [
|
|
409
|
+
"ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_BASE_URL",
|
|
410
|
+
"ANTHROPIC_MODEL", "ANTHROPIC_SMALL_FAST_MODEL",
|
|
411
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
412
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
|
|
413
|
+
];
|
|
414
|
+
for (const v of staleVars) {
|
|
415
|
+
run(`REG delete "HKCU\\Environment" /v ${v} /f`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ── [5/5] Install Claude Code CLI ──
|
|
420
|
+
info("[5/5] Checking Claude Code CLI...");
|
|
421
|
+
if (which("claude")) {
|
|
422
|
+
ok("Claude Code CLI already installed");
|
|
423
|
+
} else {
|
|
424
|
+
info("Installing Claude Code CLI...");
|
|
425
|
+
const cliResult = run("npm install -g @anthropic-ai/claude-code");
|
|
426
|
+
if (cliResult !== null) {
|
|
427
|
+
ok("Claude Code CLI installed!");
|
|
428
|
+
} else {
|
|
429
|
+
warn("Auto-install failed. Run: npm install -g @anthropic-ai/claude-code");
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ── Done ──
|
|
434
|
+
log("");
|
|
435
|
+
log(` ${c.green}╔══════════════════════════════════════════╗${c.reset}`);
|
|
436
|
+
log(` ${c.green}║ ${c.bold}✓ Setup complete!${c.reset}${c.green} ║${c.reset}`);
|
|
437
|
+
log(` ${c.green}╚══════════════════════════════════════════╝${c.reset}`);
|
|
438
|
+
log("");
|
|
439
|
+
log(` ${c.white}What was configured:${c.reset}`);
|
|
440
|
+
gray(` • API key validated ✓`);
|
|
441
|
+
gray(` • Claude Code CLI & VS Code Extension (~/.claude/settings.json)`);
|
|
442
|
+
gray(` • Claude Desktop — third-party inference, provider "gateway"`);
|
|
443
|
+
gray(` models, x-api-key auth, sandbox egress list, WebFetch preflight off`);
|
|
444
|
+
log("");
|
|
445
|
+
log(` ${c.white}Claude Desktop needs a full restart, not just a closed window:${c.reset}`);
|
|
446
|
+
gray(` • Quit it from the system tray / menu bar, then open it again.`);
|
|
447
|
+
gray(` • Config is read once at launch, so a window reopened from a running`);
|
|
448
|
+
gray(` process keeps the old settings and looks like this did not work.`);
|
|
449
|
+
log("");
|
|
450
|
+
log(` ${c.gray}╭───────────────────────────────────────╮${c.reset}`);
|
|
451
|
+
log(` ${c.gray}│ Gateway: api.codemax.pro │${c.reset}`);
|
|
452
|
+
log(` ${c.gray}│ Key: ${apiKey.substring(0, 8)}... │${c.reset}`);
|
|
453
|
+
log(` ${c.gray}╰───────────────────────────────────────╯${c.reset}`);
|
|
454
|
+
log("");
|
|
455
|
+
gray("Restart Claude Code / VS Code / Claude Desktop to apply.");
|
|
456
|
+
gray("Re-run anytime to update your key.");
|
|
457
|
+
log("");
|
|
458
|
+
|
|
459
|
+
// Ask to launch
|
|
460
|
+
if (which("claude")) {
|
|
461
|
+
const launch = await ask(` ${c.white}Launch Claude Code now? (y/n): ${c.reset}`);
|
|
462
|
+
if (launch.toLowerCase() === "y" || launch === "") {
|
|
463
|
+
log("");
|
|
464
|
+
info("🚀 Launching Claude Code...");
|
|
465
|
+
log(` ${c.gray}════════════════════════════════════${c.reset}`);
|
|
466
|
+
log("");
|
|
467
|
+
try {
|
|
468
|
+
execSync("claude", { stdio: "inherit" });
|
|
469
|
+
} catch { }
|
|
470
|
+
} else {
|
|
471
|
+
log("");
|
|
472
|
+
log(` ${c.white}To start later, open any terminal and type: claude${c.reset}`);
|
|
473
|
+
log("");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
main().catch((e) => {
|
|
479
|
+
fail(`Unexpected error: ${e.message}`);
|
|
480
|
+
process.exit(1);
|
|
481
|
+
});
|