Skip to main content

Claude Code CLI wrapped as HTTP SSE server — reusable backend for any project

Project description

claude-code-server

Claude Code CLI wrapped as HTTP SSE server + reusable React chat UI.

Install

pip install claude-code-server

Quick Start

claude-code-server --working-dir /path/to/project --port 8333
# Open http://localhost:8333 for the Web UI
# API available at http://localhost:8333/api/*

Embed in existing FastAPI app

from claude_code_server import create_router, AgentConfig

router = create_router(AgentConfig(working_dir="/path/to/project"))
app.include_router(router, prefix="/api")

Dynamic config per request

from claude_code_server import create_router, AgentConfig, ChatRequest

def config_factory(req: ChatRequest) -> AgentConfig:
    return AgentConfig(
        working_dir="/path/to/project",
        system_prompt="You are a helpful assistant for ...",
        env={"MY_VAR": "value"},
    )

router = create_router(config_factory=config_factory)

Frontend component library (npm)

npm install claude-code-chat
import { Chat } from 'claude-code-chat'

<Chat
  apiBase="/api"
  uploadUrl="/api/upload"
  getHeaders={() => ({ Authorization: `Bearer ${token}` })}
  slashCommands={[
    { name: 'status', description: 'Check status', type: 'prompt', prompt: 'Show status' },
  ]}
/>

Or use individual components:

import { useChat, ChatMessages, ChatInput } from 'claude-code-chat'

const { messages, send, cancel, isLoading, costInfo, uploadFile } = useChat({
  apiBase: '/api',
  uploadUrl: '/api/upload',
})

<ChatMessages messages={messages} isLoading={isLoading} costInfo={costInfo} />
<ChatInput onSend={send} isLoading={isLoading} onCancel={cancel} onUploadFile={uploadFile} />

Note: Import the bundled CSS in your app entry:

import 'claude-code-chat/style.css'

SSE Event Protocol

Event Data Description
session {session_id} Session created/resumed
text {content} Text delta
thinking {content} Thinking delta
tool_call {id, name, arguments} Tool invocation
tool_result {id, name, result, is_error} Tool result
done {cost, duration_ms} Turn complete
error {message} Error

API

Backend

  • ClaudeAgent — Core agent class
  • AgentConfig — Configuration (working_dir, system_prompt, env, max_turns, ...)
  • ChatRequest — Request model (prompt, session_id)
  • create_router(config?, config_factory?) — FastAPI router factory
  • create_app(config?) — Standalone FastAPI app

Frontend

  • <Chat> — Complete chat page (drop-in)
  • <ChatMessages> — Message renderer
  • <ChatInput> — Input with slash commands + file upload
  • useChat(config) — SSE streaming hook
  • useChatStore — Zustand store

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_code_server-0.1.1.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_code_server-0.1.1-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file claude_code_server-0.1.1.tar.gz.

File metadata

  • Download URL: claude_code_server-0.1.1.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for claude_code_server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f2e1e78b5612f3cf2d6e11cc120d0bce5f710ac33ef7b098c6370ca99e1511c
MD5 7d791bda6fd7905001c5d61bfbe364a4
BLAKE2b-256 28463b704cf78ba622b3acf1ff77c409a6a30c942b9603084c8e562ede2d940d

See more details on using hashes here.

File details

Details for the file claude_code_server-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_code_server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 134e5d30dc92855a300ef9d69cff378712706a92adfb4ae4548fb06dce364ce3
MD5 384a89ad5f2af23a87731b65343db690
BLAKE2b-256 a676c93525f64374a0360ac2bcfd1a36bad3027c3ada09d8a80639dc38f7be16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page