npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

claude-code-provider-switch

v1.4.0

Published

Cross-platform Claude Code provider switcher (OpenRouter, Ollama, Anthropic)

Downloads

2,717

Readme

Claude Code Provider Switcher

A powerful CLI tool that lets you seamlessly switch between different AI providers for Claude Code, including OpenRouter, Anthropic, MiniMax, Ollama, and the original Claude Code configuration.

🚀 Features

  • Multi-Provider Support: Switch between OpenRouter, Anthropic, MiniMax, Ollama, and original Claude Code
  • Enhanced Interactive Menu: Beautiful, intuitive interface with visual hierarchy and icons
  • Centralized Configuration: Secure, centralized base URL management for all providers
  • Security-First: Explicit base URL configuration prevents URL hijacking attacks
  • Default Configuration: Set and save your preferred provider and model
  • Model Selection: Choose from hundreds of models across different providers
  • Auto-Restart: Automatically restarts with new configuration after changes
  • Cross-Platform: Works on Windows, macOS, and Linux
  • Global Installation: Install once and use anywhere

📦 Installation

Prerequisites

First, ensure you have Claude Code installed.

npm install -g @anthropic-ai/claude-code

Global Installation (Method 1)

# Install globally
npm install -g claude-code-provider-switch

Global Installation (Method 2 - Alternative)

# Clone the repository
git clone <repository-url>
cd claude-code-provider-switch

# Install globally
npm install -g .

# Or use npm link for development (changes are immediate)
npm run link

🎯 Quick Start

Basic Usage

# Show interactive menu with enhanced visual interface
claude-switch ui

# Use a specific provider
claude-switch openrouter
claude-switch anthropic
claude-switch minimax
claude-switch ollama
claude-switch original

# Use specific provider with model selection
claude-switch openrouter --model
claude-switch minimax --model

Enhanced Menu Interface

When you run claude-switch ui, you'll see a beautifully formatted interactive menu:

Claude Code Provider Switcher

Configuration: Global (~/.claude/.claude-switch-env)

Current default: OpenRouter ⭐ [DEFAULT] (openrouter/free)

Available providers:

❯ 1) OpenRouter ⭐ [DEFAULT] ── (openrouter, or, open)
  2) Ollama ── (ollama, oll)
  3) Minimax ── (minimax, min, mm)
  4) Anthropic ── (anthropic, ant)
  5) Original Claude Code ── (original, orig, def, d)
──────────────────────────────────────────────────────────
  6) ⚙️ Set as Default
  7) 🔑 Manage API Keys
  8) ❓ Help

🎯 Navigation:
  • Use ↑/↓ arrows to navigate options
  • Press Enter to select highlighted option
  • Press 1-8 for quick select
  • Press ESC to exit

⭐ Tips:
  • ⭐ indicates your current default provider
  • 🌐 Providers: Launch AI models with different services
  • 🔸 Management: Configure settings and preferences

Configuration Management

# Set up default provider and model interactively
claude-switch set-default

# View current defaults
claude-switch show-defaults

# Clear all defaults
claude-switch clear-defaults

# Manage API keys interactively
claude-switch api-keys

⚙️ Configuration

Security & Centralization

The CLI now features centralized base URL management for enhanced security:

  • 🔒 Secure: All providers use explicitly configured base URLs from constants.js
  • 🛡️ Anti-Hijacking: Prevents URL hijacking through malicious environment variables
  • 📍 Centralized: Single source of truth for all provider configurations
  • ✅ Consistent: Uniform behavior across all providers

Environment Variables

The CLI is designed to create a ~/.claude/.claude-switch-env (in your home directory) with this syntax:

# API Keys for different providers
OPENROUTER_AUTH_TOKEN=your_openrouter_token_here
ANTHROPIC_API_KEY=your_anthropic_key_here
MINIMAX_AUTH_TOKEN=your_minimax_token_here
OLLAMA_AUTH_TOKEN=your_ollama_token_here

