Spaces:
Running
Running
Update CLAUDE.md with admin dashboard docs
Browse filesCo-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Overview
Free Claude Code is a FastAPI proxy that routes Claude Code's Anthropic Messages API calls to backend providers (NVIDIA NIM, Zen). It translates between client-side Anthropic protocol and provider-specific transports (OpenAI chat format, native APIs), handling SSE streaming, thinking blocks, tool calls, and token usage metadata normalization.
## Commands
```bashuv run ruff format # Format codeuv run ruff check # Lint codeuv run ty check # Type checkuv run pytest # Run tests (use -n auto for parallel)uv run pytest tests/path/test.py::test_name # Run single test
# Run the proxyuv run uvicorn server:app --host 0.0.0.0 --port 8082
# Or via installed scripts (after uv tool install)free-claude-code # Start proxy with configured host/portfcc-init # Create user config template at ~/.config/free-claude-code/.env```
Run format β lint β type check in that order before pushing. CI enforces the same sequence.
## Architecture
### Request Flow```Claude Code CLI β api/routes.py (FastAPI) β api/model_router.py β providers/* β upstream β core/chain_engine.py (sticky sessions)```
### Key Modules
- **api/routes.py** β FastAPI route handlers for `/v1/messages`, `/v1/models`, `/v1/messages/counttokens`- **api/admin.py** β Admin dashboard endpoints: `GET /admin` (HTML), `GET /api/admin/sessions` (JSON)- **api/services.py** β Sticky session logic: once a model yields first event (including thinking blocks), it stays committed for that turn- **api/model_router.py** β Resolves Claude model names to provider/model pairs using MODEL_OPUS/MODEL_SONNET/MODEL_HAIKU/MODEL env vars- **api/gateway_model_ids.py** β Gateway model ID mapping for picker integration and "(no thinking)" variants- **api/detection.py** β Request type detection for optimization routing- **api/optimization_handlers.py** β Handles local optimization for trivial requests (health probes, capability checks)- **api/dependencies.py** β Dependency injection for providers, settings, and request validation- **api/web_server_tools.py** β Web fetch/search tool implementations for Claude Code server tools- **providers/registry.py** β Provider factory and caching; builds ProviderConfig from settings, creates provider instances- **providers/base.py** β Abstract `BaseProvider` interface; `stream_response()` yields Anthropic SSE- **providers/openai_compat.py** β OpenAI chat β Anthropic SSE translation for NVIDIA NIM- **providers/nvidia_nim/** β NVIDIA NIM-specific transport implementation- **providers/zen/** β Zen (opencode.ai) native transport implementation- **core/chain_engine.py** β Orchestrates multi-provider fallback chains- **core/task_detector.py** β Detects trivial requests for local optimization- **core/session_tracker.py** β Tracks active sessions and request state- **core/model_capabilities.py** β Model capability detection and feature routing- **messaging/** β Discord/Telegram bot wrappers for remote Claude Code sessions
### Provider Model FormatModel values use `provider_id/model/name` format (e.g., `nvidia_nim/z-ai/glm4.7` or `zen/minimax-m2.5-free`).
### Multi-Model Advertisement`MODEL` env var accepts comma-separated list to force the Claude CLI to display all models. Each registered model appears in the `/model` picker. Picker-safe IDs include "(no thinking)" variants that route to the same upstream model while disabling thinking blocks.
## Python 3.14 Notes
The `except X, Y:` syntax is valid in Python 3.14 (reintroduced). PyUpgrade is configured for py314, so don't modernize this syntax away.
## Environment Configuration
Settings are loaded via pydantic-settings from `.env`. Key variables:- `MODEL` β Comma-separated fallback model list (e.g., `zen/minimax-m2.5-free,nvidia_nim/z-ai/glm4.7`)- `MODEL_OPUS`, `MODEL_SONNET`, `MODEL_HAIKU` β Per-tier overrides- `ANTHROPIC_AUTH_TOKEN` β Must match value sent by Claude Code client- Provider API keys: `NVIDIA_NIM_API_KEY`, `ZEN_API_KEY`CLAUDE.mdAdded+75