claude-switch 1.0.0__tar.gz
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.
- claude_switch-1.0.0/.claude/commands/spec.md +134 -0
- claude_switch-1.0.0/.claude/settings.local.json +50 -0
- claude_switch-1.0.0/.gitignore +11 -0
- claude_switch-1.0.0/.python-version +1 -0
- claude_switch-1.0.0/CLAUDE.md +140 -0
- claude_switch-1.0.0/LICENSE +21 -0
- claude_switch-1.0.0/PKG-INFO +290 -0
- claude_switch-1.0.0/README.md +255 -0
- claude_switch-1.0.0/claude_switch/__init__.py +14 -0
- claude_switch-1.0.0/claude_switch/cli.py +694 -0
- claude_switch-1.0.0/claude_switch/config.py +529 -0
- claude_switch-1.0.0/claude_switch/core.py +189 -0
- claude_switch-1.0.0/pyproject.toml +47 -0
- claude_switch-1.0.0/specs/pip-global-installation/requirements.md +85 -0
- claude_switch-1.0.0/uv.lock +137 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Requirements Gathering Generation
|
|
2
|
+
|
|
3
|
+
Workflow Stage: Requirements Gathering
|
|
4
|
+
|
|
5
|
+
First, generate an initial set of requirements in EARS format based on the feature idea, then iterate with the user to refine them until they are complete and accurate.
|
|
6
|
+
|
|
7
|
+
Don't focus on code exploration in this phase. Instead, just focus on writing requirements which will later be turned into
|
|
8
|
+
a design.
|
|
9
|
+
|
|
10
|
+
**Constraints:**
|
|
11
|
+
|
|
12
|
+
- The model MUST create a 'specs/{feature_name}/requirements.md' file if it doesn't already exist
|
|
13
|
+
- The model MUST generate an initial version of the requirements document based on the user's rough idea WITHOUT asking sequential questions first
|
|
14
|
+
- The model MUST format the initial requirements.md document with:
|
|
15
|
+
- A clear introduction section that summarizes the feature
|
|
16
|
+
- A hierarchical numbered list of requirements where each contains:
|
|
17
|
+
- A user story in the format "As a [role], I want [feature], so that [benefit]"
|
|
18
|
+
- A numbered list of acceptance criteria in EARS format (Easy Approach to Requirements Syntax)
|
|
19
|
+
- Example format:
|
|
20
|
+
[includes example format here]
|
|
21
|
+
- The model SHOULD consider edge cases, user experience, technical constraints, and success criteria in the initial requirements
|
|
22
|
+
- After updating the requirement document, the model MUST ask the user "Do the requirements look good? If so, we can move on to the design." using the 'userInput' tool.
|
|
23
|
+
- The 'userInput' tool MUST be used with the exact string 'spec-requirements-review' as the reason
|
|
24
|
+
- The model MUST make modifications to the requirements document if the user requests changes or does not explicitly approve
|
|
25
|
+
- The model MUST ask for explicit approval after every iteration of edits to the requirements document
|
|
26
|
+
- The model MUST NOT proceed to the design document until receiving clear approval (such as "yes", "approved", "looks good", etc.)
|
|
27
|
+
- The model MUST continue the feedback-revision cycle until explicit approval is received
|
|
28
|
+
- The model SHOULD suggest specific areas where the requirements might need clarification or expansion
|
|
29
|
+
- The model MAY ask targeted questions about specific aspects of the requirements that need clarification
|
|
30
|
+
- The model MAY suggest options when the user is unsure about a particular aspect
|
|
31
|
+
- The model MUST proceed to the design phase after the user accepts the requirements
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Design Document Creation Generation
|
|
35
|
+
|
|
36
|
+
Workflow Stage: Design Document Creation
|
|
37
|
+
|
|
38
|
+
After the user approves the Requirements, you should develop a comprehensive design document based on the feature requirements, conducting necessary research during the design process.
|
|
39
|
+
The design document should be based on the requirements document, so ensure it exists first.
|
|
40
|
+
|
|
41
|
+
**Constraints:**
|
|
42
|
+
|
|
43
|
+
- The model MUST create a 'specs/{feature_name}/design.md' file if it doesn't already exist
|
|
44
|
+
- The model MUST identify areas where research is needed based on the feature requirements
|
|
45
|
+
- The model MUST conduct research and build up context in the conversation thread
|
|
46
|
+
- The model SHOULD NOT create separate research files, but instead use the research as context for the design and implementation plan
|
|
47
|
+
- The model MUST summarize key findings that will inform the feature design
|
|
48
|
+
- The model SHOULD cite sources and include relevant links in the conversation
|
|
49
|
+
- The model MUST create a detailed design document at 'specs/{feature_name}/design.md'
|
|
50
|
+
- The model MUST incorporate research findings directly into the design process
|
|
51
|
+
- The model MUST include the following sections in the design document:
|
|
52
|
+
- Overview
|
|
53
|
+
- Architecture
|
|
54
|
+
- Components and Interfaces
|
|
55
|
+
- Data Models
|
|
56
|
+
- Error Handling
|
|
57
|
+
- Testing Strategy
|
|
58
|
+
- The model SHOULD include diagrams or visual representations when appropriate (use Mermaid for diagrams if applicable)
|
|
59
|
+
- The model MUST ensure the design addresses all feature requirements identified during the clarification process
|
|
60
|
+
- The model SHOULD highlight design decisions and their rationales
|
|
61
|
+
- The model MAY ask the user for input on specific technical decisions during the design process
|
|
62
|
+
- After updating the design document, the model MUST ask the user "Does the design look good? If so, we can move on to the implementation plan." using the 'userInput' tool.
|
|
63
|
+
- The 'userInput' tool MUST be used with the exact string 'spec-design-review' as the reason
|
|
64
|
+
- The model MUST make modifications to the design document if the user requests changes or does not explicitly approve
|
|
65
|
+
- The model MUST ask for explicit approval after every iteration of edits to the design document
|
|
66
|
+
- The model MUST NOT proceed to the implementation plan until receiving clear approval (such as "yes", "approved", "looks good", etc.)
|
|
67
|
+
- The model MUST continue the feedback-revision cycle until explicit approval is received
|
|
68
|
+
- The model MUST incorporate all user feedback into the design document before proceeding
|
|
69
|
+
- The model MUST offer to return to feature requirements clarification if gaps are identified during design
|
|
70
|
+
|
|
71
|
+
# Implementation Planning Generation
|
|
72
|
+
|
|
73
|
+
Workflow Stage: Implementation Planning
|
|
74
|
+
|
|
75
|
+
After the user approves the Design, create an actionable implementation plan with a checklist of coding tasks based on the requirements and design.
|
|
76
|
+
The tasks document should be based on the design document, so ensure it exists first.
|
|
77
|
+
|
|
78
|
+
**Constraints:**
|
|
79
|
+
|
|
80
|
+
- The model MUST create a 'specs/{feature_name}/tasks.md' file if it doesn't already exist
|
|
81
|
+
- The model MUST return to the design step if the user indicates any changes are needed to the design
|
|
82
|
+
- The model MUST return to the requirement step if the user indicates that we need additional requirements
|
|
83
|
+
- The model MUST create an implementation plan at 'specs/{feature_name}/tasks.md'
|
|
84
|
+
- The model MUST use the following specific instructions when creating the implementation plan: Convert the feature design into a series of prompts for a code-generation LLM that will implement each step in a test-driven manner. Prioritize best practices, incremental progress, and early testing, ensuring no big jumps in complexity at any stage. Make sure that each prompt builds on the previous prompts, and ends with wiring things together. There should be no hanging or orphaned code that isn't integrated into a previous step. Focus ONLY on tasks that involve writing, modifying, or testing code.
|
|
85
|
+
- The model MUST format the implementation plan as a numbered checkbox list with a maximum of two levels of hierarchy:
|
|
86
|
+
- Top-level items (like epics) should be used only when needed
|
|
87
|
+
- Sub-tasks should be numbered with decimal notation (e.g., 1.1, 1.2, 2.1)
|
|
88
|
+
- Each item must be a checkbox
|
|
89
|
+
- Simple structure is preferred
|
|
90
|
+
- The model MUST ensure each task item includes:
|
|
91
|
+
- A clear objective as the task description that involves writing, modifying, or testing code
|
|
92
|
+
- Additional information as sub-bullets under the task
|
|
93
|
+
- Specific references to requirements from the requirements document (referencing granular sub-requirements, not just user stories)
|
|
94
|
+
- The model MUST ensure that the implementation plan is a series of discrete, manageable coding steps
|
|
95
|
+
- The model MUST ensure each task references specific requirements from the requirement document
|
|
96
|
+
- The model MUST NOT include excessive implementation details that are already covered in the design document
|
|
97
|
+
- The model MUST assume that all context documents (feature requirements, design) will be available during implementation
|
|
98
|
+
- The model MUST ensure each step builds incrementally on previous steps
|
|
99
|
+
- The model SHOULD prioritize test-driven development where appropriate
|
|
100
|
+
- The model MUST ensure the plan covers all aspects of the design that can be implemented through code
|
|
101
|
+
- The model SHOULD sequence steps to validate core functionality early through code
|
|
102
|
+
- The model MUST ensure that all requirements are covered by the implementation tasks
|
|
103
|
+
- The model MUST offer to return to previous steps (requirements or design) if gaps are identified during implementation planning
|
|
104
|
+
- The model MUST ONLY include tasks that can be performed by a coding agent (writing code, creating tests, etc.)
|
|
105
|
+
- The model MUST NOT include tasks related to user testing, deployment, performance metrics gathering, or other non-coding activities
|
|
106
|
+
- The model MUST focus on code implementation tasks that can be executed within the development environment
|
|
107
|
+
- The model MUST ensure each task is actionable by a coding agent by following these guidelines:
|
|
108
|
+
- Tasks should involve writing, modifying, or testing specific code components
|
|
109
|
+
- Tasks should specify what files or components need to be created or modified
|
|
110
|
+
- Tasks should be concrete enough that a coding agent can execute them without additional clarification
|
|
111
|
+
- Tasks should focus on implementation details rather than high-level concepts
|
|
112
|
+
- Tasks should be scoped to specific coding activities (e.g., "Implement X function" rather than "Support X feature")
|
|
113
|
+
- The model MUST explicitly avoid including the following types of non-coding tasks in the implementation plan:
|
|
114
|
+
- User acceptance testing or user feedback gathering
|
|
115
|
+
- Deployment to production or staging environments
|
|
116
|
+
- Performance metrics gathering or analysis
|
|
117
|
+
- Running the application to test end to end flows. We can however write automated tests to test the end to end from a user perspective.
|
|
118
|
+
- User training or documentation creation
|
|
119
|
+
- Business process changes or organizational changes
|
|
120
|
+
- Marketing or communication activities
|
|
121
|
+
- Any task that cannot be completed through writing, modifying, or testing code
|
|
122
|
+
- After updating the tasks document, the model MUST ask the user "Do the tasks look good?" using the 'userInput' tool.
|
|
123
|
+
- The 'userInput' tool MUST be used with the exact string 'spec-tasks-review' as the reason
|
|
124
|
+
- The model MUST make modifications to the tasks document if the user requests changes or does not explicitly approve.
|
|
125
|
+
- The model MUST ask for explicit approval after every iteration of edits to the tasks document.
|
|
126
|
+
- The model MUST NOT consider the workflow complete until receiving clear approval (such as "yes", "approved", "looks good", etc.).
|
|
127
|
+
- The model MUST continue the feedback-revision cycle until explicit approval is received.
|
|
128
|
+
- The model MUST stop once the task document has been approved.
|
|
129
|
+
|
|
130
|
+
**This workflow is ONLY for creating design and planning artifacts. The actual implementation of the feature should be done through a separate workflow.**
|
|
131
|
+
|
|
132
|
+
- The model MUST NOT attempt to implement the feature as part of this workflow
|
|
133
|
+
- The model MUST clearly communicate to the user that this workflow is complete once the design and planning artifacts are created
|
|
134
|
+
- The model MUST inform the user that they can begin executing tasks by opening the tasks.md file, and clicking "Start task" next to task items.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"mcp__filesystem__create_directory",
|
|
5
|
+
"Bash(rm:*)",
|
|
6
|
+
"Bash(touch:*)",
|
|
7
|
+
"Bash(grep:*)",
|
|
8
|
+
"Bash(ls:*)",
|
|
9
|
+
"Bash(source:*)",
|
|
10
|
+
"Bash(find:*)",
|
|
11
|
+
"Bash(mv:*)",
|
|
12
|
+
"Bash(mkdir:*)",
|
|
13
|
+
"Bash(tree:*)",
|
|
14
|
+
"Bash(ruff:*)",
|
|
15
|
+
"Bash(touch:*)",
|
|
16
|
+
"Bash(cat:*)",
|
|
17
|
+
"Bash(ruff check:*)",
|
|
18
|
+
"Bash(pytest:*)",
|
|
19
|
+
"Bash(python:*)",
|
|
20
|
+
"Bash(python -m pytest:*)",
|
|
21
|
+
"Bash(python3 -m pytest:*)",
|
|
22
|
+
"WebFetch(domain:docs.anthropic.com)",
|
|
23
|
+
"Bash(uv pip install:*)",
|
|
24
|
+
"Bash(python:*)",
|
|
25
|
+
"Bash(uv run:*)",
|
|
26
|
+
"Bash(ls:*)",
|
|
27
|
+
"Bash(source:*)",
|
|
28
|
+
"Bash(echo:*)",
|
|
29
|
+
"mcp__sequential-thinking__sequentialthinking",
|
|
30
|
+
"Bash(pyenv:*)",
|
|
31
|
+
"Bash(~/.pyenv/versions/3.11.13/bin/python:*)",
|
|
32
|
+
"Bash(~/Library/Python/3.9/bin/cs list)",
|
|
33
|
+
"Bash(cs list:*)",
|
|
34
|
+
"Bash(~/.pyenv/versions/3.11.13/bin/cs list:*)",
|
|
35
|
+
"Bash(~/.pyenv/versions/3.11.13/bin/cs:*)",
|
|
36
|
+
"mcp__ide__executeCode",
|
|
37
|
+
"mcp__filesystem__list_directory",
|
|
38
|
+
"mcp__filesystem__read_file",
|
|
39
|
+
"mcp__filesystem__directory_tree",
|
|
40
|
+
"mcp__filesystem__write_file",
|
|
41
|
+
"mcp__context7__resolve-library-id",
|
|
42
|
+
"mcp__context7__get-library-docs",
|
|
43
|
+
"mcp__search__brave_web_search",
|
|
44
|
+
"mcp__perplexity-ask__perplexity_ask",
|
|
45
|
+
"Bash(pip install:*)",
|
|
46
|
+
"Bash(cs:*)"
|
|
47
|
+
],
|
|
48
|
+
"deny": []
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Claude Switch is a Python CLI tool for managing multiple Anthropic Claude API configurations. It allows users to easily switch between different environments (development, testing, production) with support for both auth_token and api_key authentication methods.
|
|
8
|
+
|
|
9
|
+
## Core Architecture
|
|
10
|
+
|
|
11
|
+
### Main Components
|
|
12
|
+
|
|
13
|
+
- **CLI Interface** (`claude_switch/cli.py`): Click-based command line interface with interactive features using questionary
|
|
14
|
+
- **Configuration Manager** (`claude_switch/config.py`): Handles JSON config file management, credential storage, and shell integration
|
|
15
|
+
- **Core Logic** (`claude_switch/core.py`): Business logic for configuration operations and environment management
|
|
16
|
+
|
|
17
|
+
### Key Features
|
|
18
|
+
|
|
19
|
+
- Multi-configuration management with secure credential storage
|
|
20
|
+
- Interactive configuration selection with arrow key navigation
|
|
21
|
+
- Shell integration for automatic environment variable loading
|
|
22
|
+
- Support for both API keys and auth tokens with custom naming
|
|
23
|
+
- Cross-shell compatibility (bash, zsh, fish)
|
|
24
|
+
|
|
25
|
+
## Development Commands
|
|
26
|
+
|
|
27
|
+
### Installation and Setup
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install in development mode using uv (recommended)
|
|
31
|
+
uv pip install -e .
|
|
32
|
+
|
|
33
|
+
# Or using pip
|
|
34
|
+
pip install -e .
|
|
35
|
+
|
|
36
|
+
# Activate virtual environment if using .venv
|
|
37
|
+
source .venv/bin/activate
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Testing Commands
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Run the CLI tool directly
|
|
44
|
+
python -m claude_switch.cli
|
|
45
|
+
|
|
46
|
+
# Test installed commands
|
|
47
|
+
cs --help
|
|
48
|
+
claude-switch --help
|
|
49
|
+
|
|
50
|
+
# Verify installation
|
|
51
|
+
cs --version
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Package Management
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Build package for distribution
|
|
58
|
+
python -m build
|
|
59
|
+
|
|
60
|
+
# Install from local build
|
|
61
|
+
pip install dist/claude_switch-1.0.0-py3-none-any.whl
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Configuration Structure
|
|
65
|
+
|
|
66
|
+
The tool uses `~/.claude-switch/config.json` for configuration storage with this structure:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"version": "2.0",
|
|
71
|
+
"active": "config_name",
|
|
72
|
+
"configs": {
|
|
73
|
+
"config_name": {
|
|
74
|
+
"base_url": "https://api.anthropic.com",
|
|
75
|
+
"api_keys": ["key1", "key2|custom_name"],
|
|
76
|
+
"auth_tokens": ["token1", "token2|custom_name"],
|
|
77
|
+
"note": "Description",
|
|
78
|
+
"active_key": 0,
|
|
79
|
+
"active_auth": -1
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Key Implementation Details
|
|
86
|
+
|
|
87
|
+
### Interactive Features
|
|
88
|
+
|
|
89
|
+
- Uses `questionary` for arrow key navigation in configuration selection
|
|
90
|
+
- Supports ESC key cancellation with confirmation prompts
|
|
91
|
+
- Visual indicators (✅) for active configurations and credentials
|
|
92
|
+
|
|
93
|
+
### Shell Integration
|
|
94
|
+
|
|
95
|
+
- Generates dynamic shell wrapper scripts in `~/.claude-switch/`
|
|
96
|
+
- Creates `cs-wrapper.sh` for command aliases and environment loading
|
|
97
|
+
- Automatic environment variable export via `env.sh`
|
|
98
|
+
|
|
99
|
+
### Credential Management
|
|
100
|
+
|
|
101
|
+
- Supports credential naming with pipe separator (`credential|name`)
|
|
102
|
+
- Automatic credential masking for display (`key[:4]...key[-4:]`)
|
|
103
|
+
- Per-configuration active credential tracking
|
|
104
|
+
|
|
105
|
+
### Error Handling
|
|
106
|
+
|
|
107
|
+
- Graceful handling of missing configurations
|
|
108
|
+
- JSON repair for corrupted config files
|
|
109
|
+
- File permission management (0o600 for config files)
|
|
110
|
+
|
|
111
|
+
## Development Notes
|
|
112
|
+
|
|
113
|
+
### Dependencies
|
|
114
|
+
|
|
115
|
+
- `click>=8.0.0`: CLI framework
|
|
116
|
+
- `questionary>=2.0.0`: Interactive prompts with arrow key support
|
|
117
|
+
- `json-repair>=0.30.0`: Robust JSON parsing and repair
|
|
118
|
+
|
|
119
|
+
### Code Style
|
|
120
|
+
|
|
121
|
+
- Use existing patterns for configuration management
|
|
122
|
+
- Follow Click conventions for command definitions
|
|
123
|
+
- Maintain backward compatibility for config file format
|
|
124
|
+
- Use type hints where appropriate
|
|
125
|
+
|
|
126
|
+
### Shell Integration Testing
|
|
127
|
+
|
|
128
|
+
When testing shell integration:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Test shell wrapper generation
|
|
132
|
+
cs init
|
|
133
|
+
|
|
134
|
+
# Verify generated files
|
|
135
|
+
ls -la ~/.claude-switch/
|
|
136
|
+
|
|
137
|
+
# Test environment loading
|
|
138
|
+
source ~/.claude-switch/cs-wrapper.sh
|
|
139
|
+
cs current --export
|
|
140
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Claude Switch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: claude-switch
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Anthropic Claude API 配置管理工具,支持多环境切换
|
|
5
|
+
Project-URL: Homepage, https://github.com/your-username/claude-switch
|
|
6
|
+
Project-URL: Repository, https://github.com/your-username/claude-switch
|
|
7
|
+
Project-URL: Documentation, https://github.com/your-username/claude-switch#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/your-username/claude-switch/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/your-username/claude-switch/releases
|
|
10
|
+
Author-email: Claude <noreply@anthropic.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: anthropic,api,claude,cli,config,environment,switch
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Topic :: System :: Systems Administration
|
|
29
|
+
Classifier: Topic :: Utilities
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Requires-Dist: click>=8.0.0
|
|
32
|
+
Requires-Dist: json-repair>=0.30.0
|
|
33
|
+
Requires-Dist: questionary>=2.0.0
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Claude Switch
|
|
37
|
+
|
|
38
|
+
A Python CLI tool for managing multiple Anthropic Claude API configurations with seamless environment switching.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- **Multi-configuration management**: Handle multiple Anthropic API configurations
|
|
43
|
+
- **One-click switching**: Switch between development, testing, and production environments
|
|
44
|
+
- **Dual authentication**: Support for both `auth_token` and `api_key` authentication methods
|
|
45
|
+
- **Automatic environment activation**: Environment variables automatically生效 after configuration switch
|
|
46
|
+
- **Secure storage**: Configuration file permission protection with encrypted credential storage
|
|
47
|
+
- **Interactive navigation**: Arrow key navigation with color highlighting
|
|
48
|
+
- **Backup mechanism**: Automatic configuration file backup to prevent data loss
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### pip Installation (Recommended)
|
|
53
|
+
```bash
|
|
54
|
+
pip install claude-switch
|
|
55
|
+
|
|
56
|
+
# Or using pipx (recommended to avoid dependency conflicts)
|
|
57
|
+
pipx install claude-switch
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### From Source
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/your-username/claude-switch.git
|
|
63
|
+
cd claude-switch
|
|
64
|
+
|
|
65
|
+
# Using uv (recommended)
|
|
66
|
+
uv pip install -e .
|
|
67
|
+
|
|
68
|
+
# Or using pip
|
|
69
|
+
pip install -e .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Getting Started
|
|
73
|
+
|
|
74
|
+
### Initialization
|
|
75
|
+
After installation, initialize shell integration:
|
|
76
|
+
```bash
|
|
77
|
+
cs init
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Initialization will:
|
|
81
|
+
- Automatically detect your shell environment (bash/zsh/fish)
|
|
82
|
+
- Generate dynamic shell configuration files
|
|
83
|
+
- Add configuration to your shell profile
|
|
84
|
+
- Optionally add the first configuration
|
|
85
|
+
|
|
86
|
+
Restart your terminal or run:
|
|
87
|
+
```bash
|
|
88
|
+
source ~/.claude-switch/cs-wrapper.sh
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Verification
|
|
92
|
+
```bash
|
|
93
|
+
# Check version
|
|
94
|
+
cs --version
|
|
95
|
+
|
|
96
|
+
# View help
|
|
97
|
+
cs --help
|
|
98
|
+
|
|
99
|
+
# Add first configuration
|
|
100
|
+
cs add
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Commands
|
|
104
|
+
|
|
105
|
+
### Interactive Operations
|
|
106
|
+
- `cs` - Interactive configuration selection (arrow key navigation)
|
|
107
|
+
- `cs add` - Interactive new configuration addition
|
|
108
|
+
|
|
109
|
+
### Management Commands
|
|
110
|
+
- `cs list` - List all configurations
|
|
111
|
+
- `cs use <name>` - Switch to specified configuration
|
|
112
|
+
- `cs current` - Display current configuration
|
|
113
|
+
- `cs edit <name>` - Edit configuration information
|
|
114
|
+
- `cs remove <name>` - Remove configuration
|
|
115
|
+
- `cs add-credential <config>` - Add credentials to specified configuration
|
|
116
|
+
|
|
117
|
+
### Environment Export
|
|
118
|
+
- `cs current --export` - Output executable export commands
|
|
119
|
+
|
|
120
|
+
## Usage Examples
|
|
121
|
+
|
|
122
|
+
### Adding a Configuration
|
|
123
|
+
```bash
|
|
124
|
+
# Interactive configuration addition
|
|
125
|
+
cs add
|
|
126
|
+
# Enter configuration name, Base URL, and description
|
|
127
|
+
|
|
128
|
+
# Add credentials to configuration
|
|
129
|
+
cs add-credential work
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Viewing and Managing Configurations
|
|
133
|
+
```bash
|
|
134
|
+
# View all configurations
|
|
135
|
+
cs list
|
|
136
|
+
# Output:
|
|
137
|
+
# → work - 工作账号 [https://api.anthropic.com] (0tokens, 1keys) [key1]
|
|
138
|
+
# personal - 个人账号 [https://api.anthropic.com] (1tokens, 0keys) [token1]
|
|
139
|
+
|
|
140
|
+
# Interactive selection
|
|
141
|
+
cs
|
|
142
|
+
# Use arrow keys to select, press Enter to confirm
|
|
143
|
+
|
|
144
|
+
# Quick switch
|
|
145
|
+
cs use work
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Configuration Management
|
|
149
|
+
```bash
|
|
150
|
+
# Edit configuration information
|
|
151
|
+
cs edit work
|
|
152
|
+
|
|
153
|
+
# View current configuration
|
|
154
|
+
cs current
|
|
155
|
+
# Output: 当前配置: work - 工作账号 [https://api.anthropic.com] (0tokens, 1keys) [key1]
|
|
156
|
+
|
|
157
|
+
# Export environment variables
|
|
158
|
+
cs current --export
|
|
159
|
+
# Output: export ANTHROPIC_BASE_URL="..."; export ANTHROPIC_API_KEY="..."
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Configuration Structure
|
|
163
|
+
|
|
164
|
+
Configuration is stored in `~/.claude-switch/config.json`:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"version": "2.0",
|
|
169
|
+
"active": "work",
|
|
170
|
+
"configs": {
|
|
171
|
+
"work": {
|
|
172
|
+
"base_url": "https://api.anthropic.com",
|
|
173
|
+
"api_keys": ["sk-xxx"],
|
|
174
|
+
"auth_tokens": [],
|
|
175
|
+
"note": "工作账号",
|
|
176
|
+
"active_key": 0,
|
|
177
|
+
"active_auth": -1
|
|
178
|
+
},
|
|
179
|
+
"personal": {
|
|
180
|
+
"base_url": "https://api.anthropic.com",
|
|
181
|
+
"api_keys": [],
|
|
182
|
+
"auth_tokens": ["sk-yyy"],
|
|
183
|
+
"note": "个人账号",
|
|
184
|
+
"active_key": -1,
|
|
185
|
+
"active_auth": 0
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Interactive Interface Features
|
|
192
|
+
|
|
193
|
+
- **Cursor highlighting**: Current selection line highlighted in green
|
|
194
|
+
- **Status indicators**: Green arrow (→) indicates active configuration
|
|
195
|
+
- **Rich information**: Shows configuration name, description, URL, credential count and type
|
|
196
|
+
- **Arrow navigation**: Supports up/down arrow key selection with Enter confirmation
|
|
197
|
+
|
|
198
|
+
## Security Features
|
|
199
|
+
|
|
200
|
+
- **File permissions**: Configuration file automatically set to 0o600 (user-readable only)
|
|
201
|
+
- **Sensitive information masking**: Automatic credential masking during display
|
|
202
|
+
- **Automatic backup**: Automatic backup creation when configuration file is corrupted
|
|
203
|
+
- **Version compatibility**: Automatic configuration version upgrade handling
|
|
204
|
+
|
|
205
|
+
## Advanced Usage
|
|
206
|
+
|
|
207
|
+
### Manual Configuration Editing
|
|
208
|
+
You can directly edit the configuration file `~/.claude-switch/config.json`. The system automatically handles format errors and creates backups.
|
|
209
|
+
|
|
210
|
+
### Environment Variable Settings
|
|
211
|
+
```bash
|
|
212
|
+
# Automatic activation (requires initialization)
|
|
213
|
+
cs use production
|
|
214
|
+
|
|
215
|
+
# Manual activation
|
|
216
|
+
eval $(cs current --export)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Shell Integration
|
|
220
|
+
After initialization, the following aliases are automatically available:
|
|
221
|
+
- `cs` - Main command
|
|
222
|
+
- `csu` - Quick configuration switching
|
|
223
|
+
- `csc` - View current configuration
|
|
224
|
+
- `css` - Manual environment variable reload
|
|
225
|
+
|
|
226
|
+
## Troubleshooting
|
|
227
|
+
|
|
228
|
+
### Installation Issues
|
|
229
|
+
|
|
230
|
+
**Problem: cs command not found**
|
|
231
|
+
```bash
|
|
232
|
+
# Check if installed correctly
|
|
233
|
+
pip list | grep claude-switch
|
|
234
|
+
|
|
235
|
+
# Check PATH settings
|
|
236
|
+
echo $PATH
|
|
237
|
+
|
|
238
|
+
# Reinstall
|
|
239
|
+
pip install --force-reinstall claude-switch
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Problem: Permission errors**
|
|
243
|
+
```bash
|
|
244
|
+
# Use user installation
|
|
245
|
+
pip install --user claude-switch
|
|
246
|
+
|
|
247
|
+
# Or use pipx
|
|
248
|
+
pipx install claude-switch
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Initialization Issues
|
|
252
|
+
|
|
253
|
+
**Problem: Shell integration not working**
|
|
254
|
+
```bash
|
|
255
|
+
# Manually source configuration file
|
|
256
|
+
source ~/.claude-switch/cs-wrapper.sh
|
|
257
|
+
|
|
258
|
+
# Check if configuration files exist
|
|
259
|
+
ls -la ~/.claude-switch/
|
|
260
|
+
|
|
261
|
+
# Reinitialize
|
|
262
|
+
cs init
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Problem: Environment variables not taking effect**
|
|
266
|
+
```bash
|
|
267
|
+
# Manually load environment variables
|
|
268
|
+
source ~/.claude-switch/env.sh
|
|
269
|
+
|
|
270
|
+
# Or use export command
|
|
271
|
+
eval $(cs current --export)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Compatibility
|
|
275
|
+
|
|
276
|
+
- **Supported Python versions**: 3.8+
|
|
277
|
+
- **Supported operating systems**: macOS, Linux, Windows
|
|
278
|
+
- **Supported shells**: bash, zsh, fish
|
|
279
|
+
- **Supported installation methods**: pip, pipx, conda, uv
|
|
280
|
+
|
|
281
|
+
## Getting Help
|
|
282
|
+
|
|
283
|
+
If you encounter issues:
|
|
284
|
+
1. View `cs --help` for command assistance
|
|
285
|
+
2. Check configuration files in `~/.claude-switch/` directory
|
|
286
|
+
3. Submit an Issue on GitHub: https://github.com/your-username/claude-switch/issues
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT License
|