A lightweight, cross-platform command-line tool for managing multiple Claude Code configuration profiles. It allows users to easily switch between different sets of configurations, such as API keys, endpoints, and model mappings, using simple commands like ccswap use <profile>. The tool supports both API key and OAuth2 authentication methods.
Version: 2.0.0 (with OAuth2 Device Code Flow support)
Built with ❤️ by JUAN MACKIE
- Download
ccswap.bat - Copy to
C:\Windows\System32\ccswap.bat - Open new Command Prompt and run:
ccswap
- Create
C:\toolsdirectory - Copy
ccswap.battoC:\tools\ccswap.bat - Add to PATH:
- Press
Win + R, typesysdm.cpl - Go to "Advanced" → "Environment Variables"
- Edit "Path" → add
C:\tools
- Press
- Restart Command Prompt and run:
ccswap
# Make executable
chmod +x ccswap
# Move to system path
sudo mv ccswap /usr/local/bin/
# Test
ccswap help# Create bin directory
mkdir -p ~/bin
# Move script
mv ccswap ~/bin/
# Add to PATH (add to ~/.bashrc or ~/.zshrc)
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Test
ccswap helpAfter installation, verify it works:
# Windows
ccswap help
# Unix/Linux/macOS
ccswap helpYou should see the usage information if installed correctly.
- Run Claude Code at least once to create
settings.json - Save your first profile:
ccswap save default - Create additional profiles as needed
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "REDACTED-INSERT YOUR KEY",
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.6"
}
}
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "REDACTED-INSERT YOUR KEY",
"ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k2-thinking",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k2-thinking",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k2-thinking"
}
}
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "REDACTED-INSERT YOUR KEY",
"ANTHROPIC_BASE_URL": "https://api.minimax.io/anthropic",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "MiniMax-M2",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "MiniMax-M2",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "MiniMax-M2"
}
}
%USERPROFILE%.claude
├── settings.json # Active Claude Code config
├── profiles\ # Profile storage
│ ├── default.json
│ ├── work.json
│ └── personal.json
└── _current.txt # Active profile tracker
$HOME/.claude/ ├── settings.json # Active Claude Code config ├── profiles/ # Profile storage │ ├── default.json │ ├── work.json │ └── personal.json └── active_profile # Active profile tracker
## Troubleshooting
### Windows Issues
- **"ccswap not recognized"**: Add to PATH or use full path
- **"Access denied"**: Run Command Prompt as Administrator
- **PowerShell issues**: Use Command Prompt instead
### Unix Issues
- **"Permission denied"**: Run `chmod +x ccswap`
- **"command not found"**: Add to PATH or use full path
- **"No such file"**: Create `~/.claude/` directory first
## Uninstallation
### Windows
```bash
# Remove from System32
del C:\Windows\System32\ccswap.bat
# Or remove from tools directory
del C:\tools\ccswap.bat
# Remove from system
sudo rm /usr/local/bin/ccswap
# Or remove from user directory
rm ~/bin/ccswapYour profiles and settings remain in ~/.claude/ for future use.
ccswap v2.0.0 adds support for OAuth2 Device Code Flow authentication, enabling you to use enterprise SSO or custom OAuth2 providers with Claude Code.
OAuth2 support requires additional tools:
# Debian/Ubuntu
sudo apt-get install curl jq openssl
# RHEL/CentOS/Fedora
sudo dnf install curl jq opensslbrew install curl jq opensslcurl- Built-in on Windows 10 1803+PowerShell 5.1+- Built-in on Windows 10+jq- Install via:Or download from: https://stedolan.github.io/jq/download/choco install jq
OAuth2 profiles include an auth_type field and an oauth2 configuration object:
{
"auth_type": "oauth2",
"oauth2": {
"client_id": "your_client_id_here",
"client_secret": "your_client_secret_here",
"device_code_endpoint": "https://auth.example.com/oauth/device_code",
"token_endpoint": "https://auth.example.com/oauth/token",
"scopes": "openid profile email offline_access"
},
"env": {
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"API_TIMEOUT_MS": "3000000",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-3-haiku-20240307",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-3-5-sonnet-20241022",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-3-opus-20240229"
}
}| Field | Description | Required |
|---|---|---|
auth_type |
Must be "oauth2" |
Yes |
oauth2.client_id |
OAuth2 client ID | Yes |
oauth2.client_secret |
OAuth2 client secret | Yes* |
oauth2.device_code_endpoint |
Device authorization endpoint | Yes |
oauth2.token_endpoint |
Token endpoint | Yes |
oauth2.scopes |
OAuth2 scopes (default: openid profile email offline_access) | No |
*Some OAuth2 providers (public clients) don't require a client secret for Device Code Flow.
Authenticate a profile using OAuth2 Device Code Flow:
ccswap oauth login <profile>Example:
ccswap oauth login workWhat happens:
- You'll be prompted to create an encryption password for storing OAuth tokens
- A device code is obtained from your OAuth2 provider
- You'll see instructions to visit a URL and enter a code
- Once you complete authorization in your browser, tokens are automatically retrieved
- Tokens are encrypted with your password and stored securely
Check the current OAuth2 token status:
ccswap oauth status <profile>Example:
ccswap oauth status workOutput:
Enter password to decrypt OAuth tokens: ********
OAuth2 Token Status
===========================================
Authentication Type: OAuth2
Token Type: Bearer
Access Token: eyJhbGci...VzI1Ni
Status: Active
Expires: 45m 23s from now
Scopes: openid profile email offline_access
===========================================
Remove OAuth2 credentials from a profile:
ccswap oauth logout <profile>Example:
ccswap oauth logout workThis deletes the encrypted token file. The profile itself remains and can be re-authenticated.
OAuth2 profiles work seamlessly with existing ccswap commands:
ccswap use work_oauthWhat happens:
- Detects that the profile uses OAuth2
- Prompts for your token decryption password
- Checks if the access token is expired
- Automatically refreshes if needed (using the refresh token)
- Updates
settings.jsonwith the fresh access token
ccswap save work_backupIf the currently active profile is OAuth2, the encrypted tokens are also copied to the new profile.
ccswap lsOAuth2 profiles are marked with [OAuth2]:
Available profiles:
* default
work [OAuth2]
personal [OAuth2] (active)
ccswap rm workBoth the profile JSON and the encrypted token file are deleted.
OAuth2 tokens are stored encrypted in your profiles directory:
Unix/Linux/macOS:
~/.claude/profiles/
├── work.json # Profile configuration
└── work_tokens.enc # Encrypted OAuth tokens
Windows:
%USERPROFILE%\.claude\profiles\
├── work.json # Profile configuration
└── work_tokens.enc # Encrypted OAuth tokens
- Algorithm: AES-256-CBC
- Key Derivation: PBKDF2 with 100,000 iterations
- File Permissions: 600 (user read/write only on Unix/macOS)
- Password: User-provided, not stored anywhere
OAuth2 access tokens typically expire after 1 hour. ccswap automatically handles token refresh:
- When you use an OAuth2 profile, it checks if the token is expired (or within 5 minutes of expiration)
- If expiring, it automatically uses the refresh token to get a new access token
- The new token is re-encrypted and stored
- No manual intervention required
If the refresh token is expired or invalid, you'll be prompted to re-authenticate:
ccswap oauth login workYou can have both API key and OAuth2 profiles:
Available profiles:
* default # API key profile
work # API key profile
enterprise [OAuth2] # OAuth2 profile
personal # API key profile
Switching between profile types works seamlessly:
ccswap use default # Uses API key from profile
ccswap use enterprise # Prompts for OAuth2 password, decrypts tokens- Strong Passwords: Use a strong password for encrypting OAuth tokens
- HTTPS Only: All OAuth2 endpoints must use HTTPS
- Secure Storage: Token files have restrictive permissions (600 on Unix/macOS)
- Regular Rotation: Consider running
ccswap oauth logoutthenccswap oauth loginperiodically to get fresh tokens
| Location | Content | Encryption |
|---|---|---|
Profile JSON (<name>.json) |
Client ID, client secret, endpoints | No (plain text) |
Token file (<name>_tokens.enc) |
Access token, refresh token | Yes (AES-256-CBC) |
Storing OAuth2 client credentials in the profile JSON is standard practice. These are not secret - they're meant to be distributed to client applications. The actual secrets (access tokens and refresh tokens) are encrypted.
Install the required tools:
# Linux
sudo apt-get install curl jq openssl
# macOS
brew install curl jq openssl
# Windows (jq only)
choco install jq- Wrong password entered
- Token file corrupted
- Solution: Try again with correct password, or delete and re-authenticate
- Refresh token expired or revoked
- OAuth2 provider issues
- Solution: Run
ccswap oauth login <profile>to re-authenticate
- Device code expired (usually 30 minutes)
- User didn't complete authorization in time
- Solution: Run
ccswap oauth login <profile>again
Check your profile JSON has all required fields:
auth_type: "oauth2"oauth2.client_idoauth2.device_code_endpointoauth2.token_endpoint
To convert an existing API key profile to OAuth2:
-
Backup your current profile:
cp ~/.claude/profiles/work.json ~/.claude/profiles/work.json.bak
-
Edit the profile to add OAuth2 configuration:
# Add auth_type and oauth2 fields nano ~/.claude/profiles/work.json
Change from:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "your-api-key", ... } }To:
{ "auth_type": "oauth2", "oauth2": { "client_id": "your_client_id", "device_code_endpoint": "https://...", "token_endpoint": "https://...", "scopes": "openid profile email offline_access" }, "env": { "ANTHROPIC_BASE_URL": "https://...", ... } } -
Authenticate:
ccswap oauth login work
-
Use the profile:
ccswap use work
To revert back to API key authentication, simply remove the auth_type and oauth2 fields from your profile JSON and restore the ANTHROPIC_AUTH_TOKEN in the env section.