- Home
- Claude Code Proxy
- deployment
- Binary Packaging
Binary Packaging
Overview
Section titled “Overview”PyInstaller bundles the proxy and all its dependencies into a standalone executable that runs without a Python installation on the target system.
Two output formats are available:
| Format | Output | Size |
|---|---|---|
| Directory | dist/claude-code-proxy/ (executable + _internal/ folder) | ~55 MB |
| Single file | dist/claude-code-proxy-single | ~24 MB |
Prerequisites
Section titled “Prerequisites”Install PyInstaller as a dev dependency:
uv add --dev pyinstallerBuilding
Section titled “Building”Directory Version (development / testing)
Section titled “Directory Version (development / testing)”uv run pyinstaller claude-proxy.specSingle-file Version (deployment)
Section titled “Single-file Version (deployment)”uv run pyinstaller --onefile --name claude-code-proxy-single src/main.pyCustom Configuration
Section titled “Custom Configuration”# Include specific hidden importsuv run pyinstaller --onefile --hidden-import=src.api.endpoints src/main.py
# Include data filesuv run pyinstaller --onefile --add-data="src:src" src/main.pyPyInstaller Spec File
Section titled “PyInstaller Spec File”The claude-proxy.spec file controls the build. Key settings:
a = Analysis( ['src/main.py'], # Entry point pathex=['.'], # Module search path datas=[('src', 'src')], # Data files to bundle hiddenimports=[ 'src.api.endpoints', 'src.core.config', 'src.core.client', 'uvicorn.logging', 'uvicorn.loops.auto', 'fastapi.openapi.utils', 'pydantic.v1', ],)If you see ModuleNotFoundError at runtime, add the missing module to
hiddenimports and rebuild.
Cross-Platform Notes
Section titled “Cross-Platform Notes”PyInstaller produces a native binary for the platform it runs on. You must build on the target OS.
| Platform | Command | Output |
|---|---|---|
| Linux | uv run pyinstaller --onefile src/main.py | ELF executable |
| Windows | pyinstaller --onefile src/main.py | .exe |
| macOS | pyinstaller --onefile src/main.py | Mach-O executable |
Running the Binary
Section titled “Running the Binary”# Directory version./dist/claude-code-proxy/claude-code-proxy
# Single-file version./dist/claude-code-proxy-singlePass configuration through environment variables (see Configuration Reference):
OPENAI_API_KEY="sk-your-key" ./dist/claude-code-proxy-singlesystemd Service
Section titled “systemd Service”Create a unit file for production deployments:
[Unit]Description=Claude Code ProxyAfter=network.target
[Service]Type=simpleUser=www-dataWorkingDirectory=/opt/claude-proxyEnvironmentFile=/opt/claude-proxy/.envExecStart=/opt/claude-proxy/claude-code-proxy-singleRestart=alwaysRestartSec=5
[Install]WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reloadsudo systemctl enable --now claude-proxyManage the service:
sudo systemctl status claude-proxysudo systemctl restart claude-proxyjournalctl -u claude-proxy -fDocker Binary Deployment
Section titled “Docker Binary Deployment”For minimal container images, copy just the binary into an Alpine image:
FROM alpine:latestRUN apk add --no-cache libstdc++COPY claude-code-proxy-single /usr/local/bin/claude-code-proxyEXPOSE 8082CMD ["claude-code-proxy"]Performance Optimization
Section titled “Performance Optimization”Reducing Binary Size
Section titled “Reducing Binary Size”- UPX compression (cross-platform):
Terminal window pyinstaller --onefile --upx-dir=/path/to/upx src/main.py - Remove unused dependencies from
requirements.txtbefore building. - Use
--excludeto skip large modules you do not need.
Faster Startup
Section titled “Faster Startup”export PYTHONOPTIMIZE=2export PYTHONDONTWRITEBYTECODE=1Version Management and Rollback
Section titled “Version Management and Rollback”Always keep a backup of the previous binary before deploying a new one:
# Backup before deployingcp claude-code-proxy-single claude-code-proxy-single.bak
# Rollback if neededmv claude-code-proxy-single.bak claude-code-proxy-singlesudo systemctl restart claude-proxyA typical update cycle:
- Build the new binary on your build machine.
- Copy it to the server alongside the running version.
- Stop the service, swap the binary, start the service.
- Verify with
curl http://localhost:8082/health.