claude-switch


Nameclaude-switch JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryAnthropic Claude API 配置管理工具,支持多环境切换
upload_time2025-07-31 06:13:52
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords anthropic api claude cli config environment switch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Claude Switch

A Python CLI tool for managing multiple Anthropic Claude API configurations with seamless environment switching.

## Features

- **Multi-configuration management**: Handle multiple Anthropic API configurations
- **One-click switching**: Switch between development, testing, and production environments
- **Dual authentication**: Support for both `auth_token` and `api_key` authentication methods
- **Automatic environment activation**: Environment variables automatically生效 after configuration switch
- **Secure storage**: Configuration file permission protection with encrypted credential storage
- **Interactive navigation**: Arrow key navigation with color highlighting
- **Backup mechanism**: Automatic configuration file backup to prevent data loss

## Installation

### uv Installation (Recommended)
```bash
# Global installation with uv (recommended)
uv pip install --user claude-switch

# Or run without installation using uvx
uvx claude-switch --help
```

### pip Installation
```bash
pip install claude-switch

# Or using pipx (recommended to avoid dependency conflicts)
pipx install claude-switch
```

### From Source
```bash
git clone https://github.com/your-username/claude-switch.git
cd claude-switch

# Using uv
uv pip install -e .

# Or using pip
pip install -e .
```

## Getting Started

### Initialization
After installation, initialize shell integration:
```bash
cs init
```

Initialization will:
- Automatically detect your shell environment (bash/zsh/fish)
- Generate dynamic shell configuration files
- Add configuration to your shell profile
- Optionally add the first configuration

Restart your terminal or run:
```bash
source ~/.claude-switch/cs-wrapper.sh
```

### Verification
```bash
# Check version
cs --version

# View help
cs --help

# Add first configuration
cs add
```

## Commands

### Interactive Operations
- `cs` - Interactive configuration selection (arrow key navigation)
- `cs add` - Interactive new configuration addition

### Management Commands
- `cs list` - List all configurations
- `cs use <name>` - Switch to specified configuration
- `cs current` - Display current configuration
- `cs edit <name>` - Edit configuration information
- `cs remove <name>` - Remove configuration
- `cs add-credential <config>` - Add credentials to specified configuration

### Environment Export
- `cs current --export` - Output executable export commands

## Usage Examples

### Adding a Configuration
```bash
# Interactive configuration addition
cs add
# Enter configuration name, Base URL, and description

# Add credentials to configuration
cs add-credential work
```

### Viewing and Managing Configurations
```bash
# View all configurations
cs list
# Output:
# → work - 工作账号 [https://api.anthropic.com] (0tokens, 1keys) [key1]
#   personal - 个人账号 [https://api.anthropic.com] (1tokens, 0keys) [token1]

# Interactive selection
cs
# Use arrow keys to select, press Enter to confirm

# Quick switch
cs use work
```

### Configuration Management
```bash
# Edit configuration information
cs edit work

# View current configuration
cs current
# Output: 当前配置: work - 工作账号 [https://api.anthropic.com] (0tokens, 1keys) [key1]

# Export environment variables
cs current --export
# Output: export ANTHROPIC_BASE_URL="..."; export ANTHROPIC_API_KEY="..."
```

## Configuration Structure

Configuration is stored in `~/.claude-switch/config.json`:

```json
{
  "version": "2.0",
  "active": "work",
  "configs": {
    "work": {
      "base_url": "https://api.anthropic.com",
      "api_keys": ["sk-xxx"],
      "auth_tokens": [],
      "note": "工作账号",
      "active_key": 0,
      "active_auth": -1
    },
    "personal": {
      "base_url": "https://api.anthropic.com",
      "api_keys": [],
      "auth_tokens": ["sk-yyy"],
      "note": "个人账号",
      "active_key": -1,
      "active_auth": 0
    }
  }
}
```

## Interactive Interface Features

- **Cursor highlighting**: Current selection line highlighted in green
- **Status indicators**: Green arrow (→) indicates active configuration
- **Rich information**: Shows configuration name, description, URL, credential count and type
- **Arrow navigation**: Supports up/down arrow key selection with Enter confirmation