# Optional: Default models for each provider
OPENROUTER_MODEL=openrouter/free
OLLAMA_MODEL=minimax-m2.5:cloud
ANTHROPIC_MODEL=claude-3-5-sonnet-latest
MINIMAX_MODEL=minimax-m2.7

# Default provider and model settings
DEFAULT_PROVIDER=default  # Use 'default' to show menu on startup, or set to 'openrouter', 'anthropic', 'minimax', 'ollama', or 'original'
DEFAULT_MODEL=

When you run the CLI for the first time, based on your selection, it will ask for the API keys or Auth Tokens and after this will be saved in the .env file for future use.

Global vs Local Configuration

The CLI supports two configuration modes:

Global Configuration (Default)

  • Location: ~/.claude/.claude-switch-env (in your home directory)
  • Priority: Used when no local .env file exists
  • Benefit: Share configuration across all projects
  • Creation: Automatically created on first run when no local .env exists

Local Configuration

  • Location: .env file in your project directory
  • Priority: Overrides global configuration when present
  • Benefit: Project-specific settings
  • Creation: Create manually or use "Save Configuration Locally" menu option

Configuration Display

The main menu shows which configuration source is active:

Configuration: Global (~/.claude/.claude-switch-en)
Configuration: Local (current_folder/.env)

Menu Behavior

  • No defaults set: Shows interactive menu for provider selection
  • Defaults set: Auto-launches with configured provider
  • Fresh install: Always shows menu until you set defaults

Switching Between Modes

  • To Local: Use "Save Configuration Locally" option from main menu
  • To Global: Delete local .env file to fall back to global config
  • Priority: Local always takes precedence over global when both exist

API Key Management

For easier API key management, use the interactive menu:

# Launch interactive API key management
claude-switch api-keys

Or access it through the main menu (option 6) when you run claude-switch without arguments.

Features:

  • 🔐 Secure: API keys are masked for display (shows only first 4 and last 4 characters)
  • 🎯 Visual: Clear status indicators (✅/❌) show which providers have keys configured
  • Interactive: Arrow key navigation with visual selection indicators and icons
  • 🔄 Flexible: Update, remove, or set new API keys interactively
  • 🎨 Enhanced UI: Beautiful menu with visual hierarchy and intuitive navigation

Provider Setup

OpenRouter

  1. Get your API key from OpenRouter
  2. Run claude-switch ui to set the API key interactively
  3. Select OpenRouter from the menu to browse and choose available models

Anthropic

  1. Get your API key from Anthropic Console
  2. Run claude-switch ui to set the API key interactively
  3. Select Anthropic from the menu to browse and choose available models

MiniMax

  1. Get your API key from MiniMax Console
  2. Run claude-switch ui to set the API key interactively
  3. Select MiniMax from the menu to browse and choose available minimal models

Ollama

  1. Install and run Ollama
  2. Run claude-switch ui to set the API key interactively (optional, for remote instances)
  3. Select Ollama from the menu to see locally available models

📋 Commands Reference

Provider Commands

| Command | Description | Example | | ------------ | ------------------------ | -------------------------- | | openrouter | Use OpenRouter provider | claude-switch openrouter | | anthropic | Use Anthropic provider | claude-switch anthropic | | minimax | Use MiniMax provider | claude-switch minimax | | ollama | Use Ollama provider | claude-switch ollama | | original | Use original Claude Code | claude-switch original |

Model Selection

| Command | Description | Example | | -------------------- | ------------------------- | ---------------------------------- | | <provider> --model | Select model for provider | claude-switch openrouter --model | | minimax --model | Select MiniMax model | claude-switch minimax --model |

Configuration Commands

| Command | Description | Example | | ---------------- | ----------------------------- | ------------------------------ | | set-default | Interactive default setup | claude-switch set-default | | show-defaults | View current defaults | claude-switch show-defaults | | clear-defaults | Reset all defaults | claude-switch clear-defaults | | api-keys | Manage API keys interactively | claude-switch api-keys | | help | Show help information | claude-switch --help | | version | Show Version information | claude-switch --version |

