Skip to content

incompletebiped/c2switcher-mint

 
 

Repository files navigation

C2Switcher (Mint Cinnamon Edition)

Manage multiple Claude Code accounts with usage tracking, load balancing, and a Cinnamon panel applet

This is a fork of can1357/c2switcher adapted for Linux Mint Cinnamon. The CLI tools work identically; the KDE Plasma widget has been replaced with a native Cinnamon applet.

Features

Retro (default) Classic
Retro Theme Classic Theme

Live usage monitoring with color-coded indicators and one-click account switching Click the "Claude Switcher" title in the popup to toggle between themes

  • Multi-account management - Add, remove, reorder, and edit accounts with nicknames
  • Auto-detect new logins - Applet monitors ~/.claude/.credentials.json and auto-imports new accounts
  • Usage tracking - Monitor 5-hour, 7-day, and Sonnet usage limits with color-coded indicators
  • Smart load balancing - Automatically picks the optimal account based on usage, drain rates, and active sessions
  • Session-safe switching - Detects when Claude Code is actively processing and blocks switching mid-request
  • Auto-switch on rate limit - When your current account hits 95%+ usage, automatically swaps to the optimal account between prompts or after the session ends
  • Re-authentication detection - Accounts with expired or revoked tokens are flagged automatically. The applet shows a "Re-auth" button instead of usage badges, and switching to the account is blocked until credentials are refreshed via c2switcher login
  • Active account indicator - Green dot and legend marker show which account Claude Code is currently using
  • Session tracking - See which accounts are actively being used and where
  • Dual themes - Retro-futurist purple (default) or classic orange — click the title to toggle
  • Cinnamon panel applet - Monitor all accounts from your panel with one-click switching
  • Usage caching - Respects rate limits with 5-minute cache
  • Wrapper script - c2claude command for seamless account switching

Disclaimer

This tool uses undocumented OAuth API endpoints to fetch usage data and authenticate accounts. While Anthropic allows users to create multiple accounts (confirmed by multiple people who asked Anthropic Staff, including me), this implementation relies on reverse-engineered API endpoints that may change without notice.

If Anthropic would prefer this tool not exist, please reach out and I'll gladly take it down. I'm very compliant like that :)


Installation

Prerequisites

  • Linux Mint (Cinnamon edition) - tested on Mint 21.x / 22.x
  • Python 3.7+
  • Claude Code CLI installed and configured
  • pipx (installed automatically by setup.sh, or: sudo apt install pipx)

Quick Start

One-line install:

curl -fsSL https://raw.githubusercontent.com/incompletebiped/c2switcher-mint/master/setup.sh | bash

Or clone and run interactively:

git clone https://github.com/incompletebiped/c2switcher-mint.git
cd c2switcher-mint
./setup.sh

The interactive installer will ask what you want to install:

  • CLI tools only
  • CLI tools + Cinnamon applet
  • Cinnamon applet only (if CLI already installed)

Install options

./setup.sh              # Interactive mode
./setup.sh --all        # Install everything (CLI + applet + status line)
./setup.sh --cli        # CLI tools only
./setup.sh --applet     # Cinnamon applet only (requires CLI)
./setup.sh --statusline # Claude Code status line only (requires CLI)
./setup.sh --uninstall  # Remove everything

Step 3: Add the applet to your panel

  1. Right-click on your Cinnamon panel
  2. Click "Applets"
  3. In the applet list, find "Claude Code Usage"
  4. Click the + button (or toggle it on) to add it to your panel

The applet will appear on your panel showing the average Sonnet usage percentage.

Step 4: Add your accounts

# Recommended: OAuth login (opens browser)
c2switcher login --nickname main

# Add more accounts
c2switcher login --nickname work
c2switcher login --nickname personal

Or import existing credentials from ~/.claude/.credentials.json:

c2switcher add --nickname main

Step 5: Verify it works

# Check that accounts are registered
c2switcher ls

# Fetch usage (the applet calls this automatically)
c2switcher usage

# Launch Claude with the optimal account
c2claude