## Security Features

- **File permissions**: Configuration file automatically set to 0o600 (user-readable only)
- **Sensitive information masking**: Automatic credential masking during display
- **Automatic backup**: Automatic backup creation when configuration file is corrupted
- **Version compatibility**: Automatic configuration version upgrade handling

## Advanced Usage

### Manual Configuration Editing
You can directly edit the configuration file `~/.claude-switch/config.json`. The system automatically handles format errors and creates backups.

### Environment Variable Settings
```bash
# Automatic activation (requires initialization)
cs use production

# Manual activation
eval $(cs current --export)
```

### Shell Integration
After initialization, the following aliases are automatically available:
- `cs` - Main command
- `csu` - Quick configuration switching
- `csc` - View current configuration
- `css` - Manual environment variable reload

## Troubleshooting

### Installation Issues

**Problem: cs command not found**
```bash
# Check if installed correctly
pip list | grep claude-switch

# Check PATH settings
echo $PATH

# Reinstall
pip install --force-reinstall claude-switch
```

**Problem: Permission errors**
```bash
# Use user installation with pip
pip install --user claude-switch

# Or use uv (recommended)
uv pip install --user claude-switch

# Or use pipx
pipx install claude-switch
```

### Initialization Issues

**Problem: Shell integration not working**
```bash
# Manually source configuration file
source ~/.claude-switch/cs-wrapper.sh

# Check if configuration files exist
ls -la ~/.claude-switch/

# Reinitialize
cs init
```

**Problem: Environment variables not taking effect**
```bash
# Manually load environment variables
source ~/.claude-switch/env.sh

# Or use export command
eval $(cs current --export)
```

## Compatibility

- **Supported Python versions**: 3.8+
- **Supported operating systems**: macOS, Linux, Windows
- **Supported shells**: bash, zsh, fish
- **Supported installation methods**: pip, pipx, conda, uv

## Getting Help

If you encounter issues:
1. View `cs --help` for command assistance
2. Check configuration files in `~/.claude-switch/` directory
3. Submit an Issue on GitHub: https://github.com/your-username/claude-switch/issues

## License

