claude-code-adapter-fastapi

Claude Code Adapter FastAPI

中文 English

A lightweight proxy/adapter layer based on FastAPI: Converts Anthropic/Claude messages and tool call requests to OpenAI Chat Completions compatible format; intelligently selects tool definition handling strategy (system prompt vs. user message) to optimize performance and functionality; supports optional automatic tool selection, SSE streaming forwarding, and response conversion back to Anthropic format. Provides server-side proxying without modifying client SDKs.

🎯 Project Overview

Key features include:

🚀 Quick Start

One-Click Setup

# Clone the repository
git clone https://github.com/wangfumin1/claude-code-adapter-fastapi.git
cd claude-code-adapter-fastapi

# Use platform-specific scripts
# Windows:
scripts\setup.bat
# Linux/macOS:
./scripts/setup.sh

Start the Service

# Using Makefile
make run

# Or run directly
python -m uvicorn src.claude_code_adapter.app:app --host 0.0.0.0 --port 8000

Verify Installation

Visit http://localhost:8000/docs to view the API documentation.

📖 Detailed Documentation

💡 Tip: We recommend reading the documentation in order, starting with the Quick Start Guide.

🔧 How It Works

graph TD
    A[Client Request] --> B[Receive Anthropic Format]
    B --> C[Convert Tool Definitions]
    C --> D[Build System Prompt or User Message]
    D --> E[Convert Message Format]
    E --> F[Forward to Target Service]
    F --> G[Receive Response]
    G --> H[Parse Tool Calls]
    H --> I[Convert Back to Anthropic Format]
    I --> J[Return to Client]

💡 Use Cases

🛠️ Technology Stack