A DDEV addon that integrates Claude Code CLI into your DDEV environment.
- Installs Claude Code CLI, GitHub CLI (
gh), and ccusage in the DDEV web container - Mounts your host
~/.claudeand~/.config/ghdirectories into the container - Injects
GH_TOKENandCLAUDE_CODE_OAUTH_TOKENvia a pre-start hook - Provides
ddev claudeandddev claude-autocommands
ddev add-on get jamespublishlab/ddev-claude-code
ddev restart- DDEV >= v1.23.0
- Claude Code installed on your host (
npm install -g @anthropic-ai/claude-codeor viaclaude.ai/install.sh) - Run
claudeon your host at least once to initialize~/.claude - GitHub CLI (
gh) authenticated on your host (gh auth login)
# Run Claude Code interactively
ddev claude
# Run with arguments
ddev claude --help
ddev claude --version
# Run in autonomous mode (skips permission prompts)
ddev claude-auto "add unit tests for the auth module"ddev claude --version # Claude Code CLI version
ddev exec gh --version # GitHub CLI version
ddev exec 'echo $GH_TOKEN' # Confirm token injectionThe addon supports two authentication methods. The pre-start hook automatically captures tokens from your host and injects them into the container — no manual env var setup required.
Uses your Claude Pro/Max subscription allowance — no additional API costs.
-
Install Claude Code on your host:
npm install -g @anthropic-ai/claude-code
-
Run
claudeonce to authenticate:claude
This opens a browser window where you sign in with your Anthropic account. On completion, Claude saves your OAuth credentials (access token + refresh token) to
~/.claude/.credentials.json. -
Install the addon and restart:
ddev add-on get jamespublishlab/ddev-claude-code ddev restart
The pre-start hook reads the token from
~/.claude/.credentials.jsonand setsCLAUDE_CODE_OAUTH_TOKENin the container automatically.
Note: OAuth access tokens expire after ~1 hour. Because
~/.claudeis volume-mounted into the container, Claude Code can auto-refresh using the refresh token stored in~/.claude/.credentials.json. If you experience auth failures during long sessions, runddev restartto re-capture a fresh token.
Uses per-token API billing — simpler but costs more than a subscription.
-
Get an API key from console.anthropic.com
-
Add it to
.ddev/.env.tokens:echo "ANTHROPIC_API_KEY=sk-ant-api03-..." >> .ddev/.env.tokens
Do not set both
ANTHROPIC_API_KEYandCLAUDE_CODE_OAUTH_TOKEN— they conflict and Claude will throw an auth error. -
Restart:
ddev restart
The addon also captures your host's gh auth token for GitHub integration. Authenticate on your host first:
gh auth loginddev exec 'echo $CLAUDE_CODE_OAUTH_TOKEN' # Should show your OAuth token
ddev exec 'echo $GH_TOKEN' # Should show your GitHub token
ddev claude --version # Should print version without auth errors- Pre-start hook (
config.claude-code.yaml): Captures your host'sgh auth tokenand Claude OAuth token into.ddev/.env.tokens - Docker Compose overlay (
docker-compose.claude-code.yaml): Mounts~/.claudeand~/.config/ghinto the container and loads.env.tokens - Dockerfile (
web-build/Dockerfile.claude-code): Installsgh,claude, andccusagein the web container
| File | Type | Purpose |
|---|---|---|
docker-compose.claude-code.yaml |
Project | Volume mounts + env_file |
config.claude-code.yaml |
Project | Pre-start hook for token capture |
web-build/Dockerfile.claude-code |
Project | Installs CLI tools |
commands/web/claude |
Global | ddev claude command |
commands/web/claude-auto |
Global | ddev claude-auto command |
ddev add-on remove claude-code
ddev restartMIT