2025-11-19 12:41:53 +08:00

3.3 KiB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Development Commands

Frontend Development

  • pnpm dev - Start development mode with hot reload
  • pnpm build - Build the application for production
  • pnpm typecheck - Run TypeScript type checking
  • pnpm format - Format code with Prettier
  • pnpm format:check - Check code formatting without making changes

Backend Development (Rust)

  • cd src-tauri && cargo fmt - Format Rust code
  • cd src-tauri && cargo clippy - Run Rust linter/analyzer
  • cd src-tauri && cargo test - Run Rust tests

Build Commands

  • pnpm tauri build - Build production application bundle
  • pnpm tauri build --debug - Build debug version

Architecture Overview

This is a Tauri 2.0 desktop application that manages Claude Code and Codex provider configurations. The application uses a hybrid architecture:

Frontend (React + TypeScript)

  • Location: src/ directory
  • Framework: React 18 with TypeScript, Vite build system, TailwindCSS 4.x
  • Key Components:
    • App.tsx - Main application component with routing logic
    • components/ - UI components including modals, forms, and provider management
    • lib/tauri-api.ts - Centralized API layer for all Tauri command calls
    • types.ts - TypeScript type definitions for Provider, Settings, etc.

Backend (Rust)

  • Location: src-tauri/src/ directory
  • Key Modules:
    • lib.rs - Main entry point, tray menu system, and application setup
    • commands.rs - Tauri command handlers (API endpoints)
    • config.rs - Configuration file management (reads/writes JSON configs)
    • provider.rs - Provider management logic and switching operations
    • store.rs - Application state management with Mutex protection
    • migration.rs - Handles migration from legacy configurations
    • vscode.rs - VS Code integration for automatic config sync

Data Flow Architecture

The application follows a Single Source of Truth (SSOT) pattern:

  1. Centralized Config: All provider data stored in ~/.cc-switch/config.json
  2. Live Config Files:
    • Claude Code: ~/.claude/settings.json
    • Codex: ~/.codex/auth.json + ~/.codex/config.toml
  3. Switching Process: Copy from centralized config → live config files
  4. Atomic Operations: Uses atomic writes with rollback for configuration safety

System Integration

  • System Tray: Dynamic menus that reflect current provider states
  • VS Code Integration: Automatic sync with VS Code Codex plugin settings
  • Cross-Platform: Windows (MSI installer), macOS (app bundle), Linux (deb/AppImage)
  • Updates: Built-in updater system for automatic application updates

State Management

  • Frontend: React hooks and context for UI state
  • Backend: AppState struct with Mutex-protected shared state
  • IPC: Tauri commands for frontend-backend communication
  • Events: Event system for real-time updates (provider switching, etc.)

Project Structure Notes

  • Configuration presets are defined in src/config/providerPresets.ts and src/config/codexProviderPresets.ts
  • The application supports both portable and installed modes
  • Icons and assets are stored in src-tauri/icons/ with platform-specific variants
  • The build system uses Vite with React plugin and TailwindCSS integration