The panel applet should now show your usage data. Click it to see the full popup with per-account details.

Optional: Claude Code Status Line

Show the active c2switcher account and its usage directly in the Claude Code status bar. Updates live whenever you switch accounts.

./setup.sh --statusline

Or select option 3 (everything) or 5 (status line only) in interactive mode.

What it looks like:

[0] work  5h:42%  7d:18%

Usage percentages are color-coded to match the applet's thresholds (green / yellow / red). Only requires python3, which is already a c2switcher dependency.

Manual setup (if you prefer to do it yourself):

  1. Create ~/.claude/statusline-command.sh:
cat > ~/.claude/statusline-command.sh << 'STATUSLINE_EOF'
#!/usr/bin/env bash
cat > /dev/null  # consume Claude Code's JSON input

RESET=$'\033[00m'
PURPLE=$'\033[38;5;141m'
GREEN=$'\033[38;5;82m'
YELLOW=$'\033[38;5;226m'
RED=$'\033[38;5;196m'

usage_color() {
    local pct="${1%%%*}"; pct="${pct%.*}"
    if   [ "$pct" -ge 90 ] 2>/dev/null; then printf '%s' "$RED"
    elif [ "$pct" -ge 70 ] 2>/dev/null; then printf '%s' "$YELLOW"
    else                                      printf '%s' "$GREEN"
    fi
}

account=""
usage_str=""

if command -v c2switcher &>/dev/null; then
    account=$(c2switcher current --format=prompt 2>/dev/null)

    if [ -n "$account" ]; then
        idx=$(c2switcher current --json 2>/dev/null | python3 -c \
            "import sys,json; print(json.load(sys.stdin).get('index',''))" 2>/dev/null)

        if [ -n "$idx" ]; then
            usage_json=$(c2switcher usage --json 2>/dev/null)
            if [ -n "$usage_json" ]; then
                read -r five_h seven_d <<< "$(echo "$usage_json" | python3 -c "
import sys, json
data = json.load(sys.stdin)
idx = int('$idx')
for acc in data:
    if acc.get('index') == idx:
        u = acc.get('usage', {})
        fh = u.get('five_hour', {}).get('utilization')
        sd = u.get('seven_day', {}).get('utilization')
        print(
            (str(round(fh)) + '%') if fh is not None else '',
            (str(round(sd)) + '%') if sd is not None else ''
        )
        break
" 2>/dev/null)"
                if [ -n "$five_h" ] || [ -n "$seven_d" ]; then
                    [ -n "$five_h"  ] && usage_str+="$(usage_color "$five_h")5h:${five_h}${RESET}"
                    [ -n "$five_h"  ] && [ -n "$seven_d" ] && usage_str+=" "
                    [ -n "$seven_d" ] && usage_str+="$(usage_color "$seven_d")7d:${seven_d}${RESET}"
                fi
            fi
        fi
    fi
fi

if [ -n "$account" ]; then
    line="${PURPLE}${account}${RESET}"
    [ -n "$usage_str" ] && line+=" ${usage_str}"
    printf '%s' "$line"
fi
STATUSLINE_EOF
chmod +x ~/.claude/statusline-command.sh
  1. Add to ~/.claude/settings.json (replace /home/yourname with your actual home directory):
{
  "statusLine": {
    "type": "command",
    "command": "bash /home/yourname/.claude/statusline-command.sh"
  }
}

Cinnamon Panel Applet

What it shows

Panel icon: A system-monitor icon with your average Sonnet usage percentage, color-coded:

  • Green (< 70%) - Plenty of headroom
  • Yellow-orange (70-90%) - Getting close
  • Red-orange (> 90%) - Nearly exhausted