Aliases

| Command | Aliases | | ------------ | ------------------------------ | | openrouter | or, open | | anthropic | ant | | minimax | min, mm | | ollama | oll | | original | original, orig, def, d |

⚠️ IMPORTANT: Extra Arguments with Default Provider

When a default provider is set, extra arguments are automatically passed to Claude Code:

claude-switch --continue           # Continue previous conversation
claude-switch --resume            # Resume last session
claude-switch -p "Explain what this project does"  # Quick prompt without interactive mode
claude-switch -p "List all providers supported" --output-format json  # Get structured JSON output

This means you can use Claude Code with your default provider seamlessly after setting a default provider, also passing extra arguments like --continue, --resume, etc.

⚠️ Important: Clearing Defaults

If the interactive menu doesn't show and Claude Code opens directly with a predefined provider, you need to clear the default settings:

claude-switch clear-defaults

Why This Happens

When you use the "Set as Default" option, the application saves your provider and model choices to provide a faster experience. However, if you want to change providers or access the full menu again, you must clear these defaults first with claude-switch clear-defaults

🎨 Enhanced Menu Features

The interactive menu includes several visual enhancements:

Visual Elements

  • Icons: Management options have intuitive icons (⚙️ Settings, 🔑 Keys, ❓ Help, etc.)
  • Color Coding: Different colors for different option types
  • Star Indicator: ⭐ shows your current default provider
  • Separator Line: Clean visual separation between providers and management options
  • Inline Aliases: Provider aliases displayed on the same line for cleaner layout

Navigation Improvements

  • Arrow Keys: Smooth up/down navigation with visual feedback
  • Quick Select: Press number keys for instant selection
  • ESC Support: Exit the menu cleanly
  • Visual Selection: Clear indicator (❯) shows currently selected option

🔧 Advanced Usage

Programmatic API

You can also use this package as a module in your Node.js applications:

const {
  setDefaultProvider,
  getDefaultProvider,
  launchOpenRouter,
  launchAnthropic,
  showApiKeyMenu,
  updateApiKey,
  maskApiKey,
} = require("claude-code-provider-switch");

// Set default provider programmatically
await setDefaultProvider("openrouter");

// Get current provider
const current = getDefaultProvider();
console.log(`Current provider: ${current}`);

// Launch specific provider
await launchOpenRouter(false, [], "gpt-4");

// Manage API keys programmatically
await showApiKeyMenu(); // Show interactive API key menu
await updateApiKey({
  id: "openrouter",
  name: "OpenRouter",
  envVar: "OPENROUTER_AUTH_TOKEN",
}); // Update specific API key
console.log(maskApiKey("sk-1234567890abcdef")); // "sk-1234...cdef"

Development

# Install for development with symlink (changes are immediate)
npm run link

# Run directly from source
npm run dev -- --help

# Run tests
npm run test:all

# Unlink development version
npm run unlink

# Install production version
npm install -g .

🐛 Troubleshooting

Common Issues

"API key required" error

  • Check your .env file contains the correct API key
  • Ensure the .env file is in your current working directory

Menu selection not showing options, opens Claude Code directly

  • Try clearing defaults: claude-switch clear-defaults

File permission errors

  • Ensure you have write permissions to create/modify the .env file
  • Try running with elevated permissions if necessary

Debug Mode

For debugging, you can run the tool directly from source:

node bin/claude-switch.js --help

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Development Scripts

  • npm run dev - Run directly from source
  • npm run test:validation - Run validation tests
  • npm run test:provider - Run provider integration tests
  • npm run test:comprehensive - Run comprehensive tests
  • npm run test:all - Run all test suites

📄 License

MIT License - see LICENSE file for details

🔗 Related Projects

📞 Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section above
  2. Search existing GitHub issues
  3. Create a new issue with detailed information
  4. Include your OS, Node.js version, and error messages

Made with ❤️ by Adrian R