Compare commits

...

10 Commits

Author SHA1 Message Date
db68610c34 feat: tsx 2025-06-23 16:49:18 +08:00
842f23b762 feat: tsx 2025-06-19 11:30:30 +08:00
Vishal Jain
63817a52e8 Remove commit_diff_summary.txt from tracking
Stop tracking commit_diff_summary.txt and add it to .gitignore
to prevent future commits
2025-06-18 15:06:56 +01:00
Vishal Jain
fb8650f686 Remove context persistance section 2025-06-18 15:02:12 +01:00
Vishal Jain
ddf35828e2 Simplify and clarify project documentation
Streamline documentation to focus on core functionality and conda
integration. Changes include:
- Clarify default design and conda environment usage
- Remove redundant workflow benefits section
- Simplify features list to focus on key capabilities
- Remove directory structure (available in repo)
- Add explicit push requirement in CLAUDE.md
- Update task completion requirements

This makes the documentation more focused and easier to understand while
emphasizing the project's integration with conda environments.
2025-06-18 14:58:59 +01:00
Vishal Jain
b97a5c17ba Update README with CLAUDE.md and task_log.md documentation
Added CLAUDE.md configuration section explaining the autonomous task
executor template and its usage with plan.md. Also documented the
task_log.md feature which captures execution details and insights.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-18 13:51:22 +00:00
Vishal Jain
3c95d84eaa Remove Anthtropic API key from read example
Do not need this anymore since we use pre configured creds.
2025-06-18 14:21:32 +01:00
Vishal Jain
9baf9f5c4b Use build args for git user config
Change git configuration to use Docker build args instead of .env file,
simplifying setup and improving security. This change:
- Removes git config from .env and startup.sh
- Adds GIT_USER_NAME and GIT_USER_EMAIL build args
- Updates documentation for new git config approach
- Improves task logging requirements in CLAUDE.md

The build arg approach provides better isolation and ensures git config is
properly set during image build rather than container runtime.
2025-06-18 14:19:18 +01:00
Vishal Jain
5377ac9b64 Remove task files and update gitignore
Remove temporary task-related files (plan.md, task_log.md) and update
.gitignore to prevent them from being tracked in the future. These files
are implementation-specific and should not be part of the repository as
they contain task execution details that are only relevant during the
development process.
2025-06-18 14:00:49 +01:00
Vishal Jain
9d1f8d0661 Add git user configuration support
Add required git user configuration to enable commits from within the container.
This change ensures proper attribution of git commits made inside the container by:

- Adding GIT_USER_NAME and GIT_USER_EMAIL to .env.example
- Configuring git user globally during Docker build
- Adding documentation for git configuration requirements
- Updating README with clearer setup instructions and requirements

The configuration is now required as part of the initial setup to prevent
issues with unattributed commits when using git inside the container.
2025-06-18 13:54:58 +01:00
6 changed files with 169 additions and 108 deletions

2
.gitignore vendored
View File

@ -33,3 +33,5 @@ data/
# Environment file with credentials
.env
plan.md
task_log.mdcommit_diff_summary.txt

View File