Popup (click the icon):

  • Header with refresh and optimal-switch buttons
  • Sonnet usage bar - Full-width stacked segments showing each account's Sonnet utilization
  • Overall usage bar - Full-width stacked segments showing each account's 7-day utilization
  • Color legend with active account indicator (triangle marker)
  • Account cards - One per account, showing:
    • Active indicator (green dot for the currently active account)
    • Index, nickname (editable via pencil icon), and email
    • Four usage indicators: 5-hour, 7-day, Sonnet, and overuse rate
    • Time-until-reset countdown in the indicator labels
    • Re-auth button (replaces usage indicators when token is expired/revoked)
    • Remove button (trash icon) to delete the account
    • Hover tooltip with detailed reset times

Interacting with the applet

  • Click the "Claude Switcher" title to toggle between retro (purple) and classic (orange) themes
  • Click an account card to switch to that account
  • Click the star button to auto-switch to the optimal account (locked while Claude is processing)
  • Click the refresh button to force a data update (menu stays open)
  • Click the pencil icon on a card to edit the account nickname (Enter to save, Escape to cancel)
  • Click the up/down arrows on a card to reorder account priority (affects load balancer round-robin)
  • Click the trash icon on a card to remove the account from c2switcher (also clears credentials if it was the active account)
  • Click the Re-auth button on a card with expired credentials to open a terminal and re-authenticate via c2switcher login
  • Data auto-refreshes every 60 seconds

Session-safe switching

The applet detects whether Claude Code is actively processing by checking for established TCP connections from Claude's PIDs to non-localhost hosts (via ss):

State Optimal button Manual card click
Claude idle at prompt Unlocked (star icon) Works
Claude streaming a response Locked (lock icon) Works (use at your own risk)
No Claude process running Unlocked (star icon) Works
Account needs re-auth N/A Blocked (Re-auth button shown instead)

The lock icon updates live every time you open the applet menu. Accounts with expired tokens show a "Token expired" label and a Re-auth button in place of usage indicators — clicking the card body is suppressed until credentials are refreshed.

Auto-switch on rate limit

When the current account's usage reaches 95%+ (on either the 5-hour or 7-day Sonnet window), the applet automatically switches to the optimal account:

  • Between prompts - If Claude is open but idle, credentials are swapped seamlessly before the next request
  • After session ends - If Claude Code is fully closed, credentials are pre-positioned for the next session
  • During processing - Auto-switch waits until the current request finishes
  • 5-minute cooldown between auto-switches to prevent rapid back-and-forth
  • Only triggers when there are 2+ accounts registered

Auto-detect new logins

The applet monitors ~/.claude/.credentials.json for changes. When a new login is detected (refresh token changes), the new account is automatically imported into c2switcher via c2switcher add. Regular token refreshes (same account, new access token) are ignored to avoid unnecessary API calls.

Upgrading the applet

After pulling new changes:

./setup.sh --applet

Then restart Cinnamon to pick up the changes: press Alt+F2, type r, and press Enter.

Troubleshooting the applet

Applet shows "Error Loading Data":

Make sure c2switcher is installed and on your PATH:

c2switcher usage --json

If this command works in a terminal but the applet can't find it, check that the install path is in Cinnamon's PATH:

# Check where c2switcher is installed
which c2switcher

# Common locations that should be on PATH:
# /usr/local/bin/c2switcher
# ~/.local/bin/c2switcher

Applet not appearing in the applet list:

Verify the files are in the right place:

ls ~/.local/share/cinnamon/applets/c2switcher@c2switcher-mint/
# Should show: applet.js  metadata.json  stylesheet.css

If missing, re-run ./setup.sh --applet.

Applet not updating after upgrade:

Restart Cinnamon: Alt+F2 -> type r -> Enter.

Checking applet logs:

Open Cinnamon's Looking Glass debugger (Alt+F2 -> type lg -> Enter) and check the "Log" tab for errors containing c2switcher.


CLI Usage

Adding Accounts

Option 1: OAuth Login (Recommended)

c2switcher login

Options:

c2switcher login --nickname work       # Login with a nickname
c2switcher login --manual-only         # Disable localhost server
c2switcher login --no-browser          # Don't auto-open browser
c2switcher login --no-add              # Save creds but don't add to c2switcher

Option 2: Import Existing Credentials

