Skip to content

Latest commit

 

History

History
159 lines (114 loc) · 3.23 KB

File metadata and controls

159 lines (114 loc) · 3.23 KB

한국어 | English

📢 Notice: This project has been integrated into https://github.com/chahero/code-agent-api-wrapper.

Claude Code API Wrapper

A project that wraps Claude Code CLI as a REST API.

Use Claude Code with your Claude Pro/Max subscription and call it as an API without additional API charges.

Prerequisites

  • Python 3.10+
  • Claude Code CLI installed and authenticated
  • Claude Pro or Max subscription

Installation

# Clone repository
git clone https://github.com/your-username/claude-code-api-wrapper.git
cd claude-code-api-wrapper

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install dependencies
pip install fastapi uvicorn python-dotenv requests

Configuration

# Create environment file
cp .env.example .env

Edit .env file:

PORT=5000
HOST=0.0.0.0

Run

python main.py

Once the server starts:

Web UI Features

Web UI Screenshot

Key Features

  • Multi-line Input: Press Shift+Enter for new line, Enter to send
  • API URL Management: Save and switch between multiple API URLs from the header dropdown
  • Chat History: All conversations are automatically saved, up to 20 sessions stored
    • Click saved chat to restore
    • Delete individual or all history
  • Resizable Chat Window: Drag the divider between messages and examples to adjust height
  • Mobile Responsive: Works perfectly on mobile and tablet devices
  • Auto-save: Messages are automatically saved to browser storage

API Usage

Endpoints

Method Path Description
POST /ask Ask Claude
GET /health Health check
GET / Web UI

POST /ask

Request:

{
  "prompt": "Hello, Claude!",
  "working_directory": null
}

Response:

{
  "success": true,
  "response": "Hello! How can I help you today?",
  "error": null
}

Specify Working Directory

To ask questions with context from a specific folder:

{
  "prompt": "Analyze the files in this folder",
  "working_directory": "C:\\my_project"
}

cURL Example

curl -X POST "http://localhost:5000/ask" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Say hello in Korean"}'

Client Examples

Python CLI

CLI Screenshot

cd examples

# Single question
python cli_example.py "What is Python?"

# Interactive mode
python cli_example.py -i

Web UI

Open http://localhost:5000 in your browser

Project Structure

claude-code-api-wrapper/
├── main.py              # FastAPI server
├── .env.example         # Environment variables example
├── .gitignore
├── README.md
└── examples/
    ├── cli_example.py   # CLI client example
    └── index.html       # Web UI

Notes

  • Claude Code CLI must be installed and authenticated.
  • This wrapper follows the usage limits of your Claude Pro/Max subscription.
  • Add proper authentication/authorization for production use.

License

MIT License