Architecture
CCS is designed with simplicity and reliability in mind. The architecture follows YAGNI, KISS, and DRY principles.Core Components
Account Profiles
Isolated Claude instances with separate credentials and session data
OAuth Providers
CLIProxy-based providers (Gemini, Codex, Agy) with zero config
API Profiles
Settings-based profiles for GLM, KM, and custom providers
Profile Resolution
Smart profile detection that checks CLIProxy → Settings → Account profiles in
order
Claude CLI Spawn
Spawns Claude CLI with resolved profile settings via
--settings flagProfile Mechanisms (Priority Order)
- CLIProxy hardcoded: gemini, codex, agy → OAuth-based, zero config
- CLIProxy variants:
config.cliproxysection → user-defined providers - Settings-based:
config.profilessection → GLM, KM - Account-based: Account metadata in
config.yaml→ isolated instances viaCLAUDE_CONFIG_DIR
Execution Flow
Directory Structure
Design Principles
Non-Invasive
- Never modifies
~/.claude/settings.json - Uses
--settingsflag for delegation - Claude CLI manages its own state
Idempotent
- All install operations safe to run multiple times
- Profile creation handles existing directories
- No side effects on repeated runs
Cross-Platform Parity
- Same behavior on macOS, Linux, Windows
- Node.js handles platform differences
- Unified codebase for all platforms
Configuration Priority Resolution
CCS resolves configuration in this order (highest to lowest priority):- CLI flags - Direct command-line arguments (
--proxy-host,--model, etc.) - Environment variables - Shell exports (
CCS_PROXY_HOST,ANTHROPIC_MODEL, etc.) - config.yaml - User configuration file (
~/.ccs/config.yaml) - Built-in defaults - Hardcoded fallback values
Proactive Token Refresh
OAuth providers (Gemini, Codex, Antigravity) proactively refresh tokens when they’re within 5 minutes of expiration. This prevents mid-session authentication failures and ensures seamless long-running conversations. How it works:- Token expiry checked before each API call
- If token expires in <5 minutes, automatic refresh triggered
- User never sees authentication interruptions
- Works silently in background
Graceful Degradation
CCS implements fallback mechanisms for robust operation: Remote → Local Proxy Fallback:- Attempts remote CLIProxy connection first
- On failure, automatically falls back to local proxy
- Configurable via
CCS_PROXY_FALLBACK_ENABLEDor--remote-onlyflag - Health checks run with configurable timeout
- Handles connection timeouts gracefully
- Auto-retry on transient failures
- Clear error messages when fallback exhausted
Technology Stack
| Component | Technology |
|---|---|
| CLI | Node.js (ES modules) |
| Build | Bun + TypeScript |
| Dashboard | React + Vite |
| Package | npm |
Advanced Architecture Patterns
Unified Config Pattern
CCS v6+ uses a singleconfig.yaml file for all configuration instead of scattered JSON files. This simplifies management and enables atomic updates.
Benefits:
- Single source of truth for all settings
- Easier backup and version control
- Atomic configuration updates
- Reduced file I/O operations
ccs migrate to convert legacy config files to unified format.
Session Reference Counting
CLIProxy tracks active sessions using reference counting to prevent premature shutdown:- Each active Claude session increments counter
- Session end decrements counter
- Proxy only stops when counter reaches zero
- Prevents disruption of concurrent sessions
~/.ccs/cliproxy/sessions.json- Global session tracking~/.ccs/cliproxy/sessions-{port}.json- Variant-specific sessions
Version Mismatch Detection
CCS automatically detects CLIProxy binary version mismatches and handles them gracefully: Detection:- Compares expected version in config vs installed binary
- Checks on every proxy startup
- Validates on health check failures
- Stops outdated proxy instance
- Downloads latest compatible version
- Restarts proxy with new binary
- Preserves session state
- Transparent to user (no interruption)
- Logged for debugging (
~/.ccs/logs/) - Optional notification in dashboard
Performance
| Operation | Time |
|---|---|
| Profile switch | < 10ms |
| First account activation | ~20-35ms |
| Subsequent activation | ~5-10ms |
| Dashboard startup | ~300ms |