c2switcher add                                            # Add current account
c2switcher add --nickname work                            # With a nickname
c2switcher add --creds-file ~/path/to/credentials.json    # From a specific file

Viewing Accounts

c2switcher ls

Editing Nicknames

c2switcher nickname 0 "My Work Account"    # By index
c2switcher nickname work "Work Pro"        # By current nickname
c2switcher nickname user@email.com "Main"  # By email

Removing Accounts

c2switcher remove 0                        # By index (prompts for confirmation)
c2switcher remove work                     # By nickname
c2switcher remove user@email.com           # By email
c2switcher remove 0 --yes                  # Skip confirmation

If the removed account is currently active in ~/.claude/.credentials.json, the credentials file is also cleared.

Checking Usage

c2switcher usage            # Rich table output
c2switcher usage --force    # Bypass 5-minute cache
c2switcher usage --json     # JSON output for scripting

Color indicators:

  • Green (< 70%) - Plenty of headroom
  • Yellow (70-90%) - Getting close
  • Red (> 90%) - Nearly exhausted

Switching Accounts

c2switcher switch 0                    # By index
c2switcher switch work                 # By nickname
c2switcher switch user@example.com     # By email

Finding the Optimal Account

c2switcher optimal                     # Auto-switch to best account
c2switcher optimal --dry-run           # Show best without switching
c2switcher optimal --token-only --quiet  # Get token for scripts

Cycling Through Accounts

c2switcher cycle       # Rotate to next account

Checking Current Account

c2switcher current
c2switcher current --format=prompt     # For shell prompts: [0] main
c2switcher current --json

Generating Analytics Reports

# Session insights (top projects, daily cadence, heatmaps)
c2switcher report-sessions \
  --db ~/.c2switcher/store.db \
  --output ~/c2switcher_session_report.png \
  --days 30 --min-duration 60

# Usage risk forecast (burn rates, reset timeline)
c2switcher report-usage \
  --db ~/.c2switcher/store.db \
  --output ~/c2switcher_usage_report.png \
  --window-hours 24

Add --show to display the figure after saving.


The c2claude Wrapper

Combines account selection with running Claude Code:

c2claude                   # Use optimal account (default)
c2claude -0                # Use account 0
c2claude -1                # Use account 1
c2claude -a work           # Use account by name/email/index
c2claude --cycle           # Cycle to next account
c2claude -p "explain this" # Pass arguments to claude

The wrapper handles session registration, load balancing, account stickiness, and cleanup on exit.


Command Reference

Core Commands

Command Aliases Description
login OAuth login and add account
add Import existing account credentials
remove Remove an account from c2switcher
nickname Set or update an account nickname
reorder Reorder accounts by specifying new order
ls list, list-accounts List all accounts
usage Show usage across accounts
current Show currently active account
report-sessions Generate session analytics report
report-usage Generate usage risk forecast report
optimal pick Find and switch to optimal account
switch use Switch to specific account
cycle Rotate to next account
sessions List active sessions
history session-history Show past sessions with usage deltas
force-refresh Force token refresh for account(s)

Session Commands (used by c2claude, not typically manual)

Command Description
start-session Register a new Claude session
end-session Mark a session as ended

How It Works

Database

All data is stored in ~/.c2switcher/store.db (SQLite):

  • Account credentials and metadata
  • Usage history with timestamps
  • Session tracking (PID, working directory, duration)

Token Refresh

Tokens are automatically refreshed when within 10 minutes of expiry. Force a manual refresh:

c2switcher force-refresh          # All accounts
c2switcher force-refresh work     # Specific account

Usage Caching

API calls are cached for 5 minutes to avoid rate limiting. Use --force to bypass.

Load Balancing Algorithm

