Skip to content

wlsdnen/claude-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Claude Switcher

Switch between Claude Code login mode (subscription) and API key mode easily.

License: MIT Platform Node

❓ The Problem

Claude Code prioritizes ANTHROPIC_API_KEY over your subscription login. This means:

  • If you have an API key set, Claude always uses it (and charges your API account)
  • To use your Pro/Max subscription, you must manually unset the environment variable
  • Switching between modes is tedious

✨ The Solution

claude-switcher (or cs) lets you choose which mode to use when launching Claude:

cs login    # Use subscription (ignores API key)
cs api      # Use API key
cs status   # Check current configuration

🎁 Features

  • 🎯 Zero configuration needed – Works out of the box with existing Claude Code installations
  • ⚑ Instant mode switching – Seamlessly toggle between subscription and API key modes
  • πŸ” Secure credential management – No passwords stored, uses system keychain
  • πŸ“ Clear status information – Always know which mode you're running in
  • πŸ”„ Seamless Claude integration – All Claude flags and arguments supported

πŸ“¦ Installation

Install directly from GitHub:

npm install -g github:wlsdnen/claude-switcher

Or using a specific version/tag:

npm install -g github:wlsdnen/claude-switcher#v1.0.0

Updating

To update to the latest version:

npm install -g github:wlsdnen/claude-switcher

πŸš€ Usage

Login Mode (Subscription)

Run Claude using your Pro/Max/Team subscription, even if ANTHROPIC_API_KEY is set:

cs login

This temporarily removes the ANTHROPIC_API_KEY environment variable for the Claude session.

API Key Mode

Run Claude using your API key:

cs api

Requires ANTHROPIC_API_KEY to be set in your environment.

Check Status

See your current authentication configuration:

cs status

Output example:

πŸ“Š Claude Switcher Status
────────────────────────────────────────

Claude CLI:
  βœ“ Installed
    Credentials stored in macOS Keychain

API Key (ANTHROPIC_API_KEY):
  βœ“ Set (sk-ant-...xxx)

────────────────────────────────────────
Mode Selection:
  ⚠  Running claude directly will use API key
     (ANTHROPIC_API_KEY takes priority over subscription)

Usage:
  cs login  β†’ Use subscription (ignores API key)
  cs api    β†’ Use API key

Passing Arguments to Claude

All arguments after the mode are passed directly to Claude:

# Start Claude in a specific directory
cs login -p ./my-project

# Continue previous session
cs login --continue

# Use with any Claude flags
cs api --model opus

πŸ”§ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ cs login    β”‚ ──▢ β”‚ Remove API key from  β”‚ ──▢ β”‚ claude      β”‚
β”‚             β”‚     β”‚ environment          β”‚     β”‚ (subscription)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ cs api      β”‚ ──▢ β”‚ Keep API key in      β”‚ ──▢ β”‚ claude      β”‚
β”‚             β”‚     β”‚ environment          β”‚     β”‚ (API)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Setting Up Your API Key

If you want to use API mode, set your API key:

# For current session
export ANTHROPIC_API_KEY="your-api-key-here"

# To persist (add to shell config)
echo 'export ANTHROPIC_API_KEY="your-api-key"' >> ~/.zshrc
source ~/.zshrc

Get your API key at: https://console.anthropic.com/

πŸ“‹ Requirements

  • Node.js 18 or later
  • Claude Code CLI installed (npm install -g @anthropic-ai/claude-code)

🌍 Platform Support

  • macOS
  • Linux
  • Windows

πŸ” Troubleshooting

Claude CLI not found

Make sure Claude Code is installed:

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

API key not working

  1. Check if the key is set: echo $ANTHROPIC_API_KEY
  2. Verify the key format starts with sk-ant-
  3. Make sure the key is valid at https://console.anthropic.com/

Login mode still uses API key

This shouldn't happen, but if it does:

  1. Run cs status to verify the setup
  2. Try running Claude directly without the key: unset ANTHROPIC_API_KEY && claude

🀝 Contributing

Issues and pull requests are welcome! Feel free to check issues page if you want to contribute.

Found a bug? Have a feature request? Please open an issue.

πŸ“„ License

MIT


Version: 1.0.0 | Status: Production Ready | Last Updated: 2026-02-06

About

πŸ” Switch between Claude Code subscription and API key modes seamlessly

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors