Claude Code Switch (ccm)

repository·main·Indexed 18 days ago

https://github.com/foreveryh/claude-code-switch

A CLI tool that allows developers to switch the AI provider used by Claude Code between services such as GLM, DeepSeek, Kimi, OpenRouter, Qwen, and MiniMax. It provides the `ccm` command for environment management and the `ccc` wrapper to switch providers and launch Claude Code in a single step. Features include support for multiple Claude Pro accounts, user-level and project-level configuration overrides, and regional provider options.

Tokens
5K
Snippets
23
Records
29
Agent score
69%

What's inside Claude Code Switch

  1. Apply User-Level or Project-Level Overrides

    main

    Claude Code Switch supports different levels of configuration priority.

    User-Level Settings (Highest Priority)

    These write directly to ~/.claude/settings.json and override everything else. Use this if you want a persistent default or if other tools (like Quotio) are modifying your settings.

    • ccm user <provider> <region>: e.g., ccm user glm global sets GLM as the default for all projects.
    • ccm user reset: Removes user-level settings and returns control to environment variables.

    Project-Level Overrides

    These create/remove a .claude/settings.local.json file in your current directory, affecting only the current project.

    • ccm project <provider> <region>: e.g., ccm project glm china uses GLM China for this project only.
    • ccm project reset: Removes the project-specific override.
    ccm user glm global
  2. Apply User-level settings (Highest Priority)

    main

    User-level settings write directly to ~/.claude/settings.json. These settings have the highest priority and will override environment variables and project-level settings. This is useful if you use other tools that modify this file or if you want a persistent default that survives shell restarts.

    # Set a global default provider for all projects
    ccm user glm global
    
    # Reset to use environment variables instead
    ccm user reset
  3. Apply Project-level overrides

    main

    You can set a provider that applies only to the current directory by using ccm project. This creates or modifies a .claude/settings.local.json file in your current project folder, allowing you to maintain different providers for different projects without changing your global settings.

    # In a specific project directory
    ccm project glm china
    
    # Remove project-specific override
    ccm project reset
  4. Understand Configuration Priority

    main

    When determining which provider and model to use, ccm follows this priority order (from highest to lowest):

    1. ~/.claude/settings.json (env section) — User-level settings (set via ccm user)
    2. .claude/settings.local.jsonProject-level settings (set via ccm project)
    3. ~/.ccm_config file — Global configuration (reloads on every ccm command)
    4. Environment variables — Used only if config values are placeholders.
  5. How ccm and ccc work together

    main

    Claude Code Switch provides two distinct workflows for managing model environments and launching Claude Code:

    Method 1: ccm (Environment Management)

    Use ccm when you want fine-grained control. It switches the model configuration in your current shell session without launching any applications. This is useful if you want to set the environment and then manually run other commands or launch Claude Code later.

    Method 2: ccc (One-Command Launch)

    Use ccc for convenience. It is the recommended method for most users. It performs two actions in a single step: it calls ccm to set the necessary environment variables and then immediately launches Claude Code using exec claude [options].

    Summary Table:

    CommandPurposeWorkflow
    ccmEnvironment ManagerSwitch environment $\rightarrow$ Manually launch Claude
    cccClaude Code CommanderSwitch environment $\rightarrow$ Launch Claude (One step)
  6. Configure API Keys in ~/.ccm_config

    main

    After installation, you must configure your API keys to use different providers. Run ccm config to open ~/.ccm_config in your default editor.

    Add the required environment variables for the providers you intend to use. Example keys include:

    • DEEPSEEK_API_KEY
    • KIMI_API_KEY
    • GLM_API_KEY
    • QWEN_API_KEY
    • MINIMAX_API_KEY
    • ARK_API_KEY (for Doubao/Seed)
    • OPENROUTER_API_KEY
    • CLAUDE_API_KEY (optional, for Claude API vs subscription)

    You can also override model IDs by adding keys like DEEPSEEK_MODEL, KIMI_MODEL, etc.

    ccm config
  7. Verify Claude Code Switch installation

    main

    After installation, you should verify that the core commands and model switching are functioning correctly. Use the following sequence to test the environment management and the one-command launch functionality.

    Verification Steps:

    1. Check current status: ccm status
    2. Switch models: ccm deepseek
    3. Verify status change: ccm status
    4. Test Claude Code launch: ccc deepseek (requires Claude Code to be installed)
    # 1. Test ccm
    ccm status
    ccm deepseek
    ccm status
    
    # 2. Test ccc (if Claude Code is installed)
    ccc deepseek
  8. Configure API keys for providers

    main

    To use non-Claude providers, you must configure your API keys. Run ccm config to open your configuration file (~/.ccm_config) in your default editor. Add the required keys for your chosen providers:

    Supported keys include:

    • DEEPSEEK_API_KEY
    • KIMI_API_KEY
    • GLM_API_KEY
    • QWEN_API_KEY
    • MINIMAX_API_KEY
    • ARK_API_KEY (for Doubao/Seed)
    • OPENROUTER_API_KEY
    • CLAUDE_API_KEY (optional, for Claude API non-subscription)

    After saving, you can verify your configuration with ccm status.

    ccm config
    # In the editor, add:
    # DEEPSEEK_API_KEY=sk-...
    # GLM_API_KEY=...
    
    ccm status
  9. Install Claude Code Switch (ccm)

    main

    You can install ccm using a quick install script or by cloning the repository for a local installation.

    Run the following command to install and then reload your shell configuration:

    curl -fsSL https://raw.githubusercontent.com/foreveryh/claude-code-switch/main/quick-install.sh | bash
    source ~/.zshrc  # or ~/.bashrc

    Local Install

    Clone the repository and run the install script manually:

    git clone https://github.com/foreveryh/claude-code-switch.git
    cd claude-code-switch
    ./install.sh
    source ~/.zshrc

    Installation Modes

    • User (default): ./install.sh - Available everywhere for personal use.
    • System: ./install.sh --system - For shared machines, available to all users.
    • Project: ./install.sh --project - Isolated, project-specific setup.
    curl -fsSL https://raw.githubusercontent.com/foreveryh/claude-code-switch/main/quick-install.sh | bash
  10. Fix Environment Variables not taking effect

    main

    Claude Code inherits environment variables from the shell at the moment it is started. If you switch models using ccm after Claude Code is already running, the changes will not apply.

    Use the ccc command to switch the model and launch Claude Code in a single step. This ensures the environment is correctly configured before the process starts:

    ccc <model_name>

    Alternative Two-Step Approach

    If you prefer not to use ccc, you must switch the environment first, then launch the CLI manually:

    1. Switch the environment: ccm <model_name>
    2. Launch Claude Code: claude
    ccc deepseek
  11. Switch AI providers and launch Claude Code

    main

    Use ccm to switch the provider for your current shell session, or use ccc to switch the provider and immediately launch Claude Code.

    # Switch provider in current shell
    ccm glm global
    ccm deepseek
    ccm kimi china
    
    # Switch provider AND launch Claude Code
    ccc glm global
    ccc deepseek
    ccc open glm