@ -1,6 +1,3 @@
# ABOUTME: Docker image for Claude Code with Twilio MCP server
# ABOUTME: Provides autonomous Claude Code environment with SMS notifications
FROM node:20-slim
# Install required system dependencies
@ -26,15 +23,19 @@ fi
# Create a non-root user with matching host UID/GID
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd -g $USER_GID claude-user && \
useradd -m -s /bin/bash -u $USER_UID -g $USER_GID claude-user && \
echo "claude-user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN addgroup --gid $USER_GID claude-user || true && \
adduser --disabled-password --gecos '' --uid $USER_UID --gid $USER_GID claude-user && \
echo "claude-user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
echo "User created:" && id claude-user && groups claude-user
# Create app directory
WORKDIR /app
# Install Claude Code globally
RUN npm install -g @anthropic-ai/claude-code
RUN npm install -g @anthropic-ai/claude-code@latest
RUN npm install -g tsx
RUN npm install -g nrm
RUN npm install -g pnpm
# Ensure npm global bin is in PATH
ENV PATH="/usr/local/bin:${PATH}"
@ -64,7 +65,8 @@ RUN cp /tmp/.claude.json /home/claude-user/.claude.json && \
rm -rf /tmp/.claude*
# Set proper ownership for everything
RUN chown -R claude-user:claude-user /app /home/claude-user
RUN chown -R claude-user:claude-user /app /home/claude-user || \
chown -R $(id -u claude-user):$(id -g claude-user) /app /home/claude-user
# Switch to non-root user
USER claude-user
@ -82,6 +84,20 @@ RUN bash -c 'source /app/.env && \
echo "No Twilio credentials found, skipping MCP configuration"; \
fi'
# Configure git user during build using host git config passed as build args
ARG GIT_USER_NAME=""
ARG GIT_USER_EMAIL=""
RUN if [ -n "$GIT_USER_NAME" ] && [ -n "$GIT_USER_EMAIL" ]; then \
echo "Configuring git user from host: $GIT_USER_NAME <$GIT_USER_EMAIL>" && \
git config --global user.name "$GIT_USER_NAME" && \
git config --global user.email "$GIT_USER_EMAIL" && \
echo "Git configuration complete"; \
else \
echo "Warning: No git user configured on host system"; \
echo "Run 'git config --global user.name \"Your Name\"' and 'git config --global user.email \"you@example.com\"' on host first"; \
fi
# Set working directory to mounted volume
WORKDIR /workspace

162
README.md
View File