MIT License
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "claude-switch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "anthropic, api, claude, cli, config, environment, switch",
    "author": null,
    "author_email": "Claude <noreply@anthropic.com>",
    "download_url": "https://files.pythonhosted.org/packages/70/5f/21e0f3e36994325dfcbfaf42e85b17e7fbd6485812089e6d5f29325c8e0c/claude_switch-1.1.0.tar.gz",
    "platform": null,
    "description": "# Claude Switch\n\nA Python CLI tool for managing multiple Anthropic Claude API configurations with seamless environment switching.\n\n## Features\n\n- **Multi-configuration management**: Handle multiple Anthropic API configurations\n- **One-click switching**: Switch between development, testing, and production environments\n- **Dual authentication**: Support for both `auth_token` and `api_key` authentication methods\n- **Automatic environment activation**: Environment variables automatically\u751f\u6548 after configuration switch\n- **Secure storage**: Configuration file permission protection with encrypted credential storage\n- **Interactive navigation**: Arrow key navigation with color highlighting\n- **Backup mechanism**: Automatic configuration file backup to prevent data loss\n\n## Installation\n\n### uv Installation (Recommended)\n```bash\n# Global installation with uv (recommended)\nuv pip install --user claude-switch\n\n# Or run without installation using uvx\nuvx claude-switch --help\n```\n\n### pip Installation\n```bash\npip install claude-switch\n\n# Or using pipx (recommended to avoid dependency conflicts)\npipx install claude-switch\n```\n\n### From Source\n```bash\ngit clone https://github.com/your-username/claude-switch.git\ncd claude-switch\n\n# Using uv\nuv pip install -e .\n\n# Or using pip\npip install -e .\n```\n\n## Getting Started\n\n### Initialization\nAfter installation, initialize shell integration:\n```bash\ncs init\n```\n\nInitialization will:\n- Automatically detect your shell environment (bash/zsh/fish)\n- Generate dynamic shell configuration files\n- Add configuration to your shell profile\n- Optionally add the first configuration\n\nRestart your terminal or run:\n```bash\nsource ~/.claude-switch/cs-wrapper.sh\n```\n\n### Verification\n```bash\n# Check version\ncs --version\n\n# View help\ncs --help\n\n# Add first configuration\ncs add\n```\n\n## Commands\n\n### Interactive Operations\n- `cs` - Interactive configuration selection (arrow key navigation)\n- `cs add` - Interactive new configuration addition\n\n### Management Commands\n- `cs list` - List all configurations\n- `cs use <name>` - Switch to specified configuration\n- `cs current` - Display current configuration\n- `cs edit <name>` - Edit configuration information\n- `cs remove <name>` - Remove configuration\n- `cs add-credential <config>` - Add credentials to specified configuration\n\n### Environment Export\n- `cs current --export` - Output executable export commands\n\n## Usage Examples\n\n### Adding a Configuration\n```bash\n# Interactive configuration addition\ncs add\n# Enter configuration name, Base URL, and description\n\n# Add credentials to configuration\ncs add-credential work\n```\n\n### Viewing and Managing Configurations\n```bash\n# View all configurations\ncs list\n# Output:\n# \u2192 work - \u5de5\u4f5c\u8d26\u53f7 [https://api.anthropic.com] (0tokens, 1keys) [key1]\n#   personal - \u4e2a\u4eba\u8d26\u53f7 [https://api.anthropic.com] (1tokens, 0keys) [token1]\n\n# Interactive selection\ncs\n# Use arrow keys to select, press Enter to confirm\n\n# Quick switch\ncs use work\n```\n\n### Configuration Management\n```bash\n# Edit configuration information\ncs edit work\n\n# View current configuration\ncs current\n# Output: \u5f53\u524d\u914d\u7f6e: work - \u5de5\u4f5c\u8d26\u53f7 [https://api.anthropic.com] (0tokens, 1keys) [key1]\n\n# Export environment variables\ncs current --export\n# Output: export ANTHROPIC_BASE_URL=\"...\"; export ANTHROPIC_API_KEY=\"...\"\n```\n\n## Configuration Structure\n\nConfiguration is stored in `~/.claude-switch/config.json`:\n\n```json\n{\n  \"version\": \"2.0\",\n  \"active\": \"work\",\n  \"configs\": {\n    \"work\": {\n      \"base_url\": \"https://api.anthropic.com\",\n      \"api_keys\": [\"sk-xxx\"],\n      \"auth_tokens\": [],\n      \"note\": \"\u5de5\u4f5c\u8d26\u53f7\",\n      \"active_key\": 0,\n      \"active_auth\": -1\n    },\n    \"personal\": {\n      \"base_url\": \"https://api.anthropic.com\",\n      \"api_keys\": [],\n      \"auth_tokens\": [\"sk-yyy\"],\n      \"note\": \"\u4e2a\u4eba\u8d26\u53f7\",\n      \"active_key\": -1,\n      \"active_auth\": 0\n    }\n  }\n}\n```\n\n## Interactive Interface Features\n\n- **Cursor highlighting**: Current selection line highlighted in green\n- **Status indicators**: Green arrow (\u2192) indicates active configuration\n- **Rich information**: Shows configuration name, description, URL, credential count and type\n- **Arrow navigation**: Supports up/down arrow key selection with Enter confirmation\n\n## Security Features\n\n- **File permissions**: Configuration file automatically set to 0o600 (user-readable only)\n- **Sensitive information masking**: Automatic credential masking during display\n- **Automatic backup**: Automatic backup creation when configuration file is corrupted\n- **Version compatibility**: Automatic configuration version upgrade handling\n\n## Advanced Usage\n\n### Manual Configuration Editing\nYou can directly edit the configuration file `~/.claude-switch/config.json`. The system automatically handles format errors and creates backups.\n\n### Environment Variable Settings\n```bash\n# Automatic activation (requires initialization)\ncs use production\n\n# Manual activation\neval $(cs current --export)\n```\n\n### Shell Integration\nAfter initialization, the following aliases are automatically available:\n- `cs` - Main command\n- `csu` - Quick configuration switching\n- `csc` - View current configuration\n- `css` - Manual environment variable reload\n\n## Troubleshooting\n\n### Installation Issues\n\n**Problem: cs command not found**\n```bash\n# Check if installed correctly\npip list | grep claude-switch\n\n# Check PATH settings\necho $PATH\n\n# Reinstall\npip install --force-reinstall claude-switch\n```\n\n**Problem: Permission errors**\n```bash\n# Use user installation with pip\npip install --user claude-switch\n\n# Or use uv (recommended)\nuv pip install --user claude-switch\n\n# Or use pipx\npipx install claude-switch\n```\n\n### Initialization Issues\n\n**Problem: Shell integration not working**\n```bash\n# Manually source configuration file\nsource ~/.claude-switch/cs-wrapper.sh\n\n# Check if configuration files exist\nls -la ~/.claude-switch/\n\n# Reinitialize\ncs init\n```\n\n**Problem: Environment variables not taking effect**\n```bash\n# Manually load environment variables\nsource ~/.claude-switch/env.sh\n\n# Or use export command\neval $(cs current --export)\n```\n\n## Compatibility\n\n- **Supported Python versions**: 3.8+\n- **Supported operating systems**: macOS, Linux, Windows\n- **Supported shells**: bash, zsh, fish\n- **Supported installation methods**: pip, pipx, conda, uv\n\n## Getting Help\n\nIf you encounter issues:\n1. View `cs --help` for command assistance\n2. Check configuration files in `~/.claude-switch/` directory\n3. Submit an Issue on GitHub: https://github.com/your-username/claude-switch/issues\n\n## License\n\nMIT License",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Anthropic Claude API \u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u652f\u6301\u591a\u73af\u5883\u5207\u6362",
    "version": "1.1.0",
    "project_urls": {
        "Changelog": "https://github.com/your-username/claude-switch/releases",
        "Documentation": "https://github.com/your-username/claude-switch#readme",
        "Homepage": "https://github.com/your-username/claude-switch",
        "Issues": "https://github.com/your-username/claude-switch/issues",
        "Repository": "https://github.com/your-username/claude-switch"
    },
    "split_keywords": [
        "anthropic",
        " api",
        " claude",
        " cli",
        " config",
        " environment",
        " switch"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "30b0d66ee52ee498a67ffc206b9c64fbb851f7de6f6c01d353fb283c0a7ce1e3",
                "md5": "b35a90a3833fbf1225a41c209fcf8abc",
                "sha256": "c3b610c13c9adc245d0f0445640b7168b658bdebcc44560802e71a461c22bdd4"
            },
            "downloads": -1,
            "filename": "claude_switch-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b35a90a3833fbf1225a41c209fcf8abc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19818,
            "upload_time": "2025-07-31T06:13:50",
            "upload_time_iso_8601": "2025-07-31T06:13:50.010970Z",
            "url": "https://files.pythonhosted.org/packages/30/b0/d66ee52ee498a67ffc206b9c64fbb851f7de6f6c01d353fb283c0a7ce1e3/claude_switch-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "705f21e0f3e36994325dfcbfaf42e85b17e7fbd6485812089e6d5f29325c8e0c",
                "md5": "ebc8eb3b99de5c77e44cc70d40e10e2b",
                "sha256": "14dc6bc9ae0644a02260200eb2d081a14588e00e5fbfd1ea9096e358b8f0c38f"
            },
            "downloads": -1,
            "filename": "claude_switch-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ebc8eb3b99de5c77e44cc70d40e10e2b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26008,
            "upload_time": "2025-07-31T06:13:52",
            "upload_time_iso_8601": "2025-07-31T06:13:52.039379Z",
            "url": "https://files.pythonhosted.org/packages/70/5f/21e0f3e36994325dfcbfaf42e85b17e7fbd6485812089e6d5f29325c8e0c/claude_switch-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 06:13:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "your-username",
    "github_project": "claude-switch",
    "github_not_found": true,
    "lcname": "claude-switch"
}
        
Elapsed time: 1.02910s