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.

Quick Start

Backend

pip install -e .
claude-code-server --working-dir /path/to/project --port 8333

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="/agent")

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

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

<Chat
  apiBase="/api/agent"
  uploadUrl="/api/agent/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/agent',
  uploadUrl: '/api/agent/upload',
})

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

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.0.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.0-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_code_server-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 c215d260e8730fea2db5385d707c664d4a1cb1ad64e1fd92ac9823b575a6de00
MD5 8fc668cdc903a7bf658d250e7368424d
BLAKE2b-256 1546f90ac4977f2d660369a7a7285e3cbb21dca709d68281e46aa154e5181274

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude_code_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98e90f521d0de9ff97888b3b28bf442121109ee564b966aa5c3be94a2ea10aff
MD5 51cc5468f30bb2e70a758db6ac58e7f8
BLAKE2b-256 f199069d787af51c31a7f78898d60d7fb3a93e875079dc71d4037a178c2f96bf

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