@ -2,13 +2,18 @@
A Docker container setup for running Claude Code with full autonomous permissions and SMS notifications via Twilio MCP integration.
## What This Does
### CLAUDE.md Configuration
- Runs Claude Code in an isolated Docker container with full autonomy
- Integrates Twilio MCP for SMS notifications when tasks complete
- Provides persistent context across sessions
- Auto-configures Claude settings for seamless operation
- Simple one-command setup and usage
This codebase includes a custom `CLAUDE.md` template that configures Claude as an autonomous task executor. Located at `/templates/.claude/CLAUDE.md`, this file provides detailed instructions for how Claude should behave when executing tasks.
**Default Design:** The claude-docker agent expects a detailed `plan.md` file in your project root containing task specifications and which conda env to use. Claude will read this plan and execute it as faithfully as possible, documenting progress in `task_log.md`, send a text on completion if you set up your twilio credentials (optional). Simply tell it to make sure it has read the user scope claude md file and to execute.
## What This Does
- Runs Claude Code in an isolated Docker container with full autonomy.
- Integrates Twilio MCP for SMS notifications when tasks complete.
- Simple one-command setup and usage.
- Integrates existing conda environments to avoid custom env instructions in the Dockerfile.
- Documents work in a file `task_log.md`.
## Prerequisites
@ -33,7 +38,16 @@ ls ~/.claude.json ~/.claude/
- **Docker Desktop**: https://docs.docker.com/get-docker/
- Ensure Docker daemon is running before proceeding
### 3. Twilio Account (Optional - for SMS notifications)
### 3. Git Configuration (Required)
Git configuration is automatically loaded from your host system during Docker build:
- Make sure you have configured git on your host system first:
```bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
```
- **Important**: Claude Docker will commit to your current branch - make sure you're on the correct branch before starting
### 4. Twilio Account (Optional - for SMS notifications)
If you want SMS notifications when tasks complete:
- Create free trial account: https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account
- Get your Account SID and Auth Token from the Twilio Console
@ -66,9 +80,6 @@ claude-docker
### Environment Variables (.env)
```bash
# Required
ANTHROPIC_API_KEY=your_anthropic_key
# Optional - SMS notifications
TWILIO_ACCOUNT_SID=your_twilio_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
@ -85,36 +96,6 @@ SYSTEM_PACKAGES="libopenslide0 libgdal-dev"
⚠️ **Security Note**: Credentials are baked into the Docker image. Keep your image secure!
## How This Differs from Anthropic's DevContainer
We provide a different approach than [Anthropic's official .devcontainer](https://github.com/anthropics/claude-code/tree/main/.devcontainer):
| Feature | claude-docker | Anthropic's DevContainer |
|---------|--------------|-------------------------|
| **IDE Integration** | Standalone - works with any editor | VSCode-specific |
| **Authentication** | Persistent across all projects | Per-devcontainer |
| **Security Model** | Full autonomy (dangerously-skip-permissions) | Restrictive firewall whitelist |
| **Network Access** | Unrestricted | Limited to specific domains |
| **Conda Support** | Full integration with custom paths | Standard Node.js environment |
| **SMS Notifications** | Built-in Twilio MCP | Not included |
| **Setup Complexity** | One-time install, works everywhere | Per-project configuration |
| **Use Case** | Autonomous task execution | Secure development environment |
### When to Use Each
**Use claude-docker when you want:**
- 🚀 Maximum autonomy and flexibility
- 📱 SMS notifications for long-running tasks
- 🐍 Integration with existing conda environments
- 🔧 Quick setup without per-project configuration
- 💻 Editor/IDE independence
**Use Anthropic's DevContainer when you want:**
- 🔒 Maximum security with network restrictions
- 🆚 Deep VSCode integration
- 🛡️ Controlled environment with explicit whitelisting
- 👥 Team-standardized development environments
## Usage Patterns
### One-Time Setup Per Project
@ -142,11 +123,6 @@ For the best experience, run `claude-docker` once per project and leave it runni
docker stop claude-docker-session
```
This workflow gives you:
- ✅ Persistent authentication (login once per machine)
- ✅ Persistent project context (one session per project)
- ✅ Perfect file permissions between host and container
- ✅ No repeated setup or authentication
## Features
@ -161,15 +137,9 @@ This workflow gives you:
- Optional - works without if Twilio not configured
### 🐍 Conda Integration
- Has access to your conda envs so do not need to add build instructions to the Dockerfile
- Supports custom conda installations (ideal for academic/lab environments)
- Mounts conda directories to preserve original paths and configurations
- Automatic environment variable configuration for seamless conda usage
- Works with environments and package caches in non-standard locations
### 🗂️ Context Persistence
- Maintains project-specific Claude configuration
- Persistent across container sessions
- Helps Claude remember project context
### 🔑 Authentication Persistence
- Login once, use forever - authentication tokens persist across sessions
@ -177,10 +147,14 @@ This workflow gives you:
- Credentials stored securely in `~/.claude-docker/claude-home`
- Automatic UID/GID mapping ensures perfect file permissions between host and container
### 📝 Task Execution Logging
- Generates `task_log.md` documenting agent's execution process
- Stores assumptions, insights, and challenges encountered
- Acts as a simple summary to quickly understand what the agent accomplished
### 🐳 Clean Environment
- Each session runs in fresh Docker container
- Container auto-removes on exit
- No system pollution or conflicts
- Only current working directory mounted (along with conda directories specified in `.env`).
## How It Works
@ -190,20 +164,56 @@ This workflow gives you:
4. **Project Mounting**: Your project directory mounts to `/workspace`
5. **Clean Exit**: Container removes itself when Claude session ends
## Directory Structure
```
claude-docker/
├── Dockerfile # Main container definition
├── .env.example # Template for environment variables
├── scripts/
│ ├── claude-docker.sh # Wrapper script for container
│ ├── install.sh # Installation script
│ └── startup.sh # Container startup script
└── templates/
└── .claude/
└── CLAUDE.md # Claude behavior instructions
```
## How This Differs from Anthropic's DevContainer
We provide a different approach than [Anthropic's official .devcontainer](https://github.com/anthropics/claude-code/tree/main/.devcontainer), optimized for autonomous task execution:
### Key Advantages
**🐍 Seamless Conda Integration**
- **claude-docker**: Your existing conda environments work out-of-the-box - no setup needed per project
- **Anthropic**: Requires environment setup in each DevContainer's Dockerfile
**🧠 Custom Prompt Engineering**
- **claude-docker**: Includes carefully engineered CLAUDE.md prompts for agentic task execution
- **Anthropic**: Basic Claude Code functionality without task-specific optimization
**🔑 One-Time Authentication**
- **claude-docker**: Authenticate once, use forever across all projects
- **Anthropic**: Re-authenticate for each new DevContainer
**📱 Additional Features**
- **claude-docker**: Built-in Twilio MCP for SMS notifications on task completion
- **Anthropic**: No notification system included
### Feature Comparison
| Feature | claude-docker | Anthropic's DevContainer |
|---------|--------------|-------------------------|
| **IDE Support** | Any editor/IDE | VSCode-specific |
| **Authentication** | Once per machine, persists forever | Per-devcontainer setup |
| **Conda Environments** | Direct access to all host envs | Manual setup in Dockerfile |
| **Prompt Engineering** | Optimized CLAUDE.md for tasks | Standard behavior |
| **Network Access** | Full access (firewall coming soon) | Configurable firewall |
| **SMS Notifications** | Built-in Twilio MCP | Not available |
| **Permissions** | Auto (--dangerously-skip-permissions) | Auto (--dangerously-skip-permissions) |
### When to Use Each
**Use claude-docker for:**
- 🚀 Autonomous task execution with optimized prompts
- 🐍 Projects requiring conda environments without Docker setup
- 📱 Long-running tasks with SMS completion notifications
- 🔧 Quick start without per-project configuration
- 💻 Non-VSCode development environments
**Use Anthropic's DevContainer for:**
- 🔒 Network-restricted environments (domain whitelisting)
- 🆚 Teams standardizing on VSCode
- 🛡️ Projects requiring strict network isolation today
**Note**: Network firewall functionality similar to Anthropic's implementation is our next planned feature.
## Configuration
@ -242,10 +252,10 @@ For custom conda installations (common in academic/lab environments), add these
```bash
# Main conda installation
CONDA_PREFIX=/vol/biomedic3/username/miniconda3
CONDA_PREFIX=/vol/lab/username/miniconda3
# Additional conda directories (space-separated)
CONDA_EXTRA_DIRS="/vol/biomedic3/username/.conda/envs /vol/biomedic3/username/conda_envs /vol/biomedic3/username/.conda/pkgs /vol/biomedic3/username/conda_pkgs"
CONDA_EXTRA_DIRS="/vol/lab/username/.conda/envs /vol/lab/username/conda_envs /vol/lab/username/.conda/pkgs /vol/lab/username/conda_pkgs"
```
**How it works:**
@ -270,25 +280,13 @@ SYSTEM_PACKAGES="libopenslide0"
SYSTEM_PACKAGES="libopenslide0 libgdal-dev libproj-dev libopencv-dev"
```
**Common packages:**
- `libopenslide0` - OpenSlide for whole slide imaging
- `libgdal-dev` - GDAL for geospatial data
- `libproj-dev` - PROJ for cartographic projections
- `libopencv-dev` - OpenCV for computer vision
- `libfftw3-dev` - FFTW for fast Fourier transforms
**Note:** Adding system packages requires rebuilding the Docker image (`docker rmi claude-docker:latest`).
## Requirements
- Docker installed and running
- Anthropic API key (or Claude subscription)
- (Optional) Twilio account with API Key/Secret for SMS notifications
## Next Steps
**Phase 2 - Security Enhancements:**
- Network firewall to whitelist only essential domains
- Network firewall to whitelist specific domains (similar to Anthropic's DevContainer)
- Shell history persistence between sessions
- Additional security features

View File

@ -54,14 +54,22 @@ if [ "$NEED_REBUILD" = true ]; then
cp -r "$HOME/.claude" "$PROJECT_ROOT/.claude"
fi
# Build docker command with conditional system packages
# Get git config from host
GIT_USER_NAME=$(git config --global --get user.name 2>/dev/null || echo "")
GIT_USER_EMAIL=$(git config --global --get user.email 2>/dev/null || echo "")
# Build docker command with conditional system packages and git config
BUILD_ARGS="--build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g)"
if [ -n "$GIT_USER_NAME" ] && [ -n "$GIT_USER_EMAIL" ]; then
BUILD_ARGS="$BUILD_ARGS --build-arg GIT_USER_NAME=\"$GIT_USER_NAME\" --build-arg GIT_USER_EMAIL=\"$GIT_USER_EMAIL\""
fi
if [ -n "$SYSTEM_PACKAGES" ]; then
echo "✓ Building with additional system packages: $SYSTEM_PACKAGES"
docker build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) --build-arg SYSTEM_PACKAGES="$SYSTEM_PACKAGES" -t claude-docker:latest "$PROJECT_ROOT"
else
docker build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) -t claude-docker:latest "$PROJECT_ROOT"
BUILD_ARGS="$BUILD_ARGS --build-arg SYSTEM_PACKAGES=\"$SYSTEM_PACKAGES\""
fi
eval "docker build $BUILD_ARGS -t claude-docker:latest \"$PROJECT_ROOT\""
# Clean up copied auth files
rm -f "$PROJECT_ROOT/.claude.json"
rm -rf "$PROJECT_ROOT/.claude"

View File

@ -34,6 +34,8 @@ else
echo "No Twilio credentials found - SMS notifications disabled"
fi
# Git configuration is handled during Docker build from host git config
# Start Claude Code with permissions bypass
echo "Starting Claude Code..."
exec claude --dangerously-skip-permissions "$@"

View File

@ -1,6 +1,8 @@
# Autonomous Task Executor
You are an autonomous task executor running in a sandboxed Docker environment. Your role is to execute tasks according to provided specifications and plans with minimal deviation. Read ALL of the following first before doing anything else. The task will be specified in `plan.md`, codebase details will be in `claude.md` and you will write to `task_log.md`.
使用中文回答用户的问题
## Communication Design
You MAY have Twilio MCP integration for SMS notifications. Check if ALL required environment variables exist:
- `TWILIO_ACCOUNT_SID`
@ -27,9 +29,9 @@ If ANY Twilio variables are missing, skip SMS notifications and continue task ex
## Required Workflow
### 1. Task Initialization
- **FIRST**: Check for `claude.md` in project root - if exists, read it to understand project-specific context and requirements
- Read and understand the complete specification/plan written in `plan.md`.
- **ULTRA THINK**: ultrathink about the execution approach - analyse potential pitfalls, complications, technical challenges, and validate that your planned approach will actually work and properly implement the specification.
- Check for `claude.md` in project root - if exists, read it to understand project-specific context and requirements
- Read and understand the complete specification/plan written in `plan.md`
- **ULTRA-THINK**: Analyze potential pitfalls, complications, technical challenges, and validate that your planned approach will actually work and properly implement the specification
- Create a detailed checklist using TodoWrite breaking down all steps
- Create `task_log.md` in project root to document the execution process
- Begin systematic execution
@ -38,6 +40,7 @@ If ANY Twilio variables are missing, skip SMS notifications and continue task ex
- Follow the checklist step by step
- Document ALL assumptions made in `task_log.md`
- Document ANY problems encountered and how they were solved in `task_log.md`
- Document ALL insights / discoveries made during implementation in `task_log.md`
- Update todo list as steps are completed
- NEVER skip steps or take shortcuts
- `task_log.md` MUST contain your checklist as well.
@ -67,6 +70,8 @@ Must include these sections:
## Deviations from Plan
[Any necessary changes from original plan with justification]
## Insights / Discoveries
## Final Status
[Success/Failure with details]
```
@ -87,19 +92,48 @@ Upon successful task completion:
1. Clean up temporary files and stop unnecessary processes
2. Leave environment in clean, reproducible state
3. Complete final documentation in `task_log.md`
4. Make git commits following the commit message rules below
4. Make git commits following the commit message rules below. ALWAYS PUSH TO REMOTE.
5. If Twilio is configured (all env vars present), send completion message to `$TWILIO_TO_NUMBER` with summary
6. Completion msg MUST include a remote url link. See below for generation instructions.
### Constructing Remote Git URLs
When you need to create GitHub commit URLs, use these commands to extract repository information:
```bash
REMOTE_URL=$(git config --get remote.origin.url)
COMMIT_SHA=$(git rev-parse HEAD)
```
Parse the remote URL to construct GitHub commit links:
- For HTTPS URLs like `https://github.com/username/repo.git`: Extract username and repo from path
- For SSH URLs like `git@github.com:username/repo.git`: Extract username and repo after the colon
- Final URL format: `https://github.com/username/repo/commit/COMMIT_SHA`
Example extraction logic:
```bash
# Remove .git suffix and extract parts
if [[ $REMOTE_URL == *"github.com:"* ]]; then
# SSH format: git@github.com:username/repo.git
REPO_PATH=${REMOTE_URL#*:}
REPO_PATH=${REPO_PATH%.git}
elif [[ $REMOTE_URL == *"github.com/"* ]]; then
# HTTPS format: https://github.com/username/repo.git
REPO_PATH=${REMOTE_URL#*github.com/}
REPO_PATH=${REPO_PATH%.git}
fi
GITHUB_URL="https://github.com/${REPO_PATH}/commit/${COMMIT_SHA}"
```
## Environment & Tools
### Python/Conda Environment
- ALWAYS use conda binary at `/vol/biomedic3/vj724/miniconda3/bin/conda`
- ALWAYS use conda binary at `$CONDA_PREFIX/bin/conda`
- ALWAYS use this format for script execution:
```bash
/vol/biomedic3/vj724/miniconda3/bin/conda run --live-stream -n ENVIRONMENT_NAME python -u your_script.py [args]
$CONDA_PREFIX/bin/conda run --live-stream -n ENVIRONMENT_NAME python -u your_script.py [args]
```
- ALWAYS include --live-stream and -u flags for real-time output
- You will be told the conda env name to use in the `plan.md`
- You WILL be told the conda env name to use in the `plan.md`, IF NOT TOLD AND PYTHON CODE WITH CUSTOM PACKAGES needs to be run - log this as termination reason in `task_log.md` and if twilio configured, text to the user.
### Sandbox Environment
- You have full file system access within the container
@ -119,8 +153,8 @@ Upon successful task completion:
- Monitor process health and status
## Coding Standards
- NEVER use hard-coded values - use config files or argparse with defaults
- Constants in ALL CAPS at TOP of script
- NEVER use hard-coded values - use constants, config files or cli argparse args with defaults
- Constants ALWAYS placed in ALL CAPS at TOP of script
- Prefer simple, maintainable solutions over complex ones
- Match existing code style within files
- NEVER remove code comments unless provably false
@ -128,7 +162,7 @@ Upon successful task completion:
- NEVER use mock implementations for any purpose
- NEVER commit API credentials - use .env files
- NEVER rewrite existing implementations without explicit need
- Define constants centrally
## Security Guidelines
- Never expose sensitive data in logs or files
@ -141,6 +175,7 @@ Upon successful task completion:
### When to Commit
- Commit after completing each major step in your checklist
- Use execution context, not git diff, to write messages
- Always push to the current branch's origin after commits: git push -u origin current-branch
### Commit Message Format
**Subject Line:**
@ -180,7 +215,7 @@ See task_log.md for details
**Successful Completion:**
```
TASK COMPLETED: [Brief summary]
Files modified: [Key files changed]
GIT_COMMIT_URL: [Remote Git URL]
See task_log.md for full details
```
@ -189,8 +224,8 @@ See task_log.md for full details
- Break down into atomic, actionable steps
- Execute methodically without shortcuts
- Document everything as you work
- Never assume - ask for clarification by terminating if critical info missing
- Stick to the plan unless technically impossible
- Never assume - ask for clarification by terminating if CRITICAL info missing.
- Minor / Non Critical missing information MUST BE DOCUMENTED in `task_log.md` with your imputations.
- Real implementations only - no mocks, no simplified versions
- DO NOT IMPLEMENT FALLBACKS when the specified approach fails
- Complete the task as specified or fail explicitly with clear reasoning
- Complete the task EXACTLY as specified or CHOOSE EARLY TERMINATION if plan is flawed or infeasible or you are stuck.