ai-account-switch 1.7.0 → 1.8.1

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_EN.md ADDED
@@ -0,0 +1,1191 @@
1
+ # AI Account Switch (ais)
2
+
3
+ [简体中文](README.md) | English
4
+
5
+ A cross-platform CLI tool to manage and switch between Claude/Codex/Droids account configurations for different projects.
6
+
7
+ ## Features
8
+
9
+ - **Cross-Platform**: Works seamlessly on macOS, Linux, and Windows
10
+ - **Multiple Accounts**: Store and manage multiple AI service accounts
11
+ - **Project-Specific**: Each project can use a different account
12
+ - **Smart Directory Detection**: Works in any subdirectory of your project (like git)
13
+ - **Claude Code Integration**: Automatically generates `.claude/settings.local.json` for Claude Code CLI
14
+ - **Secure Storage**: Account credentials stored locally in your home directory
15
+ - **Interactive CLI**: Easy-to-use interactive prompts for all operations
16
+ - **Account Types**: Support for Claude, Codex, CCR (Claude Code Router), Droids, and other AI services
17
+ - **Web UI**: Modern web interface with account status checking and management
18
+ - **MCP Web UI Management**: Complete MCP (Model Context Protocol) server management through Web UI
19
+ - Add, edit, delete MCP servers with intuitive interface
20
+ - Support for stdio, sse, and http server types
21
+ - Test MCP server connections
22
+ - Enable/disable servers per project
23
+ - Search and filter functionality
24
+ - Full internationalization (Chinese/English)
25
+
26
+ ## Installation
27
+
28
+ ### npm Installation (Recommended)
29
+
30
+ ```bash
31
+ npm install -g ai-account-switch
32
+ ```
33
+
34
+ After installation, the `ais` command will be available globally.
35
+
36
+ **Troubleshooting**: If you encounter "command not found" after installation:
37
+
38
+ ```bash
39
+ # Check npm global bin path
40
+ npm config get prefix
41
+
42
+ # Add to PATH (Linux/macOS)
43
+ export PATH="$PATH:$(npm config get prefix)/bin"
44
+
45
+ # On Windows, add to system PATH: %APPDATA%\npm
46
+ ```
47
+
48
+ ### Install from Source
49
+
50
+ ```bash
51
+ # Clone the repository
52
+ git clone https://github.com/yourusername/ai-agent-user-swith.git
53
+ cd ai-agent-user-swith
54
+
55
+ # Install dependencies
56
+ npm install
57
+
58
+ # Link the CLI tool globally
59
+ npm link
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ ### Commands Overview
65
+
66
+ | Command | Alias | Description |
67
+ |---------|-------|-------------|
68
+ | `ais add [name]` | - | Add a new account configuration |
69
+ | `ais list` | `ls` | List all available accounts |
70
+ | `ais use [name]` | - | Set account for current project |
71
+ | `ais info` | - | Show current project's account info |
72
+ | `ais current` | - | Show current account name |
73
+ | `ais remove [name]` | `rm` | Remove an account |
74
+ | `ais model list` | `ls` | List all model groups for current account |
75
+ | `ais model add [name]` | - | Add a new model group |
76
+ | `ais model use <name>` | - | Switch to a different model group |
77
+ | `ais model remove [name]` | `rm` | Remove a model group |
78
+ | `ais model show [name]` | - | Show model group configuration |
79
+ | `ais mcp add [name]` | - | Add a new MCP server |
80
+ | `ais mcp list` | `ls` | List all MCP servers |
81
+ | `ais mcp show [name]` | - | Show MCP server details |
82
+ | `ais mcp update [name]` | - | Update MCP server configuration |
83
+ | `ais mcp remove [name]` | `rm` | Remove an MCP server |
84
+ | `ais mcp enable [name]` | - | Enable MCP server for current project |
85
+ | `ais mcp disable [name]` | - | Disable MCP server for current project |
86
+ | `ais mcp enabled` | - | Show enabled MCP servers |
87
+ | `ais mcp sync` | - | Sync MCP configuration to Claude Code |
88
+ | `ais ui` | - | Start web-based UI manager |
89
+ | `ais paths` | - | Show configuration file paths |
90
+ | `ais doctor` | - | Diagnose configuration issues |
91
+ | `ais export <name>` | - | Export account as JSON |
92
+ | `ais help` | - | Display help information |
93
+ | `ais --version` | - | Show version number |
94
+
95
+ ### Quick Start
96
+
97
+ #### 1. Add an Account
98
+
99
+ Add your first account interactively:
100
+
101
+ ```bash
102
+ ais add
103
+ ```
104
+
105
+ Or specify a name directly:
106
+
107
+ ```bash
108
+ ais add my-claude-account
109
+ ```
110
+
111
+ You'll be prompted to enter:
112
+ - Account type (Claude, Codex, CCR, Droids, Other)
113
+ - API Key
114
+ - API URL (optional)
115
+ - Organization ID (optional)
116
+ - Email (optional)
117
+ - Description (optional)
118
+ - Custom environment variables (optional)
119
+ - Enter in `KEY=VALUE` format (e.g., `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`)
120
+ - The tool will display all added variables before completion
121
+ - Press Enter without input to finish adding variables
122
+
123
+ #### 2. List All Accounts
124
+
125
+ View all your configured accounts:
126
+
127
+ ```bash
128
+ ais list
129
+ # or
130
+ ais ls
131
+ ```
132
+
133
+ The active account for the current project will be marked with a green dot.
134
+
135
+ #### 3. Switch Account for Current Project
136
+
137
+ Set which account to use in your current project:
138
+
139
+ ```bash
140
+ ais use my-claude-account
141
+ ```
142
+
143
+ Or select interactively:
144
+
145
+ ```bash
146
+ ais use
147
+ ```
148
+
149
+ **Note:** This command automatically generates `.claude/settings.local.json` for Claude Code CLI integration.
150
+ You can run this command from any subdirectory within your project - it will automatically find the project root.
151
+
152
+ #### 4. Check Current Project Info
153
+
154
+ See which account is active for your current project:
155
+
156
+ ```bash
157
+ ais info
158
+ ```
159
+
160
+ Or just show the account name:
161
+
162
+ ```bash
163
+ ais current
164
+ ```
165
+
166
+ **Note:** These commands work from any subdirectory within your project, similar to how git commands work.
167
+
168
+ #### 5. Remove an Account
169
+
170
+ Remove an account you no longer need:
171
+
172
+ ```bash
173
+ ais remove old-account
174
+ # or
175
+ ais rm
176
+ ```
177
+
178
+ ### Advanced Usage
179
+
180
+ #### Show Configuration Paths
181
+
182
+ See where your configurations are stored:
183
+
184
+ ```bash
185
+ ais paths
186
+ ```
187
+
188
+ #### Export Account Configuration
189
+
190
+ Export an account's configuration as JSON:
191
+
192
+ ```bash
193
+ ais export my-claude-account
194
+ ```
195
+
196
+ ## Configuration
197
+
198
+ ### Global Configuration
199
+
200
+ All accounts are stored globally in your home directory:
201
+
202
+ - **macOS/Linux**: `~/.ai-account-switch/config.json`
203
+ - **Windows**: `%USERPROFILE%\.ai-account-switch\config.json`
204
+
205
+ ### Project Configuration
206
+
207
+ Each project stores its active account reference in:
208
+
209
+ ```
210
+ ./.ais-project-config
211
+ ```
212
+
213
+ This file is created automatically when you run `ais use` and should be added to `.gitignore`.
214
+
215
+ ### Claude Code Integration
216
+
217
+ When you run `ais use`, the tool automatically creates `.claude/settings.local.json` with the following structure:
218
+
219
+ ```json
220
+ {
221
+ "env": {
222
+ "ANTHROPIC_AUTH_TOKEN": "your-api-key",
223
+ "ANTHROPIC_BASE_URL": "your-api-url",
224
+ "ANTHROPIC_ORGANIZATION_ID": "your-org-id",
225
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
226
+ },
227
+ "permissions": {
228
+ "allow": [],
229
+ "deny": [],
230
+ "ask": []
231
+ }
232
+ }
233
+ ```
234
+
235
+ This ensures Claude Code CLI automatically uses the correct account for your project.
236
+
237
+ ### Codex Integration
238
+
239
+ When you add a **Codex** type account and run `ais use`, the tool automatically creates a profile in `~/.codex/config.toml` and a `.codex-profile` file in your project directory.
240
+
241
+ #### Adding a Codex Account
242
+
243
+ When adding a Codex account, you'll see helpful configuration tips:
244
+
245
+ ```bash
246
+ ais add my-codex-account
247
+
248
+ ? Select account type: Codex
249
+
250
+ 📝 Codex Configuration Tips:
251
+ • API URL should include the full path (e.g., https://api.example.com/v1)
252
+ • AIS will automatically add /v1 if missing
253
+ • Codex uses OpenAI-compatible API format
254
+
255
+ ? Enter API Key: sk-xxx...
256
+ ? Enter API URL (e.g., https://api.example.com or https://api.example.com/v1): https://zone.veloera.org
257
+ ```
258
+
259
+ **Important Notes:**
260
+ - AIS automatically adds `/v1` to the API URL if it's missing
261
+ - The configuration uses `wire_api = "chat"` (OpenAI-compatible format)
262
+ - This prevents common issues like Cloudflare 400 errors
263
+
264
+ #### Using Codex with Your Project
265
+
266
+ After running `ais use` with a Codex account:
267
+
268
+ ```bash
269
+ cd ~/my-project
270
+ ais use my-codex-account
271
+
272
+ # Output:
273
+ # ✓ Switched to account 'my-codex-account' for current project.
274
+ # ✓ Codex profile created: ais_my-project
275
+ # Use: codex --profile ais_my-project [prompt]
276
+ ```
277
+
278
+ The tool creates:
279
+ 1. **Global Profile**: `~/.codex/config.toml` with your account configuration
280
+ 2. **Project Reference**: `.codex-profile` containing the profile name
281
+
282
+ #### Running Codex
283
+
284
+ Use Codex with the generated profile:
285
+
286
+ ```bash
287
+ # In your project directory
288
+ codex --profile ais_my-project "your prompt here"
289
+
290
+ # Or use the profile name from .codex-profile
291
+ codex --profile $(cat .codex-profile) "your prompt"
292
+ ```
293
+
294
+ #### Codex Configuration Structure
295
+
296
+ The generated configuration in `~/.codex/config.toml`:
297
+
298
+ ```toml
299
+ # AIS Profile for project: /path/to/your/project
300
+ [profiles.ais_my-project]
301
+ model_provider = "ais_my-codex-account"
302
+
303
+ [model_providers.ais_my-codex-account]
304
+ name = "ais_my-codex-account"
305
+ base_url = "https://zone.veloera.org/v1"
306
+ wire_api = "chat"
307
+ http_headers = { "Authorization" = "Bearer sk-xxx..." }
308
+ ```
309
+
310
+ #### Switching Between Projects
311
+
312
+ Each project can use a different Codex account:
313
+
314
+ ```bash
315
+ # Project A
316
+ cd ~/project-a
317
+ ais use codex-account-1
318
+ codex --profile ais_project-a "implement feature X"
319
+
320
+ # Project B
321
+ cd ~/project-b
322
+ ais use codex-account-2
323
+ codex --profile ais_project-b "fix bug Y"
324
+ ```
325
+
326
+ #### Troubleshooting Codex
327
+
328
+ **Error: "duplicate key" in TOML**
329
+ - This happens if profiles weren't cleaned up properly
330
+ - Solution: Run `ais use <account>` again to regenerate the configuration
331
+
332
+ **Error: "400 Bad Request" from Cloudflare**
333
+ - This usually means the API URL is incorrect
334
+ - Solution: Make sure your API URL includes `/v1` or let AIS add it automatically
335
+ - Run `ais use <account>` to regenerate with the correct configuration
336
+
337
+ **Check Codex Configuration**
338
+ ```bash
339
+ # View your Codex profile
340
+ cat .codex-profile
341
+
342
+ # Check the configuration
343
+ grep -A 10 "$(cat .codex-profile)" ~/.codex/config.toml
344
+
345
+ # Or use the doctor command
346
+ ais doctor
347
+ ```
348
+
349
+ ### CCR (Claude Code Router) Integration
350
+
351
+ [Claude Code Router](https://github.com/musistudio/claude-code-router) is a powerful routing layer for Claude Code that allows you to use multiple AI providers and models seamlessly.
352
+
353
+ When you add a **CCR** type account and run `ais use`, the tool automatically:
354
+ 1. Updates `~/.claude-code-router/config.json` with Provider and Router configuration
355
+ 2. Generates `.claude/settings.local.json` pointing to the local CCR Router
356
+ 3. Automatically restarts CCR Router to apply changes
357
+
358
+ **Prerequisites:**
359
+ - Install Claude Code Router: `npm install -g @musistudio/claude-code-router`
360
+ - Start CCR Router: `ccr start`
361
+
362
+ #### Adding a CCR Account
363
+
364
+ When adding a CCR account, you'll see helpful configuration tips:
365
+
366
+ ```bash
367
+ ais add my-ccr-account
368
+
369
+ ? Select account type: CCR
370
+
371
+ 📝 CCR Configuration Tips:
372
+ • CCR configuration will be stored in ~/.claude-code-router/config.json
373
+ • You need to provide Provider name and models
374
+ • Router configuration will be automatically updated
375
+
376
+ ? Enter API Key: sk-xxx...
377
+ ? Enter API URL: http://localhost:3000/v1/chat/completions
378
+ ? Enter Provider name: Local-new-api
379
+ ? Enter default model: gemini-2.5-flash
380
+ ? Enter background model: gemini-2.5-flash
381
+ ? Enter think model: gemini-2.5-pro
382
+ ```
383
+
384
+ **Important Notes:**
385
+ - Default API URL is `http://localhost:3000/v1/chat/completions`
386
+ - You need to specify three models: default, background, and think
387
+ - Models are automatically deduplicated in the Provider configuration
388
+
389
+ #### Using CCR with Your Project
390
+
391
+ After running `ais use` with a CCR account:
392
+
393
+ ```bash
394
+ cd ~/my-project
395
+ ais use my-ccr-account
396
+
397
+ # Output:
398
+ # ✓ Switched to account 'my-ccr-account' for current project.
399
+ # 🔄 Restarting CCR Router...
400
+ # ✓ CCR Router restarted successfully
401
+ # ✓ CCR configuration updated at: ~/.claude-code-router/config.json
402
+ # ✓ Claude configuration generated at: .claude/settings.local.json
403
+ #
404
+ # 📖 Next Steps:
405
+ # Start interactive session: claude
406
+ # This will enter project-level interactive mode
407
+ # Claude Code will use CCR Router to route requests
408
+ ```
409
+
410
+ The tool:
411
+ 1. **Updates CCR Config**: Adds/updates Provider in `~/.claude-code-router/config.json`
412
+ 2. **Updates Router**: Sets default, background, and think models
413
+ 3. **Generates Claude Config**: Creates `.claude/settings.local.json` with `ANTHROPIC_BASE_URL` pointing to CCR Router
414
+ 4. **Restarts CCR**: Automatically runs `ccr restart` to apply changes
415
+
416
+ #### Running Claude with CCR
417
+
418
+ Start Claude interactive session:
419
+
420
+ ```bash
421
+ # In your project directory
422
+ claude
423
+
424
+ # Claude Code will automatically use CCR Router
425
+ # Requests are routed based on your CCR configuration
426
+ ```
427
+
428
+ #### CCR Configuration Structure
429
+
430
+ The generated configuration in `~/.claude-code-router/config.json`:
431
+
432
+ ```json
433
+ {
434
+ "PORT": 3456,
435
+ "Providers": [
436
+ {
437
+ "api_base_url": "http://localhost:3000/v1/chat/completions",
438
+ "api_key": "sk-xxx...",
439
+ "models": ["gemini-2.5-flash", "gemini-2.5-pro"],
440
+ "name": "Local-new-api"
441
+ }
442
+ ],
443
+ "Router": {
444
+ "default": "Local-new-api,gemini-2.5-flash",
445
+ "background": "Local-new-api,gemini-2.5-flash",
446
+ "think": "Local-new-api,gemini-2.5-pro"
447
+ }
448
+ }
449
+ ```
450
+
451
+ The generated configuration in `.claude/settings.local.json`:
452
+
453
+ ```json
454
+ {
455
+ "env": {
456
+ "ANTHROPIC_AUTH_TOKEN": "your-api-key",
457
+ "ANTHROPIC_BASE_URL": "http://127.0.0.1:3456"
458
+ }
459
+ }
460
+ ```
461
+
462
+ #### Switching Between Projects
463
+
464
+ Each project can use a different CCR configuration:
465
+
466
+ ```bash
467
+ # Project A
468
+ cd ~/project-a
469
+ ais use ccr-account-1
470
+ claude
471
+
472
+ # Project B
473
+ cd ~/project-b
474
+ ais use ccr-account-2
475
+ claude
476
+ ```
477
+
478
+ #### Troubleshooting CCR
479
+
480
+ **Check CCR Configuration**
481
+ ```bash
482
+ # View your CCR configuration
483
+ cat ~/.claude-code-router/config.json
484
+
485
+ # View Claude configuration
486
+ cat .claude/settings.local.json
487
+
488
+ # Or use the doctor command
489
+ ais doctor
490
+ ```
491
+
492
+ **CCR Router not installed**
493
+ - Install from npm: `npm install -g @musistudio/claude-code-router`
494
+ - Visit the project page: https://github.com/musistudio/claude-code-router
495
+
496
+ **CCR Router not restarting**
497
+ - Make sure CCR CLI is installed and available in your PATH
498
+ - Run `ccr restart` manually if automatic restart fails
499
+ - Check if CCR Router is running: `ccr status`
500
+
501
+ **Claude not using CCR Router**
502
+ - Verify `ANTHROPIC_BASE_URL` in `.claude/settings.local.json` points to correct port
503
+ - Check CCR Router is running on the configured port
504
+ - Restart Claude Code after configuration changes
505
+
506
+ ### Droids Integration
507
+
508
+ When you add a **Droids** type account and run `ais use`, the tool automatically creates a configuration file at `.droids/config.json` in your project directory.
509
+
510
+ #### Adding a Droids Account
511
+
512
+ When adding a Droids account, you'll see helpful configuration tips:
513
+
514
+ ```bash
515
+ ais add my-droids-account
516
+
517
+ ? Select account type: Droids
518
+
519
+ 📝 Droids Configuration Tips:
520
+ • Droids configuration will be stored in .droids/config.json
521
+ • API URL is optional (defaults to Droids default endpoint)
522
+ • You can configure custom models and settings
523
+
524
+ ? Enter API Key: sk-xxx...
525
+ ? Enter API URL (optional): https://api.example.com
526
+ ? Do you want to specify a model? (Optional) Yes
527
+ ? Enter model name: droids-model-v1
528
+ ```
529
+
530
+ #### Using Droids with Your Project
531
+
532
+ After running `ais use` with a Droids account:
533
+
534
+ ```bash
535
+ cd ~/my-project
536
+ ais use my-droids-account
537
+
538
+ # Output:
539
+ # ✓ Switched to account 'my-droids-account' for current project.
540
+ # ✓ Droids configuration generated at: .droids/config.json
541
+ #
542
+ # 📖 Next Steps:
543
+ # Start interactive session: droid
544
+ # This will enter project-level interactive mode
545
+ # Droids will automatically use the configuration from .droids/config.json
546
+ ```
547
+
548
+ The tool creates:
549
+ - **Project Configuration**: `.droids/config.json` with your account settings
550
+
551
+ #### Running Droids
552
+
553
+ Start Droids interactive session:
554
+
555
+ ```bash
556
+ # In your project directory
557
+ droid
558
+
559
+ # Droids will automatically load configuration from .droids/config.json
560
+ ```
561
+
562
+ #### Droids Configuration Structure
563
+
564
+ The generated configuration in `.droids/config.json`:
565
+
566
+ ```json
567
+ {
568
+ "apiKey": "your-api-key",
569
+ "baseUrl": "https://api.example.com",
570
+ "model": "droids-model-v1",
571
+ "customSettings": {
572
+ "CUSTOM_VAR": "value"
573
+ }
574
+ }
575
+ ```
576
+
577
+ #### Switching Between Projects
578
+
579
+ Each project can use a different Droids account:
580
+
581
+ ```bash
582
+ # Project A
583
+ cd ~/project-a
584
+ ais use droids-account-1
585
+ droid
586
+
587
+ # Project B
588
+ cd ~/project-b
589
+ ais use droids-account-2
590
+ droid
591
+ ```
592
+
593
+ #### Troubleshooting Droids
594
+
595
+ **Check Droids Configuration**
596
+ ```bash
597
+ # View your Droids configuration
598
+ cat .droids/config.json
599
+
600
+ # Or use the doctor command
601
+ ais doctor
602
+ ```
603
+
604
+ **Droids CLI not found**
605
+ - Make sure Droids CLI is installed and available in your PATH
606
+ - Run `droid --version` to verify installation
607
+
608
+ #### Custom Environment Variables
609
+
610
+ You can add custom environment variables when creating an account. When prompted, enter them in `KEY=VALUE` format:
611
+
612
+ **Input Format:**
613
+ ```
614
+ ? Environment variable (KEY=VALUE format): CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
615
+ ✓ Added: CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
616
+
617
+ 📋 Current environment variables:
618
+ • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
619
+
620
+ ? Add another environment variable? (y/N)
621
+ ```
622
+
623
+ **Common Examples:**
624
+ - `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1` - Disable non-essential network traffic
625
+ - `HTTP_PROXY=http://proxy.example.com:8080` - Set HTTP proxy
626
+ - `HTTPS_PROXY=https://proxy.example.com:8080` - Set HTTPS proxy
627
+ - Any other environment variables needed for your setup
628
+
629
+ **Features:**
630
+ - One-line input format (`KEY=VALUE`)
631
+ - Real-time display of added variables
632
+ - Press Enter without input to finish
633
+ - Variables are automatically included in `.claude/settings.local.json`
634
+
635
+ ### MCP (Model Context Protocol) Integration
636
+
637
+ AIS supports managing MCP servers globally and enabling them per project. MCP servers extend Claude Code with additional tools and capabilities.
638
+
639
+ You can manage MCP servers through both **CLI commands** and **Web UI**.
640
+
641
+ #### Web UI Management (Recommended)
642
+
643
+ The easiest way to manage MCP servers is through the Web UI:
644
+
645
+ ```bash
646
+ ais ui
647
+ ```
648
+
649
+ Then click on the **"MCP 服务器" (MCP Servers)** tab to:
650
+
651
+ **Features:**
652
+ - ✅ **Add MCP Servers**: Click "+ 添加 MCP 服务器" to add new servers
653
+ - Choose server type: stdio, sse, or http
654
+ - Fill in configuration (command, URL, environment variables, etc.)
655
+ - Add description for easy identification
656
+ - ✅ **Edit Servers**: Click "编辑" to modify existing server configurations
657
+ - ✅ **Test Connection**: Click "测试连接" to verify server availability
658
+ - ✅ **Enable/Disable**: Toggle servers for the current project with one click
659
+ - ✅ **Search & Filter**: Quickly find servers by name or type
660
+ - ✅ **Delete Servers**: Remove servers you no longer need
661
+ - ✅ **Sync Configuration**: Click "同步配置" to sync to Claude Code
662
+
663
+ **Benefits:**
664
+ - Intuitive visual interface
665
+ - Real-time validation
666
+ - No need to remember command syntax
667
+ - See all servers at a glance
668
+ - Status indicators (enabled/disabled)
669
+ - Supports Chinese and English
670
+
671
+ **Example Workflow:**
672
+ 1. Start Web UI: `ais ui`
673
+ 2. Click "MCP 服务器" tab
674
+ 3. Click "+ 添加 MCP 服务器"
675
+ 4. Select type: "stdio"
676
+ 5. Enter command: "npx"
677
+ 6. Enter arguments: "@modelcontextprotocol/server-filesystem,/path"
678
+ 7. Click "保存"
679
+ 8. Click "测试连接" to verify
680
+ 9. Click "启用" to enable for current project
681
+
682
+ #### CLI Management
683
+
684
+ You can also manage MCP servers through CLI commands:
685
+
686
+ ##### Adding an MCP Server
687
+
688
+ Add a new MCP server interactively:
689
+
690
+ ```bash
691
+ ais mcp add filesystem
692
+ ```
693
+
694
+ You'll be prompted to configure:
695
+ - **Server type**: stdio, sse, or http
696
+ - **Command and arguments** (for stdio type)
697
+ - **URL** (for sse/http types)
698
+ - **Environment variables** (optional)
699
+ - **Headers** (optional for sse/http)
700
+ - **Description** (optional)
701
+
702
+ **Example: Adding a stdio MCP server**
703
+ ```bash
704
+ $ ais mcp add filesystem
705
+ ? Select MCP server type: stdio
706
+ ? Enter command: npx
707
+ ? Enter arguments (comma-separated): @modelcontextprotocol/server-filesystem,/Users/user/workspace
708
+ ? Add environment variables? Yes
709
+ ? Environment variable (KEY=VALUE): ALLOWED_PATHS=/Users/user/workspace
710
+ ? Add another? No
711
+ ? Enter description: File system access MCP server
712
+ ✓ MCP server 'filesystem' added successfully!
713
+ ```
714
+
715
+ ##### Listing MCP Servers
716
+
717
+ View all configured MCP servers:
718
+
719
+ ```bash
720
+ ais mcp list
721
+ ```
722
+
723
+ Output shows server name, type, enabled status, and description.
724
+
725
+ ##### Enabling MCP Servers for a Project
726
+
727
+ Enable an MCP server for the current project:
728
+
729
+ ```bash
730
+ cd ~/my-project
731
+ ais mcp enable filesystem
732
+ ```
733
+
734
+ This will:
735
+ 1. Add the server to the project's enabled list
736
+ 2. Update `.claude/settings.local.json` with the MCP configuration
737
+ 3. Make the MCP server available to Claude Code in this project
738
+
739
+ ##### Managing MCP Servers
740
+
741
+ ```bash
742
+ # Show MCP server details
743
+ ais mcp show filesystem
744
+
745
+ # Update MCP server configuration
746
+ ais mcp update filesystem
747
+
748
+ # Disable MCP server for current project
749
+ ais mcp disable filesystem
750
+
751
+ # Show enabled MCP servers for current project
752
+ ais mcp enabled
753
+
754
+ # Sync MCP configuration to Claude Code
755
+ ais mcp sync
756
+
757
+ # Remove an MCP server
758
+ ais mcp remove filesystem
759
+ ```
760
+
761
+ #### MCP Configuration Structure
762
+
763
+ MCP servers are stored globally in `~/.ai-account-switch/config.json`:
764
+
765
+ ```json
766
+ {
767
+ "accounts": { ... },
768
+ "mcpServers": {
769
+ "filesystem": {
770
+ "name": "filesystem",
771
+ "type": "stdio",
772
+ "command": "npx",
773
+ "args": ["@modelcontextprotocol/server-filesystem", "/Users/user/workspace"],
774
+ "env": {
775
+ "ALLOWED_PATHS": "/Users/user/workspace"
776
+ },
777
+ "description": "File system access MCP server",
778
+ "createdAt": "2025-01-03T00:00:00.000Z",
779
+ "updatedAt": "2025-01-03T00:00:00.000Z"
780
+ }
781
+ }
782
+ }
783
+ ```
784
+
785
+ Project-level enabled servers are stored in `.ais-project-config`:
786
+
787
+ ```json
788
+ {
789
+ "activeAccount": "my-account",
790
+ "projectPath": "/path/to/project",
791
+ "setAt": "2025-01-03T00:00:00.000Z",
792
+ "enabledMcpServers": ["filesystem"]
793
+ }
794
+ ```
795
+
796
+ When enabled, MCP servers are automatically added to `.claude/settings.local.json`:
797
+
798
+ ```json
799
+ {
800
+ "env": { ... },
801
+ "permissions": { ... },
802
+ "mcpServers": {
803
+ "filesystem": {
804
+ "command": "npx",
805
+ "args": ["@modelcontextprotocol/server-filesystem", "/Users/user/workspace"],
806
+ "env": {
807
+ "ALLOWED_PATHS": "/Users/user/workspace"
808
+ }
809
+ }
810
+ }
811
+ }
812
+ ```
813
+
814
+ #### MCP Server Types
815
+
816
+ **stdio**: Communicates via standard input/output
817
+ - Requires: `command`, `args`
818
+ - Optional: `env`
819
+
820
+ **sse**: Server-Sent Events
821
+ - Requires: `url`
822
+ - Optional: `headers`
823
+
824
+ **http**: HTTP requests
825
+ - Requires: `url`
826
+ - Optional: `headers`
827
+
828
+ ## Examples
829
+
830
+ ### Example 1: Setting Up Multiple Accounts
831
+
832
+ ```bash
833
+ # Add your personal Claude account
834
+ ais add personal-claude
835
+
836
+ # Add your work Claude account
837
+ ais add work-claude
838
+
839
+ # Add a Codex account
840
+ ais add codex-dev
841
+
842
+ # Add a Droids account
843
+ ais add droids-dev
844
+
845
+ # List all accounts
846
+ ais list
847
+ ```
848
+
849
+ ### Example 2: Using Different Accounts for Different Projects
850
+
851
+ ```bash
852
+ # In your personal project
853
+ cd ~/my-personal-project
854
+ ais use personal-claude
855
+
856
+ # In your work project
857
+ cd ~/work/company-project
858
+ ais use work-claude
859
+
860
+ # Check what's active
861
+ ais info
862
+ ```
863
+
864
+ ### Example 3: Managing Accounts
865
+
866
+ ```bash
867
+ # View all accounts
868
+ ais list
869
+
870
+ # Check current account
871
+ ais current
872
+
873
+ # Export an account config
874
+ ais export personal-claude
875
+
876
+ # Remove old accounts
877
+ ais remove old-account
878
+
879
+ # View config locations
880
+ ais paths
881
+ ```
882
+
883
+ ## Security Notes
884
+
885
+ - API keys are stored locally on your machine only
886
+ - The global configuration file contains sensitive credentials
887
+ - Always add `.ais-project-config` to your `.gitignore`
888
+ - Never commit account credentials to version control
889
+ - API keys are masked when displayed (shows first and last 4 characters only)
890
+
891
+ ## Platform Compatibility
892
+
893
+ | Platform | Status | Notes |
894
+ |----------|--------|-------|
895
+ | macOS | ✅ Fully Supported | Tested on macOS 10.15+ |
896
+ | Linux | ✅ Fully Supported | Tested on Ubuntu 20.04+ |
897
+ | Windows | ✅ Fully Supported | Tested on Windows 10+ |
898
+
899
+ ## Requirements
900
+
901
+ - **Node.js**: >= 16.0.0
902
+ - **npm**: >= 7.0.0
903
+
904
+ **Note**: This tool requires Node.js version 16 or higher (due to commander@11.x dependency). You can check your current version with:
905
+ ```bash
906
+ node --version
907
+ npm --version
908
+ ```
909
+
910
+ If you need to upgrade Node.js, visit [nodejs.org](https://nodejs.org/) or use a version manager like [nvm](https://github.com/nvm-sh/nvm).
911
+
912
+ ## Project Structure
913
+
914
+ ```
915
+ ai-agent-user-swith/
916
+ ├── bin/
917
+ │ └── ais.js # Executable entry point
918
+ ├── src/
919
+ │ ├── index.js # Main CLI program
920
+ │ ├── commands.js # Command implementations
921
+ │ └── config.js # Configuration manager
922
+ ├── package.json
923
+ ├── .gitignore
924
+ └── README.md
925
+ ```
926
+
927
+ ## Troubleshooting
928
+
929
+ ### Command not found: ais
930
+
931
+ If you get this error after installation, make sure you've linked the package:
932
+
933
+ ```bash
934
+ npm link
935
+ ```
936
+
937
+ ### Permission denied
938
+
939
+ On Unix systems, ensure the bin file is executable:
940
+
941
+ ```bash
942
+ chmod +x bin/ais.js
943
+ ```
944
+
945
+ ### No accounts found
946
+
947
+ Make sure you've added at least one account:
948
+
949
+ ```bash
950
+ ais add
951
+ ```
952
+
953
+ ### Claude Code uses wrong account
954
+
955
+ If Claude Code is using a different account than expected:
956
+
957
+ 1. Run diagnostics:
958
+ ```bash
959
+ ais doctor
960
+ ```
961
+
962
+ 2. Check if global Claude config is overriding project config:
963
+ - If `~/.claude/settings.json` contains `env.ANTHROPIC_AUTH_TOKEN`, it may conflict
964
+ - **Solution**: Remove the `env` section from global config, or only keep `permissions`
965
+
966
+ 3. Ensure you're starting Claude Code from your project directory or subdirectory
967
+
968
+ 4. Regenerate project config:
969
+ ```bash
970
+ ais use <your-account-name>
971
+ ```
972
+
973
+ ### Project config not found in subdirectory
974
+
975
+ The tool should work in any subdirectory. If it doesn't:
976
+
977
+ ```bash
978
+ # Make sure you're within a configured project
979
+ cd /path/to/your/project
980
+ ais use <account>
981
+
982
+ # Then try from subdirectory
983
+ cd src/
984
+ ais current # Should show your account
985
+ ```
986
+
987
+ ## Contributing
988
+
989
+ Contributions are welcome! Feel free to:
990
+ - Report bugs
991
+ - Suggest new features
992
+ - Submit pull requests
993
+
994
+ ## License
995
+
996
+ MIT License - feel free to use this tool in your projects!
997
+
998
+ ## Changelog
999
+
1000
+ ### v1.7.0
1001
+ - **MCP Web UI Management**:
1002
+ - Complete MCP server management through Web UI
1003
+ - Tab navigation system (Accounts / MCP Servers)
1004
+ - Add, edit, delete MCP servers with intuitive interface
1005
+ - Test MCP server connections
1006
+ - Enable/disable servers per project with one click
1007
+ - Search and filter functionality
1008
+ - Real-time validation and status indicators
1009
+ - Full internationalization (Chinese/English)
1010
+ - **MCP CLI Integration**:
1011
+ - Global MCP server management with `ais mcp` commands
1012
+ - Project-level MCP server enable/disable functionality
1013
+ - Support for stdio, sse, and http MCP server types
1014
+ - Automatic Claude Code configuration generation with MCP servers
1015
+ - Commands: `ais mcp add`, `ais mcp list`, `ais mcp show`, `ais mcp update`, `ais mcp remove`
1016
+ - Project commands: `ais mcp enable`, `ais mcp disable`, `ais mcp enabled`, `ais mcp sync`
1017
+ - Interactive MCP server configuration with validation
1018
+ - Environment variables and headers support for MCP servers
1019
+ - **Bug Fixes**:
1020
+ - Fixed account data not showing after adding tabs
1021
+ - Fixed "switchTab is not defined" error
1022
+ - Fixed incorrect search result messages
1023
+ - **Improvements**:
1024
+ - Better user experience with clearer messages
1025
+ - Modern JavaScript practices (event listeners)
1026
+ - Improved code quality and maintainability
1027
+ - 32 automated tests all passing
1028
+
1029
+ ### v1.6.0
1030
+ - **CCR (Claude Code Router) Integration**:
1031
+ - Added full support for Claude Code Router
1032
+ - Automatic generation of `~/.claude-code-router/config.json` configuration
1033
+ - Provider and Router configuration management
1034
+ - Automatic CCR Router restart after configuration changes
1035
+ - Claude Code integration with local CCR Router endpoint
1036
+ - Support for default, background, and think model routing
1037
+ - **Web UI Enhancements**:
1038
+ - Added account status checking with color-coded indicators (green: available, orange: unstable, red: unavailable)
1039
+ - Status results are saved and displayed on page load
1040
+ - Real-time status checking with "状态检查" button
1041
+ - Improved account card layout with status in top-right corner
1042
+ - Enhanced visual feedback during status checks
1043
+ - **Configuration Improvements**:
1044
+ - CCR accounts automatically generate both CCR and Claude configurations
1045
+ - Dynamic port reading from CCR config for Claude integration
1046
+ - Better error handling and user feedback
1047
+
1048
+ ### v1.5.8
1049
+ - **Bilingual Support (双语支持)**:
1050
+ - All CLI commands now display both English and Chinese text (所有 CLI 命令现在同时显示中英文)
1051
+ - Help messages, prompts, and output messages are bilingual (帮助信息、提示和输出消息都支持双语)
1052
+ - Better user experience for Chinese-speaking users (为中文用户提供更好的使用体验)
1053
+ - No configuration needed - works out of the box (无需配置 - 开箱即用)
1054
+ - Uses parentheses format for better clarity: `English text (中文)` (使用括号格式更清晰)
1055
+
1056
+ ### v1.5.7
1057
+ - **Droids Integration**:
1058
+ - Added full support for Droids AI assistant
1059
+ - Automatic generation of `.droids/config.json` configuration
1060
+ - Simple model configuration for Droids accounts
1061
+ - Interactive session command: `droid`
1062
+ - Enhanced `ais doctor` command with Droids configuration detection
1063
+ - **UI Enhancements**:
1064
+ - Added type filter dropdown for quick account filtering
1065
+ - Color-coded account cards by type (Claude: blue, Codex: purple, Droids: green, Other: orange)
1066
+ - Left border color indicators on account cards
1067
+ - Improved visual hierarchy and user experience
1068
+ - **Model Configuration Improvements**:
1069
+ - Separated model configuration for different account types
1070
+ - Claude: Complex model groups with multiple model settings
1071
+ - Codex/Droids: Simple model field for straightforward configuration
1072
+ - All model settings moved to collapsible "Advanced Configuration" section
1073
+ - **Better User Guidance**:
1074
+ - Enhanced `ais use` command with clear next-step instructions
1075
+ - Type-specific usage examples for each AI assistant
1076
+ - Interactive mode prompts instead of one-time command examples
1077
+
1078
+ ### v1.5.1
1079
+ - **Codex Integration Enhancements**:
1080
+ - Added full support for Codex CLI with profile-based configuration
1081
+ - Automatic generation of `~/.codex/config.toml` profiles for Codex accounts
1082
+ - Project-level `.codex-profile` file for easy profile reference
1083
+ - Smart API URL handling: automatically adds `/v1` path if missing
1084
+ - Uses OpenAI-compatible `wire_api = "chat"` format
1085
+ - Prevents Cloudflare 400 errors with correct configuration
1086
+ - **Improved User Experience**:
1087
+ - Configuration tips displayed when adding Codex accounts
1088
+ - Usage instructions shown after account creation
1089
+ - Enhanced `ais doctor` command with Codex configuration detection
1090
+ - Better duplicate profile cleanup in TOML files
1091
+ - **Bug Fixes**:
1092
+ - Fixed duplicate profile key errors in Codex configuration
1093
+ - Improved profile deletion regex patterns
1094
+ - Separated Claude and Codex configuration generation logic
1095
+ - **Documentation**:
1096
+ - Comprehensive Codex integration guide in README
1097
+ - Troubleshooting section for common Codex issues
1098
+ - Examples for multi-project Codex usage
1099
+
1100
+ ### v1.5.0
1101
+ - **Model Groups Management System**:
1102
+ - Refactored model configuration to use flexible Model Groups
1103
+ - Each account can have multiple model groups with different configurations
1104
+ - Quick switching between model groups with automatic Claude config updates
1105
+ - **New CLI Commands**:
1106
+ - `ais model list/ls` - List all model groups for current account
1107
+ - `ais model add [name]` - Create a new model group
1108
+ - `ais model use <name>` - Switch to a different model group
1109
+ - `ais model remove/rm [name]` - Remove a model group
1110
+ - `ais model show [name]` - Show model group configuration
1111
+ - **Enhancements**:
1112
+ - Enhanced account creation workflow with model group support
1113
+ - Web UI updated with collapsible model group management
1114
+ - Fixed model configuration not switching when changing accounts
1115
+ - Better color consistency in CLI output
1116
+ - DEFAULT_MODEL auto-fills other model configs when not specified
1117
+ - **Backward Compatibility**:
1118
+ - Maintains support for old modelConfig structure
1119
+ - Existing accounts continue to work without migration
1120
+
1121
+ ### v1.4.0
1122
+ - **Added Web UI Management Interface**:
1123
+ - Modern single-page application with dark/light theme support
1124
+ - Bilingual support (English/Chinese), default English
1125
+ - Visual account management: CRUD operations at a glance
1126
+ - Import/Export functionality: batch manage account configurations
1127
+ - Real-time search and filter accounts
1128
+ - Custom environment variables configuration
1129
+ - Theme follows system settings automatically
1130
+ - iOS-style theme toggle switch
1131
+ - **Port Optimization**:
1132
+ - UI server uses random high ports (49152-65535)
1133
+ - Automatic port conflict detection and retry
1134
+ - **UI Improvements**:
1135
+ - Fixed inconsistent button positioning in account cards
1136
+ - Buttons now consistently fixed at card bottom
1137
+ - **Removed Organization ID**:
1138
+ - Simplified account configuration process
1139
+ - Removed organization ID option from CLI and UI
1140
+
1141
+ ### v1.3.0
1142
+ - **Improved custom environment variables input**:
1143
+ - One-line `KEY=VALUE` format input (e.g., `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`)
1144
+ - Real-time display of added variables during configuration
1145
+ - Press Enter without input to finish adding variables
1146
+ - Better error messages and user guidance
1147
+ - Enhanced documentation with detailed examples and usage instructions
1148
+
1149
+ ### v1.2.0
1150
+ - Added custom environment variables support for accounts
1151
+ - Added `ais doctor` command for configuration diagnostics
1152
+ - Enhanced `ais help` with all new features
1153
+ - Updated installation documentation (npm as recommended method)
1154
+ - Improved PATH configuration instructions
1155
+ - Display custom env variables in `ais list` and `ais info`
1156
+
1157
+ ### v1.1.0
1158
+ - Added smart directory detection (works in any subdirectory)
1159
+ - Automatic Claude Code `.claude/settings.local.json` generation
1160
+ - Project root display in `ais info` command
1161
+ - Improved cross-platform compatibility
1162
+
1163
+ ### v1.0.0
1164
+ - Initial release
1165
+ - Basic account management (add, list, remove)
1166
+ - Project-specific account switching
1167
+ - Cross-platform support
1168
+ - Interactive CLI prompts
1169
+ - Account export functionality
1170
+
1171
+ ## Future Enhancements
1172
+
1173
+ Potential features for future versions:
1174
+ - Account validation
1175
+ - Bulk import/export
1176
+ - Account templates
1177
+ - Environment variable export
1178
+ - Account sharing (encrypted)
1179
+ - Cloud sync support
1180
+ - Account usage statistics
1181
+
1182
+ ## Support
1183
+
1184
+ If you encounter any issues or have questions:
1185
+ 1. Check the troubleshooting section
1186
+ 2. Review existing issues
1187
+ 3. Create a new issue with detailed information
1188
+
1189
+ ---
1190
+
1191
+ **Happy coding with your AI assistants!** 🤖