From 7c14a75afcd84dbebfc17f1e147c7b4437f73a8c Mon Sep 17 00:00:00 2001 From: Vishal Jain Date: Thu, 12 Jun 2025 11:10:32 +0100 Subject: [PATCH] Fix Docker startup issues - Change executable from claude-code to claude in startup.sh - Fix .env parsing to handle comments using set -a/source - Add explicit PATH for npm global binaries in Dockerfile - Update scratchpad.md with fix documentation --- .env.example | 15 ++++++++------- Dockerfile | 5 ++++- README.md | 13 +++++++++---- config/mcp-config.json | 18 ++++++++++-------- scratchpad.md | 10 ++++++++-- scripts/install.sh | 13 +++++++------ scripts/startup.sh | 22 +++++++++++----------- 7 files changed, 57 insertions(+), 39 deletions(-) diff --git a/.env.example b/.env.example index 993fbef..5ae32b7 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,12 @@ # ABOUTME: Environment variables for Claude Docker # ABOUTME: Copy this to ~/.claude-docker/.env and fill in your values -# Anthropic API key for Claude Code -ANTHROPIC_API_KEY=your_anthropic_api_key_here +# Optional: Anthropic API key (only needed if not using subscription auth) +# ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key_here -# Twilio credentials for SMS notifications -TWILIO_ACCOUNT_SID=your_twilio_account_sid -TWILIO_AUTH_TOKEN=your_twilio_auth_token -TWILIO_PHONE_NUMBER=+1234567890 # Your Twilio phone number -YOUR_PHONE_NUMBER=+1234567890 # Your personal phone to receive SMS \ No newline at end of file +# Optional: Twilio credentials for SMS notifications via MCP +# TWILIO_ACCOUNT_SID=your_twilio_sid_here +# TWILIO_API_KEY=your_twilio_api_key_here +# TWILIO_API_SECRET=your_twilio_api_secret_here +# TWILIO_FROM_NUMBER=+1234567890 # Your Twilio phone number +# TWILIO_TO_NUMBER=+1234567890 # Your personal phone to receive SMS \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9a4f66e..c3078ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,8 +17,11 @@ WORKDIR /app # Install Claude Code globally RUN npm install -g @anthropic-ai/claude-code +# Ensure npm global bin is in PATH +ENV PATH="/usr/local/bin:${PATH}" + # Install Twilio MCP server -RUN npm install -g @twilioalpha/mcp-server-twilio +RUN npm install -g @twilio-alpha/mcp # Create directories for configuration RUN mkdir -p /app/config /app/.claude diff --git a/README.md b/README.md index c3f46e0..8348967 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,20 @@ A Docker container setup for running Claude Code with full autonomous permission ```bash # Edit ~/.claude-docker/.env with your keys ANTHROPIC_API_KEY=your_anthropic_key + + # For Twilio MCP integration: TWILIO_ACCOUNT_SID=your_twilio_sid - TWILIO_AUTH_TOKEN=your_twilio_token + TWILIO_API_KEY=your_twilio_api_key + TWILIO_API_SECRET=your_twilio_api_secret TWILIO_FROM_NUMBER=your_twilio_number TWILIO_TO_NUMBER=your_phone_number ``` + + > **Note**: Twilio MCP requires API Key/Secret instead of Auth Token. Create API keys in your Twilio Console under Account → API keys & tokens. 3. **Use from any project directory:** ```bash - claude + claude-docker ``` ## Features @@ -89,8 +94,8 @@ The setup creates `~/.claude-docker/` with: ## Requirements - Docker installed and running -- Anthropic API key -- (Optional) Twilio account for SMS notifications +- Anthropic API key (or Claude subscription) +- (Optional) Twilio account with API Key/Secret for SMS notifications ## Next Steps diff --git a/config/mcp-config.json b/config/mcp-config.json index 03e6875..745d860 100644 --- a/config/mcp-config.json +++ b/config/mcp-config.json @@ -1,14 +1,16 @@ { "mcpServers": { "twilio": { - "command": "node", - "args": ["/usr/lib/node_modules/@twilioalpha/mcp-server-twilio/build/index.js"], - "env": { - "TWILIO_ACCOUNT_SID": "${TWILIO_ACCOUNT_SID}", - "TWILIO_AUTH_TOKEN": "${TWILIO_AUTH_TOKEN}", - "TWILIO_PHONE_NUMBER": "${TWILIO_PHONE_NUMBER}", - "YOUR_PHONE_NUMBER": "${YOUR_PHONE_NUMBER}" - } + "command": "npx", + "args": [ + "-y", + "@twilio-alpha/mcp", + "${TWILIO_ACCOUNT_SID}/${TWILIO_API_KEY}:${TWILIO_API_SECRET}", + "--services", + "twilio_api_v2010", + "--tags", + "Api20100401Message" + ] } } } \ No newline at end of file diff --git a/scratchpad.md b/scratchpad.md index cab5960..a33faa4 100644 --- a/scratchpad.md +++ b/scratchpad.md @@ -59,15 +59,21 @@ Building a Docker container that runs Claude Code with full autonomous permissio ## Notes & Context - Repository: https://github.com/VishalJ99/claude-docker - Using --dangerously-skip-permissions flag for full autonomy -- Twilio MCP server runs alongside Claude Code in container +- Twilio MCP server runs via Claude's MCP config (not as separate process) +- Uses @twilio-alpha/mcp package with API Key/Secret authentication - Container auto-removes on exit for clean state - Project directory mounted at /workspace - Need to research Claude dev container's init-firewall.sh implementation - Need to research their history persistence mechanism +- **Fixed startup issues (Dec 2024):** + - Changed executable from `claude-code` to `claude` in startup.sh + - Fixed .env parsing to handle comments properly using `set -a`/`source` + - Added explicit PATH for npm global binaries + - Maintained separation: `claude-docker` (host) vs `claude` (container) ## Quick References - Install: `./scripts/install.sh` -- Usage: `claude` (from any project directory) +- Usage: `claude-docker` (from any project directory) - Config: `~/.claude-docker/.env` - Repo: https://github.com/VishalJ99/claude-docker - Claude dev container: https://github.com/anthropics/claude-code/tree/main/.devcontainer \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh index 07cdbc5..e58cd2b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -16,15 +16,15 @@ if [ ! -f "$HOME/.claude-docker/.env" ]; then fi # Add alias to .zshrc -ALIAS_LINE="alias claude='$PROJECT_ROOT/scripts/claude-docker.sh'" +ALIAS_LINE="alias claude-docker='$PROJECT_ROOT/scripts/claude-docker.sh'" -if ! grep -q "alias claude=" "$HOME/.zshrc"; then +if ! grep -q "alias claude-docker=" "$HOME/.zshrc"; then echo "" >> "$HOME/.zshrc" echo "# Claude Docker alias" >> "$HOME/.zshrc" echo "$ALIAS_LINE" >> "$HOME/.zshrc" - echo "✓ Added 'claude' alias to .zshrc" + echo "✓ Added 'claude-docker' alias to .zshrc" else - echo "✓ Claude alias already exists in .zshrc" + echo "✓ Claude-docker alias already exists in .zshrc" fi # Make scripts executable @@ -35,6 +35,7 @@ echo "" echo "Installation complete! 🎉" echo "" echo "Next steps:" -echo "1. Edit $HOME/.claude-docker/.env with your API keys" +echo "1. (Optional) Edit $HOME/.claude-docker/.env with your API keys" echo "2. Run 'source ~/.zshrc' or start a new terminal" -echo "3. Navigate to any project and run 'claude' to start" \ No newline at end of file +echo "3. Navigate to any project and run 'claude-docker' to start" +echo "4. If no API key, Claude will prompt for interactive authentication" \ No newline at end of file diff --git a/scripts/startup.sh b/scripts/startup.sh index 09daec9..986c861 100755 --- a/scripts/startup.sh +++ b/scripts/startup.sh @@ -1,23 +1,23 @@ #!/bin/bash # ABOUTME: Startup script for Claude Code container with MCP server -# ABOUTME: Launches Twilio MCP server then starts Claude Code with permissions bypass +# ABOUTME: Configures environment and starts Claude Code with Twilio MCP integration # Load environment variables from .env if it exists if [ -f /app/.env ]; then - export $(cat /app/.env | grep -v '^#' | xargs) + set -a + source /app/.env 2>/dev/null || true + set +a fi -# Start Twilio MCP server in the background -echo "Starting Twilio MCP server..." -npx @twilioalpha/mcp-server-twilio & -MCP_PID=$! - -# Give MCP server time to start -sleep 2 - # Configure Claude Code to use the MCP server export CLAUDE_MCP_CONFIG=/app/config/mcp-config.json # Start Claude Code with permissions bypass echo "Starting Claude Code..." -exec claude-code --dangerously-skip-permissions "$@" \ No newline at end of file +if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ]; then + echo "Twilio MCP integration enabled" +else + echo "No Twilio credentials found, MCP features will be unavailable" +fi +echo "Note: If prompted for authentication, follow the interactive prompts" +exec claude --dangerously-skip-permissions "$@" \ No newline at end of file