$ show farion1231/cc-switch
CC Switch is a desktop application built with Tauri (Rust backend + React/TypeScript frontend) that serves as a unified management hub for multiple AI coding assistants, including Claude Code, Claude Desktop, Codex, Gemini CLI, Grok Build, OpenCode, OpenClaw, and Hermes Agent. Its core function is provider switching: it manages configurations, API keys, OAuth tokens, and MCP servers across these tools, and provides a local HTTP proxy that routes API requests to different AI providers with failover, circuit breaking, and usage tracking. The application also includes session management, skills/prompts synchronization, cloud sync (S3/WebDAV), deep link import/export, and a usage dashboard with cost tracking. The architecture follows a command-service-DAO pattern in Rust, with a React frontend using TanStack Query for state management, react-hook-form for forms, and shadcn/ui components. The proxy subsystem is particularly sophisticated, implementing format conversion bridges between different AI API protocols (Anthropic Messages, OpenAI Chat/Responses, Gemini), streaming transforms, thinking budget optimization, cache injection, and content encoding handling with bomb protection. The frontend is organized around per-app provider forms, a universal provider panel, and settings pages for proxy, MCP, skills, and usage. Key features include: 50+ provider presets for third-party API relay services, one-click provider switching with live config backup/restore, a local proxy with auto-failover and circuit breaker, session history browsing across supported apps, skills installation from GitHub repos, prompt management with per-app sync, and usage statistics with custom pricing. The application supports i18n (English, Japanese, Chinese) and runs on Windows, macOS, and Linux.
The LLM identified 20 files worth highlighting for reuse:
Generic SSE (Server-Sent Events) parsing utilities including strip_sse_field, take_sse_block, and append_utf8_safe for stream-safe UTF-8 handling. These functions are isolated, well-tested, and can be reused in any project that needs to parse SSE streams from HTTP responses.
Deterministic JSON canonicalization for generating consistent SHA-256 hashes of JSON payloads. Used for cache key generation in the proxy. The implementation handles key sorting, value normalization, and nested structures. Reusable in any caching or deduplication system.
Manual decompression of HTTP response bodies supporting gzip, deflate, br (Brotli), and zstd with configurable size limits to prevent decompression bombs. Demonstrates non-obvious skill in handling streaming decompression safely. Reusable in any HTTP client or proxy that needs to handle compressed responses.
Circuit breaker implementation for the proxy that tracks consecutive failures and opens the circuit to fail fast. Includes configurable thresholds, half-open state, and automatic recovery. Reusable in any service that needs to protect against cascading failures.
Injects cache_control breakpoints into Anthropic API requests to enable prompt caching. Parses the request body, identifies system messages and tool definitions, and inserts cache_control markers. Demonstrates deep understanding of the Anthropic API protocol. Reusable for any proxy that needs to optimize API usage.
Optimizes the thinking budget for AI models by adjusting budget_tokens based on model capabilities (adaptive vs legacy). Handles model-specific behavior and ensures budget is within valid ranges. Demonstrates non-obvious skill in managing model-specific parameters. Reusable in any proxy that needs to optimize thinking budgets.
Converts JSON Schema to Gemini's restricted Schema format, handling field compatibility and falling back to parametersJsonSchema for unsupported features. Includes Vertex AI compatibility fixes. Demonstrates deep understanding of API schema differences. Reusable for any API gateway that needs to translate between schema formats.
Thread-safe bounded store for replaying assistant turns and tool call metadata (thought signatures) in Gemini streaming responses. Uses RwLock with poison recovery. Reusable pattern for any system that needs to buffer and replay streaming data with bounded memory.
Transport helpers for converting reasoning items between Anthropic Messages and OpenAI Responses protocols. Handles content block conversion and streaming event mapping. Demonstrates non-obvious skill in protocol bridging. Reusable for any proxy that needs to translate between different AI API formats.
Usage cost calculator with Decimal precision for tracking token usage and costs across multiple AI providers. Handles per-model pricing, cache hit/miss differentiation, and multiple currency units. Reusable for any billing or usage tracking system.
Comprehensive frontend logger with multi-layer secret redaction (URL params, named credentials, opaque token shapes, JSON property-level) and bounded output size. Demonstrates non-obvious skill in secure logging. Reusable in any frontend application that needs to log errors without leaking secrets.
Heuristics for classifying deep link import risks: endpoint risk (private IP ranges, cloud metadata), command risk (shell interpreters, dangerous commands), and env key risk (sensitive environment variables). Reusable for any import/export security system.
Serializes writes to whole-file configs to avoid overwrites by running actions sequentially with a mutex. Reusable for any file-based config management that needs to prevent race conditions.
Generic React hook for subscribing to Tauri events with automatic cleanup on unmount. Reusable in any Tauri application that needs to listen for backend events.
React hook that keeps the last valid value of a state variable, useful for preserving content during dialog close transitions. Reusable for any modal with transient state.
React hook that returns a debounced version of a value, useful for search inputs. Reusable in any React application.
React hook integrating @dnd-kit for drag-and-drop sorting with automatic sortIndex updates and tray menu refresh. Reusable for any sortable list UI.
Shared React hook for managing OAuth device code flows (Codex, xAI, Copilot). Handles polling, token storage, and error handling. Reusable pattern for any OAuth device code implementation.
React Query hook with keep-last-good pattern for subscription data: transient errors show last successful value within a time window, deterministic errors immediately surface and clear cache. Reusable for any data that should degrade gracefully.
React hook for validating TOML configuration using smol-toml, with error parsing and field-level error mapping. Reusable for any TOML-based form validation.