Skip to content

Docker containers for Claude Code Typescript and Python SDKs with built-in authentication support for Claude Pro and Max plans

License

Notifications You must be signed in to change notification settings

cabinlab/claude-code-sdk-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Claude Code SDKs in Docker

Discord Build and Publish

Docker images with Official Claude Code SDK built-in.

Images:

  • TypeScript (607MB) - SDK and CLI are already included in the standard @anthropic-ai/claude-code package on NPM.
  • 🐍 Python (693MB) - adds Python 3 and Anthropic's claude-code-sdk-python aka claude-code-sdk on PyPI.
  • πŸ”οΈ Alpine TypeScript (383MB) - Minimal Alpine Linux base
  • πŸ”οΈ Alpine Python (474MB) - Alpine with Python support

Why use these images?

βœ… Claude Pro and Max subscription compatibility

Problem: As of July, 2025, the Claude Code SDKs use the CLI OAuth flow, which is clunky inside a container.

Solution: These containers replace the CLI authentication with Long-lived access tokens. See: claude setup-token --help

Available Images

Debian-based:

  • ghcr.io/cabinlab/claude-code-sdk:typescript - CLI + TypeScript SDK
  • ghcr.io/cabinlab/claude-code-sdk:python - Above + Python SDK

Alpine-based:

  • ghcr.io/cabinlab/claude-code-sdk:alpine - Minimal TypeScript
  • ghcr.io/cabinlab/claude-code-sdk:alpine-python - Minimal + Python

Quick Start (for Claude Pro and Max users)

  1. Get your OAuth token (on host machine):

    claude setup-token
    # Follow Anthropic's 2 or 3 screens of auth flow CLI --> Browser --> CLI
    # Copy the token that starts with "sk-ant-oat01-"
  2. Set environment variable:

    RECOMMENDED:

    export CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-your-token-here

    ALTERNATE:

    # Copy .env.example to .env
    cp .env.example .env
    # Edit .env and update this line with your actual token
    CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-your-token-here
  3. Start the containers:

    # Start containers (automatically uses .env file)
    docker compose up -d
  4. Test it works:

    # TypeScript (using compose.yaml)
    docker compose exec typescript node /app/scripts/test-auth.js
    
    # Python (using compose-python.yaml)
    docker compose -f compose-python.yaml exec python python /app/scripts/test_auth.py

Using Docker Compose (Full Examples)

Note: This project includes compose files for different variants:

  • compose.yaml - Debian TypeScript
  • compose-python.yaml - Debian Python
  • compose-alpine.yaml - Alpine TypeScript
  • compose-alpine-python.yaml - Alpine Python

Option 1: Run TypeScript

# Start TypeScript container
docker compose up -d

# Run TypeScript example
docker compose exec typescript tsx /app/examples/typescript/hello.ts

# Interactive TypeScript development
docker compose exec typescript bash

Option 2: Run Python (Includes Typescript!)

# Start Python container
docker compose -f compose-python.yaml up -d

# Run Python example
docker compose -f compose-python.yaml exec python python /app/examples/python/hello.py

# Interactive Python development
docker compose -f compose-python.yaml exec python python

# Tip: If you only use Python, rename the file for convenience
mv compose-python.yaml compose.yaml

Using Docker Run

For users who prefer direct docker commands:

# TypeScript
docker run --rm -it \
  -e CLAUDE_CODE_OAUTH_TOKEN="sk-ant-oat01-..." \
  -v $(pwd):/app \
  -p 3000:3000 \
  ghcr.io/cabinlab/claude-code-sdk:typescript \
  bash

# Python
docker run --rm -it \
  -e CLAUDE_CODE_OAUTH_TOKEN="sk-ant-oat01-..." \
  -v $(pwd):/app \
  -p 3000:3000 \
  ghcr.io/cabinlab/claude-code-sdk:python \
  python

Features

Included Tools

Base (CLI + Typescript SDK)

  • Non-root user - Security best practice
  • Claude Code CLI - Familiar Claude Code CLI and auth flow
  • TypeScript SDK - Native TypeScript/JavaScript support
  • tsx - Run TypeScript files directly without compilation
  • Git, cURL, jq - Essential development tools

Python

  • Python SDK - Python bindings (in :python image)

Claude Config Scaffolding

Each container includes a .claude/ directory with:

  • Slash Commands - Directory and instructions for extending Claude Code with custom commands
  • Hooks - Directory and instructions to leverage Claude's behavior
  • Example configurations and documentation

Mount your own configuration:

docker run -v ~/.claude:/home/claude/.claude ...

Authentication

Which method should I use?

Claude Pro/Max users

  • Long-lived tokens [Recommended] β†’ See Quick Start above
  • Session based tokens - This is the standard Claude Code auth flow

Anthropic API Keys

  • Anthropic API keys β†’ Set ANTHROPIC_API_KEY in your .env file
  • Can also be used through standard Claude Code auth flow
  • ⚠️ Likely overrides OAuth/Subscription plan settings
  • βœ… Use API OR Subscription, not both together

For technical details and troubleshooting, see our Authentication Guide.

Building Your Own Images

Extending the Base Images (click to expand)

For TypeScript Projects

# For TypeScript projects
FROM ghcr.io/cabinlab/claude-code-sdk:typescript

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npm", "start"]

For Python Projects

# For Python projects
FROM ghcr.io/cabinlab/claude-code-sdk:python

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "main.py"]

Building Locally

# Build TypeScript base
docker build -f Dockerfile.typescript -t claude-code-sdk:typescript .

# Build Python extension
docker build --build-arg BASE_IMAGE=claude-code-sdk:typescript \
  -t claude-code-sdk:python .

Security

  • Containers run as non-root user claude
  • OAuth tokens should never be built into images
  • Use .aiexclude to prevent Claude from accessing sensitive files
  • Mount secrets at runtime, don't embed them

Examples

See the examples/ directory for sample code in:

  • JavaScript
  • TypeScript (with direct execution via tsx)
  • Python

Automatic Updates

This repository automatically checks for new SDK versions daily and creates pull requests when updates are available. The automated workflow:

  • Runs daily at 2 AM UTC
  • Checks npm for Claude Code CLI updates
  • Checks PyPI for Python SDK updates
  • Creates PRs with updated versions
  • Auto-merges PRs after tests pass

Manual version checks can be triggered via the "Check for Updates" workflow in the Actions tab.

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

MIT License - see LICENSE file for details

About

Docker containers for Claude Code Typescript and Python SDKs with built-in authentication support for Claude Pro and Max plans

Topics

Resources

License

Stars

Watchers

Forks

Packages