The optimal account selection uses a multi-factor scoring system:

  1. Drain rate (core metric) - headroom / hours_until_reset where headroom = 99% - current utilization. Higher drain rate = more capacity available per hour = better candidate.
  2. Window selection - Uses the Overall window (tier 2) while it has headroom, falls back to the Sonnet window (tier 1) when Overall is exhausted.
  3. Five-hour throttling - Penalizes accounts with high short-term usage to prevent burst rate limits. Score is halved at 90%+ five-hour utilization.
  4. Burst protection - Skips accounts where current usage + expected burst (based on historical deltas) >= 94%.
  5. Pace alignment - When Sonnet usage exceeds 90%, adjusts score based on whether usage is ahead of or behind the expected pace for the reset window.
  6. Session awareness - Among similar candidates, prefers accounts with fewer active and recent sessions.
  7. Round-robin - Accounts within 0.05 %/hr of each other are treated as equivalent and rotated fairly.

Accounts at 99%+ on both Sonnet and Overall windows are excluded entirely.

Session Tracking

Each c2claude invocation registers a session, selects an account, runs Claude, and cleans up on exit. Dead sessions are auto-cleaned via multi-factor liveness checks.


Files and Paths

Path Purpose
~/.c2switcher/store.db SQLite database (accounts, usage, sessions)
~/.c2switcher/load_balancer_state.json Round-robin state for fair rotation
~/.c2switcher/.last_cleanup Session cleanup throttle marker
~/.claude/.credentials.json Active Claude Code credentials
~/.local/share/cinnamon/applets/c2switcher@c2switcher-mint/ Cinnamon applet files

Environment Variables

Variable Description
DEBUG_SESSIONS=1 Enable verbose session tracking logs
C2SWITCHER_DEBUG_BALANCER=1 Show detailed load balancer scoring

Roadmap

All planned applet features are complete:

  • Reorder account priority - Up/down arrows on each card to reorder accounts (affects load balancer round-robin)
  • Re-authentication detection - Expired/revoked tokens are flagged with a Re-auth button; switching is blocked until credentials are refreshed
  • Dual themes - Retro-futurist purple and classic orange, toggled by clicking the title

Uninstallation

One-line uninstall (works from anywhere):

curl -fsSL https://raw.githubusercontent.com/incompletebiped/c2switcher-mint/master/setup.sh | bash -s -- --uninstall

Or from a local checkout:

./setup.sh --uninstall

Or manually:

# Remove CLI tools
pipx uninstall c2switcher
rm ~/.local/bin/c2claude

# Remove Cinnamon applet
rm -rf ~/.local/share/cinnamon/applets/c2switcher@c2switcher-mint/

# Remove all c2switcher data (optional)
rm -rf ~/.c2switcher/

Upgrading

Re-running the installer overwrites the previous install:

curl -fsSL https://raw.githubusercontent.com/incompletebiped/c2switcher-mint/master/setup.sh | bash

Then restart Cinnamon to reload the applet: Alt+F2 -> type r -> Enter.


Troubleshooting

"c2switcher: command not found"

Ensure the install location is on your PATH:

export PATH="$HOME/.local/bin:/usr/local/bin:$PATH"

Add to ~/.bashrc to make permanent.

Token refresh fails

If you see "Failed to refresh token" or an account shows the Re-auth button in the applet:

  1. Click the Re-auth button on the account card (opens a login terminal), or run manually:
    c2switcher login
  2. Log in with the affected account — the existing account record is updated automatically by UUID match.

Verify Claude works: claude -p hi --model haiku

Sessions not tracked properly

Dead sessions auto-cleanup, but you can check manually:

c2switcher sessions
DEBUG_SESSIONS=1 c2claude     # Verbose session logging

Development

git clone https://github.com/incompletebiped/c2switcher-mint.git
cd c2switcher-mint
pipx install --editable .
c2switcher --help

The CLI entry point is c2switcher, and the Python package lives under c2switcher/. The Cinnamon applet source is in applet/.

Credits

Original project by can1357. Cinnamon applet port for Linux Mint.


Tip: Bind c2claude to a shell alias or keyboard shortcut for maximum laziness.

About

Manage multiple Claude Code accounts with usage tracking & load balancing.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Contributors

Languages

  • Python 70.9%
  • JavaScript 15.2%
  • QML 7.7%
  • Shell 5.1%
  • CSS 1.1%