forked from techjarves/OpenClaude-Portable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTART.bat
More file actions
657 lines (608 loc) · 24.8 KB
/
Copy pathSTART.bat
File metadata and controls
657 lines (608 loc) · 24.8 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
221
222
223
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
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
title Portable AI USB - Starting...
:: Define ANSI Colors
for /F %%a in ('powershell -NoProfile -Command "[char]27"') do set "ESC=%%a"
set "CYAN=!ESC![36m"
set "GREEN=!ESC![32m"
set "YELLOW=!ESC![33m"
set "RED=!ESC![31m"
set "DIM=!ESC![90m"
set "RESET=!ESC![0m"
set "BOLD=!ESC![1m"
set "USB_ROOT=%~dp0"
set "ENGINE_DIR=%USB_ROOT%engine"
set "DATA_DIR=%USB_ROOT%data"
set "ENV_FILE=%DATA_DIR%\ai_settings.env"
set "NODE_VERSION=22.14.0"
set "NODE_DIR_NAME=node-win-x64"
set "NODE_DIR=%ENGINE_DIR%\%NODE_DIR_NAME%"
:: 1. Force the portable AI to save logs/memory strictly to the USB
set "CLAUDE_CONFIG_DIR=%DATA_DIR%\openclaude"
set "XDG_CONFIG_HOME=%DATA_DIR%\config"
set "XDG_DATA_HOME=%DATA_DIR%\app_data"
if not exist "%CLAUDE_CONFIG_DIR%" mkdir "%CLAUDE_CONFIG_DIR%"
if not exist "%XDG_CONFIG_HOME%" mkdir "%XDG_CONFIG_HOME%"
if not exist "%XDG_DATA_HOME%" mkdir "%XDG_DATA_HOME%"
:: Display Banner
echo.
echo !CYAN! ____ __ __ __ ___ ____!RESET!
echo !CYAN! / __ \____ ____/ /_____ _/ /_ / /__ / ^| / _/!RESET!
echo !CYAN! / /_/ / __ \/ __/ __/ __ `/ __ \/ / _ \ / /^| ^| / / !RESET!
echo !CYAN! / ____/ /_/ / / / /_/ /_/ / /_/ / / __/ / ___ ^|_/ / !RESET!
echo !CYAN!/_/ \____/_/ \__/\__,_/_.___/_/\___/ /_/ ^|_/___/ !RESET!
echo.
echo !CYAN!=========================================================!RESET!
echo !BOLD!Claude Code - Open Source Multi-Platform!RESET!
echo !CYAN!=========================================================!RESET!
echo.
if not exist "%ENGINE_DIR%" mkdir "%ENGINE_DIR%"
:: 2. Check Node.js
if not exist "%NODE_DIR%\node.exe" (
echo !YELLOW![~] Node.js not found for Windows-x64. Downloading...!RESET!
curl.exe -L "https://nodejs.org/dist/v%NODE_VERSION%/node-v%NODE_VERSION%-win-x64.zip" -o "%ENGINE_DIR%\node.zip"
if errorlevel 1 (
echo !RED![ERROR] Failed to download Node.js!!RESET!
pause
exit /b 1
)
echo !YELLOW![~] Extracting Node.js...!RESET!
powershell -NoProfile -Command "Expand-Archive -Path '%ENGINE_DIR%\node.zip' -DestinationPath '%ENGINE_DIR%' -Force"
ren "%ENGINE_DIR%\node-v%NODE_VERSION%-win-x64" "%NODE_DIR_NAME%"
del "%ENGINE_DIR%\node.zip"
echo !GREEN![OK] Node.js installed to %NODE_DIR%!RESET!
)
set "PATH=%NODE_DIR%;%PATH%"
if not exist "%ENGINE_DIR%\node_modules\@gitlawb\openclaude" (
echo !YELLOW![~] Installing OpenClaude Engine...!RESET!
pushd "%ENGINE_DIR%"
call npm.cmd install @gitlawb/openclaude@latest --no-audit --no-fund --loglevel=error --no-bin-links
echo !GREEN![OK] Engine installed!!RESET!
popd
)
:: 3. Check for flags (--offline, --quick)
set "SKIP_UPDATE=0"
set "QUICK_MODE=0"
for %%A in (%*) do (
if /I "%%A"=="--offline" set "SKIP_UPDATE=1"
if /I "%%A"=="--quick" set "QUICK_MODE=1"
)
if !SKIP_UPDATE!==1 (
echo !DIM![~] Offline mode - skipping update check!RESET!
) else (
:: Only check for updates once per day using a timestamp file
set "UPDATE_STAMP=%DATA_DIR%\last_update_check.txt"
set "TODAY_DATE="
for /f "tokens=*" %%D in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd"') do set "TODAY_DATE=%%D"
set "LAST_CHECK="
if exist "!UPDATE_STAMP!" (
set /p "LAST_CHECK="<"!UPDATE_STAMP!"
)
if "!LAST_CHECK!"=="!TODAY_DATE!" (
echo !DIM![~] Update check already done today - skipping!RESET!
) else (
echo !YELLOW![~] Checking for engine updates...!RESET!
pushd "%ENGINE_DIR%"
call npm.cmd outdated @gitlawb/openclaude >nul 2>&1
if errorlevel 1 (
echo !YELLOW![~] New version detected! Upgrading...!RESET!
call npm.cmd install @gitlawb/openclaude@latest --no-audit --no-fund --loglevel=error --no-bin-links >nul 2>&1
echo !GREEN![OK] Engine upgraded to latest version!!RESET!
) else (
echo !GREEN![OK] Engine is up to date!!RESET!
)
popd
echo !TODAY_DATE!>"!UPDATE_STAMP!"
)
)
echo.
:: 4. Check for settings file
if exist "%ENV_FILE%" (
findstr /C:"AI_PROVIDER=" "%ENV_FILE%" >nul
if errorlevel 1 (
echo !YELLOW![INFO] Legacy configuration detected. Upgrading format...!RESET!
del "%ENV_FILE%"
) else (
goto load_settings
)
)
:: ---------------------------------------------------------
:: PROVIDER SELECTION MENU
:: ---------------------------------------------------------
echo !CYAN!=========================================================!RESET!
echo !BOLD!AI PROVIDER SELECTION!RESET!
echo !CYAN!=========================================================!RESET!
echo.
echo !CYAN!1)!RESET! !BOLD!OpenRouter!RESET! !DIM!- 200+ Free and Paid Models!RESET! !GREEN![RECOMMENDED]!RESET!
echo !CYAN!2)!RESET! !BOLD!NVIDIA NIM!RESET! !DIM!- High-Speed GPU Free Tier!RESET! !GREEN![RECOMMENDED]!RESET!
echo !CYAN!3)!RESET! !BOLD!Gemini!RESET! !DIM!- Google AI API!RESET!
echo !CYAN!4)!RESET! !BOLD!Claude!RESET! !DIM!- Anthropic API!RESET!
echo !CYAN!5)!RESET! !BOLD!OpenAI!RESET! !DIM!- GPT / Codex API!RESET!
echo !CYAN!6)!RESET! !BOLD!Ollama!RESET! !DIM!- Local Offline AI (No internet)!RESET!
echo.
:prompt_provider
set "PROVIDER_SEL="
set /p "PROVIDER_SEL= Select your provider !CYAN!(1-6)!RESET!: "
if "!PROVIDER_SEL!"=="1" goto setup_openrouter
if "!PROVIDER_SEL!"=="2" goto setup_nvidia
if "!PROVIDER_SEL!"=="3" goto setup_gemini
if "!PROVIDER_SEL!"=="4" goto setup_claude
if "!PROVIDER_SEL!"=="5" goto setup_openai
if "!PROVIDER_SEL!"=="6" goto setup_ollama
echo !RED![ERROR] Invalid selection. Please choose 1-6.!RESET!
goto prompt_provider
:: ---------------------------------------------------------
:: OPENROUTER SETUP
:: ---------------------------------------------------------
:setup_openrouter
echo.
echo !CYAN!--- OPENROUTER SETUP ---!RESET!
echo.
set /p "USER_API_KEY= Enter your OpenRouter API Key: "
if "!USER_API_KEY!"=="" (
echo !RED![ERROR] API Key cannot be empty!!RESET!
goto setup_openrouter
)
set "USER_API_KEY=!USER_API_KEY: =!"
:: Mask key for display
set "KEY_MASK=!USER_API_KEY:~0,6!****!USER_API_KEY:~-4!"
echo !DIM!Key: !KEY_MASK!!RESET!
echo.
echo !YELLOW![~] Verifying API Key... Please wait...!RESET!
powershell -NoProfile -Command "$headers = @{ 'Authorization' = 'Bearer !USER_API_KEY!' }; try { $response = Invoke-RestMethod -Uri 'https://openrouter.ai/api/v1/auth/key' -Headers $headers -ErrorAction Stop; exit 0 } catch { exit 1 }"
if errorlevel 1 (
echo !RED![ERROR] Invalid or expired OpenRouter API Key!!RESET!
goto setup_openrouter
)
echo !GREEN![OK] Key Verified!!RESET!
echo.
echo Do you want to use !GREEN!Free!RESET! or !YELLOW!Paid!RESET! models?
echo !CYAN!1)!RESET! Free Models
echo !CYAN!2)!RESET! Paid Models
:prompt_tier
set "MODEL_TIER="
set /p "MODEL_TIER= Select category !CYAN!(1 or 2)!RESET!: "
if "!MODEL_TIER!"=="1" goto setup_free
if "!MODEL_TIER!"=="2" goto setup_paid
echo !RED![ERROR] Invalid selection. Please choose 1 or 2.!RESET!
goto prompt_tier
:setup_free
echo.
echo !CYAN!--- FREE MODELS ---!RESET! !DIM!(Live Fetching...)!RESET!
set "idx=1"
for /f "delims=" %%I in ('powershell -NoProfile -Command "$d = (Invoke-RestMethod 'https://openrouter.ai/api/v1/models').data; $free = $d | Where-Object { $_.id -match ':free$' } | Select-Object -First 20 -ExpandProperty id; $free"') do (
set "FREE_MODEL_!idx!=%%I"
echo !CYAN!!idx!^)!RESET! %%I
set /a "idx+=1"
)
if "!idx!"=="1" (
echo !YELLOW![API Error] Could not fetch models, using fallback...!RESET!
set "FREE_MODEL_1=qwen/qwen-2.5-coder-32b-instruct:free"
echo !CYAN!1^)!RESET! qwen/qwen-2.5-coder-32b-instruct:free
set /a "idx=2"
)
set "FREE_MAX=!idx!"
echo !CYAN!!FREE_MAX!^)!RESET! !DIM!Custom Free Model...!RESET!
echo.
:prompt_free_sel
set "FREE_SEL="
set /p "FREE_SEL= Choose a model !CYAN!(1-!FREE_MAX!)!RESET!: "
if defined FREE_SEL (
if "!FREE_SEL!"=="!FREE_MAX!" (
set /p "USER_MODEL= Enter custom model string: "
) else (
for %%V in (!FREE_SEL!) do set "USER_MODEL=!FREE_MODEL_%%V!"
)
)
if "!USER_MODEL!"=="" (
echo !RED![ERROR] Invalid selection. Please choose 1 to !FREE_MAX!.!RESET!
goto prompt_free_sel
)
goto save_settings_openrouter
:setup_paid
echo.
echo !CYAN!--- PAID MODELS ---!RESET! !DIM!(Live Fetching...)!RESET!
set "idx=1"
for /f "delims=" %%I in ('powershell -NoProfile -Command "$d = (Invoke-RestMethod 'https://openrouter.ai/api/v1/models').data; $paid = $d | Where-Object { $_.id -notmatch ':free$' } | Select-Object -First 20 -ExpandProperty id; $paid"') do (
set "PAID_MODEL_!idx!=%%I"
echo !CYAN!!idx!^)!RESET! %%I
set /a "idx+=1"
)
if "!idx!"=="1" (
echo !YELLOW![API Error] Could not fetch models, using fallback...!RESET!
set "PAID_MODEL_1=anthropic/claude-3.5-sonnet"
echo !CYAN!1^)!RESET! anthropic/claude-3.5-sonnet
set /a "idx=2"
)
set "PAID_MAX=!idx!"
echo !CYAN!!PAID_MAX!^)!RESET! !DIM!Custom Paid Model...!RESET!
echo.
:prompt_paid_sel
set "PAID_SEL="
set /p "PAID_SEL= Choose a model !CYAN!(1-!PAID_MAX!)!RESET!: "
if defined PAID_SEL (
if "!PAID_SEL!"=="!PAID_MAX!" (
set /p "USER_MODEL= Enter custom model string: "
) else (
for %%V in (!PAID_SEL!) do set "USER_MODEL=!PAID_MODEL_%%V!"
)
)
if "!USER_MODEL!"=="" (
echo !RED![ERROR] Invalid selection. Please choose 1 to !PAID_MAX!.!RESET!
goto prompt_paid_sel
)
goto save_settings_openrouter
:save_settings_openrouter
(
echo # ========================================================
echo # Portable AI - Master Switchboard
echo # ========================================================
echo AI_PROVIDER=openai
echo CLAUDE_CODE_USE_OPENAI=1
echo OPENAI_API_KEY=%USER_API_KEY%
echo OPENAI_BASE_URL=https://openrouter.ai/api/v1
echo OPENAI_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:: ---------------------------------------------------------
:: NVIDIA NIM SETUP
:: ---------------------------------------------------------
:setup_nvidia
echo.
echo !CYAN!--- NVIDIA NIM SETUP ---!RESET!
echo.
set /p "USER_API_KEY= Enter your NVIDIA API Key: "
if "!USER_API_KEY!"=="" (
echo !RED![ERROR] API Key cannot be empty!!RESET!
goto setup_nvidia
)
set "USER_API_KEY=!USER_API_KEY: =!"
set "KEY_MASK=!USER_API_KEY:~0,6!****!USER_API_KEY:~-4!"
echo !DIM!Key: !KEY_MASK!!RESET!
echo.
echo !YELLOW![~] Verifying API Key... Please wait...!RESET!
powershell -NoProfile -Command "$headers = @{ 'Authorization' = 'Bearer !USER_API_KEY!' }; try { $response = Invoke-RestMethod -Uri 'https://integrate.api.nvidia.com/v1/models' -Headers $headers -ErrorAction Stop; exit 0 } catch { exit 1 }"
if errorlevel 1 (
echo !RED![ERROR] Invalid or expired NVIDIA API Key!!RESET!
goto setup_nvidia
)
echo !GREEN![OK] Key Verified!!RESET!
echo.
echo !CYAN!--- NVIDIA MODELS ---!RESET! !DIM!(Live + Curated)!RESET!
set "idx=1"
for %%M in (
"moonshotai/kimi-k2-instruct" "moonshotai/kimi-k2-thinking" "z-ai/glm4.7"
"deepseek-ai/deepseek-v3.2" "deepseek-ai/deepseek-v3.1-terminus" "stepfun-ai/step-3.5-flash"
"mistralai/mistral-large-3-675b-instruct-2512" "qwen/qwen3-coder-480b-a35b-instruct"
"mistralai/mistral-nemotron" "bytedance/seed-oss-36b-instruct" "mistralai/mamba-codestral-7b-v0.1"
"google/gemma-7b" "tiiuae/falcon3-7b-instruct" "minimaxai/minimax-m2.7"
) do (
set "NVIDIA_MODEL_!idx!=%%~M"
echo !CYAN!!idx!^)!RESET! %%~M
set /a "idx+=1"
)
for /f "delims=" %%I in ('powershell -NoProfile -Command "$headers = @{ 'Authorization' = 'Bearer !USER_API_KEY!' }; try { $d = (Invoke-RestMethod -Uri 'https://integrate.api.nvidia.com/v1/models' -Headers $headers).data; $d | Select-Object -ExpandProperty id | Select-Object -First 40 } catch { }"') do (
set "EXISTS=0"
for /L %%K in (1,1,14) do (
if "%%I"=="!NVIDIA_MODEL_%%K!" set "EXISTS=1"
)
if !EXISTS!==0 (
set "NVIDIA_MODEL_!idx!=%%I"
echo !CYAN!!idx!^)!RESET! %%I
set /a "idx+=1"
)
)
if "!idx!"=="1" (
echo !YELLOW![API Error] Could not fetch models, using fallback...!RESET!
set "NVIDIA_MODEL_1=meta/llama-3.1-70b-instruct"
echo !CYAN!1^)!RESET! meta/llama-3.1-70b-instruct
set /a "idx=2"
)
set "MAX_IDX=!idx!"
echo !CYAN!!MAX_IDX!^)!RESET! !DIM!Custom NVIDIA Model...!RESET!
echo.
:prompt_nvidia_sel
set "MODEL_SEL="
set /p "MODEL_SEL= Choose a model !CYAN!(1-!MAX_IDX!)!RESET!: "
if defined MODEL_SEL (
if "!MODEL_SEL!"=="!MAX_IDX!" (
set /p "USER_MODEL= Enter custom model string: "
) else (
for %%V in (!MODEL_SEL!) do set "USER_MODEL=!NVIDIA_MODEL_%%V!"
)
)
if "!USER_MODEL!"=="" (
echo !RED![ERROR] Invalid selection. Please choose 1 to !MAX_IDX!.!RESET!
goto prompt_nvidia_sel
)
:save_settings_nvidia
(
echo AI_PROVIDER=openai
echo CLAUDE_CODE_USE_OPENAI=1
echo OPENAI_API_KEY=%USER_API_KEY%
echo OPENAI_BASE_URL=https://integrate.api.nvidia.com/v1
echo OPENAI_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:: ---------------------------------------------------------
:: GEMINI SETUP
:: ---------------------------------------------------------
:setup_gemini
echo.
echo !CYAN!--- GEMINI SETUP ---!RESET!
echo.
set /p "USER_API_KEY= Enter your Gemini API Key: "
if "!USER_API_KEY!"=="" (
echo !RED![ERROR] API Key cannot be empty!!RESET!
goto setup_gemini
)
set "USER_API_KEY=!USER_API_KEY: =!"
set "KEY_MASK=!USER_API_KEY:~0,6!****!USER_API_KEY:~-4!"
echo !DIM!Key: !KEY_MASK!!RESET!
echo.
echo !YELLOW![~] Verifying API Key... Please wait...!RESET!
powershell -NoProfile -Command "try { $response = Invoke-RestMethod -Uri 'https://generativelanguage.googleapis.com/v1beta/models?key=!USER_API_KEY!' -ErrorAction Stop; exit 0 } catch { exit 1 }"
if errorlevel 1 (
echo !RED![ERROR] Invalid or expired Gemini API Key!!RESET!
goto setup_gemini
)
echo !GREEN![OK] Key Verified!!RESET!
echo.
echo !CYAN!--- GEMINI MODELS ---!RESET! !DIM!(Live Fetching...)!RESET!
set "idx=1"
set "FETCH_CMD=$d = (Invoke-RestMethod 'https://generativelanguage.googleapis.com/v1alpha/models?key=!USER_API_KEY!').models; if ($null -ne $d) { $d | Where-Object { $_.supportedGenerationMethods -contains 'generateContent' -and $_.name -notmatch 'vision|embedding|banana|lyria|robot|research|computer' } | Select-Object -ExpandProperty name | ForEach-Object { $_.Replace('models/', '') } | Select-Object -First 40 }"
for /f "delims=" %%I in ('powershell -NoProfile -Command "!FETCH_CMD!"') do (
set "GEMINI_MODEL_!idx!=%%I"
echo !CYAN!!idx!^)!RESET! %%I
set /a "idx+=1"
)
if "!idx!"=="1" (
echo !YELLOW![API Error] Could not fetch models, using fallback...!RESET!
set "GEMINI_MODEL_1=gemini-2.5-pro"
echo !CYAN!1^)!RESET! gemini-2.5-pro
set /a "idx=2"
)
set "MAX_IDX=!idx!"
echo !CYAN!!MAX_IDX!^)!RESET! !DIM!Custom Gemini Model...!RESET!
echo.
:prompt_gemini_sel
set "MODEL_SEL="
set /p "MODEL_SEL= Choose a model !CYAN!(1-!MAX_IDX!)!RESET! [Enter for 1]: "
if not defined MODEL_SEL set "MODEL_SEL=1"
if "!MODEL_SEL!"=="" set "MODEL_SEL=1"
if "!MODEL_SEL!"=="!MAX_IDX!" (
set /p "USER_MODEL= Enter custom model string: "
) else (
for %%V in (!MODEL_SEL!) do set "USER_MODEL=!GEMINI_MODEL_%%V!"
)
if "!USER_MODEL!"=="" (
echo !RED![ERROR] Invalid selection.!RESET!
goto prompt_gemini_sel
)
(
echo AI_PROVIDER=gemini
echo CLAUDE_CODE_USE_GEMINI=1
echo GEMINI_API_KEY=%USER_API_KEY%
echo GEMINI_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:: ---------------------------------------------------------
:: CLAUDE SETUP
:: ---------------------------------------------------------
:setup_claude
echo.
echo !CYAN!--- CLAUDE SETUP ---!RESET!
echo.
set /p "USER_API_KEY= Enter your Anthropic API Key: "
if "!USER_API_KEY!"=="" (
echo !RED![ERROR] API Key cannot be empty!!RESET!
goto setup_claude
)
set "USER_API_KEY=!USER_API_KEY: =!"
set "KEY_MASK=!USER_API_KEY:~0,6!****!USER_API_KEY:~-4!"
echo !DIM!Key: !KEY_MASK!!RESET!
echo.
echo !YELLOW![~] Verifying API Key... Please wait...!RESET!
powershell -NoProfile -Command "$headers = @{ 'x-api-key' = '!USER_API_KEY!'; 'anthropic-version' = '2023-06-01' }; try { $response = Invoke-RestMethod -Uri 'https://api.anthropic.com/v1/models' -Headers $headers -ErrorAction Stop; exit 0 } catch { exit 1 }"
if errorlevel 1 (
echo !RED![ERROR] Invalid or expired Anthropic API Key!!RESET!
goto setup_claude
)
echo !GREEN![OK] Key Verified!!RESET!
echo.
set /p "USER_MODEL= Enter Model !DIM!(Enter for claude-3-7-sonnet-20250219)!RESET!: "
if "%USER_MODEL%"=="" set "USER_MODEL=claude-3-7-sonnet-20250219"
(
echo AI_PROVIDER=anthropic
echo ANTHROPIC_API_KEY=%USER_API_KEY%
echo ANTHROPIC_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:: ---------------------------------------------------------
:: OLLAMA SETUP
:: ---------------------------------------------------------
:setup_ollama
echo.
echo !CYAN!--- OLLAMA LOCAL SETUP ---!RESET!
echo.
set /p "USER_MODEL= Enter local model !DIM!(Enter for llama3.2:3b)!RESET!: "
if "%USER_MODEL%"=="" set "USER_MODEL=llama3.2:3b"
(
echo AI_PROVIDER=ollama
echo CLAUDE_CODE_USE_OPENAI=1
echo OPENAI_API_KEY=ollama
echo OPENAI_BASE_URL=http://localhost:11434/v1
echo OPENAI_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:: ---------------------------------------------------------
:: OPENAI SETUP
:: ---------------------------------------------------------
:setup_openai
echo.
echo !CYAN!--- OPENAI / CODEX SETUP ---!RESET!
echo.
set /p "USER_API_KEY= Enter your OpenAI API Key: "
if "!USER_API_KEY!"=="" (
echo !RED![ERROR] API Key cannot be empty!!RESET!
goto setup_openai
)
set "USER_API_KEY=!USER_API_KEY: =!"
set "KEY_MASK=!USER_API_KEY:~0,6!****!USER_API_KEY:~-4!"
echo !DIM!Key: !KEY_MASK!!RESET!
echo.
echo !YELLOW![~] Verifying API Key... Please wait...!RESET!
powershell -NoProfile -Command "$headers = @{ 'Authorization' = 'Bearer !USER_API_KEY!' }; try { $response = Invoke-RestMethod -Uri 'https://api.openai.com/v1/models' -Headers $headers -ErrorAction Stop; exit 0 } catch { exit 1 }"
if errorlevel 1 (
echo !RED![ERROR] Invalid or expired OpenAI API Key!!RESET!
goto setup_openai
)
echo !GREEN![OK] Key Verified!!RESET!
echo.
set /p "USER_MODEL= Enter Model !DIM!(Enter for gpt-4o)!RESET!: "
if "%USER_MODEL%"=="" set "USER_MODEL=gpt-4o"
(
echo AI_PROVIDER=openai
echo CLAUDE_CODE_USE_OPENAI=1
echo OPENAI_API_KEY=%USER_API_KEY%
echo OPENAI_BASE_URL=https://api.openai.com/v1
echo OPENAI_MODEL=%USER_MODEL%
echo AI_DISPLAY_MODEL=%USER_MODEL%
) > "%ENV_FILE%"
goto finish_setup
:finish_setup
echo.
echo !GREEN![OK] Settings saved!!RESET!
echo.
:: ---------------------------------------------------------
:: LOAD SETTINGS + WELCOME BACK SCREEN
:: ---------------------------------------------------------
:load_settings
:: Load the settings from ai_settings.env
for /f "usebackq tokens=1,* delims==" %%A in ("%ENV_FILE%") do (
set "%%A=%%~B"
)
if not "!AI_PROVIDER!"=="anthropic" (
set "ANTHROPIC_API_KEY="
)
:: Friendly provider name
set "PROVIDER_NAME=!AI_PROVIDER!"
if "!AI_PROVIDER!"=="openai" (
if defined OPENAI_BASE_URL (
echo !OPENAI_BASE_URL! | findstr /C:"openrouter" >nul && set "PROVIDER_NAME=OpenRouter"
echo !OPENAI_BASE_URL! | findstr /C:"integrate.api.nvidia.com" >nul && set "PROVIDER_NAME=NVIDIA NIM"
echo !OPENAI_BASE_URL! | findstr /C:"api.openai.com" >nul && set "PROVIDER_NAME=OpenAI"
echo !OPENAI_BASE_URL! | findstr /C:"localhost:11434" >nul && set "PROVIDER_NAME=Ollama"
)
)
if "!AI_PROVIDER!"=="gemini" set "PROVIDER_NAME=Google Gemini"
if "!AI_PROVIDER!"=="anthropic" set "PROVIDER_NAME=Anthropic Claude"
if "!AI_PROVIDER!"=="ollama" set "PROVIDER_NAME=Ollama (Local)"
title Portable AI USB - !PROVIDER_NAME! - !AI_DISPLAY_MODEL!
echo !CYAN!=========================================================!RESET!
echo !BOLD!Claude Code - Ready (Multi-Platform)!RESET!
echo !CYAN!=========================================================!RESET!
echo.
echo !BOLD!Provider!RESET! : !GREEN!!PROVIDER_NAME!!RESET!
echo !BOLD!Model!RESET! : !GREEN!!AI_DISPLAY_MODEL!!RESET!
echo !BOLD!Data!RESET! : !DIM!Portable Mode (No PC Leaks)!RESET!
echo.
echo !CYAN!=========================================================!RESET!
echo.
:prompt_launch_mode
:: Quick mode: skip menu, go straight to limitless
if !QUICK_MODE!==1 (
echo !RED!!BOLD!QUICK LAUNCH - Limitless Mode!RESET!
goto launch_limitless
)
echo !BOLD!Select Action:!RESET!
echo 🚀 !CYAN!1)!RESET! !GREEN!Launch AI!RESET! !DIM!- Normal Mode (Auto-starts in 10s)!RESET!
echo ⚡ !CYAN!2)!RESET! !RED!Limitless Mode!RESET! !DIM!- Auto-executes everything (Advanced)!RESET!
echo !DIM!─────────────────────────────────────────────────────────!RESET!
echo 📊 !CYAN!3)!RESET! !BOLD!Open Dashboard!RESET! !DIM!- View your chats visually!RESET!
echo ⚙️ !CYAN!4)!RESET! !BOLD!Change Provider!RESET! !DIM!- Switch your AI provider or API Key!RESET!
echo 💾 !CYAN!5)!RESET! !BOLD!Setup Offline!RESET! !DIM!- Download local AI models (Ollama)!RESET!
echo.
echo !DIM! Auto-launching in 10 seconds... press a key to choose.!RESET!
echo.
set /p "= Select action (1-5): " <nul
choice /c 12345 /n /t 10 /d 1
set "LAUNCH_MODE=!ERRORLEVEL!"
:menu_done
echo.
if "!LAUNCH_MODE!"=="1" goto launch_normal
if "!LAUNCH_MODE!"=="2" goto launch_limitless
if "!LAUNCH_MODE!"=="3" (
echo.
call "%USB_ROOT%tools\Open_Dashboard.bat"
exit /b
)
if "!LAUNCH_MODE!"=="4" (
echo.
call "%USB_ROOT%tools\Change_Provider.bat"
exit /b
)
if "!LAUNCH_MODE!"=="5" (
echo.
call "%USB_ROOT%tools\Setup_Local_Models.bat"
exit /b
)
echo !RED![ERROR] Invalid selection.!RESET!
echo.
goto prompt_launch_mode
:launch_limitless
echo.
echo !RED!!BOLD![!] LIMITLESS MODE ACTIVATED!RESET!
set "CMD_ARGS=--dangerously-skip-permissions"
goto do_launch
:launch_normal
echo.
echo !GREEN![OK] Normal mode selected.!RESET!
set "CMD_ARGS="
goto do_launch
:do_launch
if not "!AI_PROVIDER!"=="ollama" goto skip_ollama_start
if not exist "%DATA_DIR%\ollama\ollama.exe" goto skip_ollama_start
echo !CYAN![~] Starting Local Ollama Server...!RESET!
set "OLLAMA_MODELS=%DATA_DIR%\ollama\data"
start "Ollama Portable" /B /MIN "%DATA_DIR%\ollama\ollama.exe" serve >nul 2>&1
timeout /t 3 /nobreak >nul
echo !GREEN![OK] Ollama running!RESET!
if not exist "%USB_ROOT%tools\local-proxy.js" goto skip_proxy_start
echo !CYAN![~] Starting local speed proxy (trims system prompt)...!RESET!
REM Surgical kill: find any node process running local-proxy.js and kill it
powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter 'Name = ''node.exe''' | Where-Object { $_.CommandLine -like '*local-proxy.js*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }" >nul 2>&1
start "LocalProxy" /B /MIN "%NODE_DIR%\node.exe" "%USB_ROOT%tools\local-proxy.js"
timeout /t 2 /nobreak >nul
set "OPENAI_BASE_URL=http://localhost:11435/v1"
echo !GREEN![OK] Speed proxy active - system prompt trimming enabled!RESET!
:skip_proxy_start
echo.
:skip_ollama_start
echo !CYAN![~] Starting AI Engine...!RESET!
echo.
set "PROVIDER_ARGS="
if defined AI_PROVIDER set "PROVIDER_ARGS=--provider !AI_PROVIDER!"
set "OC_BIN=%ENGINE_DIR%\node_modules\@gitlawb\openclaude\bin\openclaude"
pushd "%ENGINE_DIR%"
if exist "%OC_BIN%" goto use_oc_bin
call npx.cmd openclaude !PROVIDER_ARGS! !CMD_ARGS!
goto engine_done
:use_oc_bin
call "%NODE_DIR%\node.exe" "%OC_BIN%" !PROVIDER_ARGS! !CMD_ARGS!
:engine_done
popd
if not "!AI_PROVIDER!"=="ollama" goto skip_ollama_stop
if not exist "%DATA_DIR%\ollama\ollama.exe" goto skip_ollama_stop
echo.
echo !CYAN![~] Stopping Local Ollama Server...!RESET!
taskkill /F /IM ollama.exe >nul 2>&1
powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter 'Name = ''node.exe''' | Where-Object { $_.CommandLine -like '*local-proxy.js*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }" >nul 2>&1
:skip_ollama_stop
pause