Yash030 Claude Opus 4.7 commited on
Commit
0015069
Β·
1 Parent(s): f69902b

Update CLAUDE.md with admin dashboard docs

Browse files

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (1) hide show
  1. CLAUDE.md +75 -0
CLAUDE.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Overview
6
+
7
+ 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.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ uv run ruff format # Format code
13
+ uv run ruff check # Lint code
14
+ uv run ty check # Type check
15
+ uv run pytest # Run tests (use -n auto for parallel)
16
+ uv run pytest tests/path/test.py::test_name # Run single test
17
+
18
+ # Run the proxy
19
+ uv run uvicorn server:app --host 0.0.0.0 --port 8082
20
+
21
+ # Or via installed scripts (after uv tool install)
22
+ free-claude-code # Start proxy with configured host/port
23
+ fcc-init # Create user config template at ~/.config/free-claude-code/.env
24
+ ```
25
+
26
+ Run format β†’ lint β†’ type check in that order before pushing. CI enforces the same sequence.
27
+
28
+ ## Architecture
29
+
30
+ ### Request Flow
31
+ ```
32
+ Claude Code CLI β†’ api/routes.py (FastAPI) β†’ api/model_router.py β†’ providers/* β†’ upstream
33
+ ↓
34
+ core/chain_engine.py (sticky sessions)
35
+ ```
36
+
37
+ ### Key Modules
38
+
39
+ - **api/routes.py** β€” FastAPI route handlers for `/v1/messages`, `/v1/models`, `/v1/messages/counttokens`
40
+ - **api/admin.py** β€” Admin dashboard endpoints: `GET /admin` (HTML), `GET /api/admin/sessions` (JSON)
41
+ - **api/services.py** β€” Sticky session logic: once a model yields first event (including thinking blocks), it stays committed for that turn
42
+ - **api/model_router.py** β€” Resolves Claude model names to provider/model pairs using MODEL_OPUS/MODEL_SONNET/MODEL_HAIKU/MODEL env vars
43
+ - **api/gateway_model_ids.py** β€” Gateway model ID mapping for picker integration and "(no thinking)" variants
44
+ - **api/detection.py** β€” Request type detection for optimization routing
45
+ - **api/optimization_handlers.py** β€” Handles local optimization for trivial requests (health probes, capability checks)
46
+ - **api/dependencies.py** β€” Dependency injection for providers, settings, and request validation
47
+ - **api/web_server_tools.py** β€” Web fetch/search tool implementations for Claude Code server tools
48
+ - **providers/registry.py** β€” Provider factory and caching; builds ProviderConfig from settings, creates provider instances
49
+ - **providers/base.py** β€” Abstract `BaseProvider` interface; `stream_response()` yields Anthropic SSE
50
+ - **providers/openai_compat.py** β€” OpenAI chat β†’ Anthropic SSE translation for NVIDIA NIM
51
+ - **providers/nvidia_nim/** β€” NVIDIA NIM-specific transport implementation
52
+ - **providers/zen/** β€” Zen (opencode.ai) native transport implementation
53
+ - **core/chain_engine.py** β€” Orchestrates multi-provider fallback chains
54
+ - **core/task_detector.py** β€” Detects trivial requests for local optimization
55
+ - **core/session_tracker.py** β€” Tracks active sessions and request state
56
+ - **core/model_capabilities.py** β€” Model capability detection and feature routing
57
+ - **messaging/** β€” Discord/Telegram bot wrappers for remote Claude Code sessions
58
+
59
+ ### Provider Model Format
60
+ Model values use `provider_id/model/name` format (e.g., `nvidia_nim/z-ai/glm4.7` or `zen/minimax-m2.5-free`).
61
+
62
+ ### Multi-Model Advertisement
63
+ `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.
64
+
65
+ ## Python 3.14 Notes
66
+
67
+ The `except X, Y:` syntax is valid in Python 3.14 (reintroduced). PyUpgrade is configured for py314, so don't modernize this syntax away.
68
+
69
+ ## Environment Configuration
70
+
71
+ Settings are loaded via pydantic-settings from `.env`. Key variables:
72
+ - `MODEL` β€” Comma-separated fallback model list (e.g., `zen/minimax-m2.5-free,nvidia_nim/z-ai/glm4.7`)
73
+ - `MODEL_OPUS`, `MODEL_SONNET`, `MODEL_HAIKU` β€” Per-tier overrides
74
+ - `ANTHROPIC_AUTH_TOKEN` β€” Must match value sent by Claude Code client
75
+ - Provider API keys: `NVIDIA_NIM_API_KEY`, `ZEN_API_KEY`